mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-07-04 16:20:12 +02:00
dump error message to frontend instead of generic error (#114)
This commit is contained in:
parent
60a00843df
commit
82d132427c
|
@ -54,11 +54,6 @@ export default function ChatContainer({ workspace, knownHistory = [] }) {
|
||||||
window.localStorage.getItem(`workspace_chat_mode_${workspace.slug}`) ??
|
window.localStorage.getItem(`workspace_chat_mode_${workspace.slug}`) ??
|
||||||
"chat"
|
"chat"
|
||||||
);
|
);
|
||||||
if (!chatResult) {
|
|
||||||
alert("Could not send chat.");
|
|
||||||
setLoadingResponse(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
handleChat(
|
handleChat(
|
||||||
chatResult,
|
chatResult,
|
||||||
setLoadingResponse,
|
setLoadingResponse,
|
||||||
|
|
|
@ -10,7 +10,6 @@ export default function handleChat(
|
||||||
|
|
||||||
if (type === "abort") {
|
if (type === "abort") {
|
||||||
setLoadingResponse(false);
|
setLoadingResponse(false);
|
||||||
alert(error);
|
|
||||||
setChatHistory([
|
setChatHistory([
|
||||||
...remHistory,
|
...remHistory,
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
const { v4: uuidv4 } = require("uuid");
|
||||||
const { reqBody } = require("../utils/http");
|
const { reqBody } = require("../utils/http");
|
||||||
const { Workspace } = require("../models/workspace");
|
const { Workspace } = require("../models/workspace");
|
||||||
const { chatWithWorkspace } = require("../utils/chats");
|
const { chatWithWorkspace } = require("../utils/chats");
|
||||||
|
@ -18,8 +19,14 @@ function chatEndpoints(app) {
|
||||||
const result = await chatWithWorkspace(workspace, message, mode);
|
const result = await chatWithWorkspace(workspace, message, mode);
|
||||||
response.status(200).json({ ...result });
|
response.status(200).json({ ...result });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e.message, e);
|
response.status(500).json({
|
||||||
response.sendStatus(500).end();
|
id: uuidv4(),
|
||||||
|
type: "abort",
|
||||||
|
textResponse: null,
|
||||||
|
sources: [],
|
||||||
|
close: true,
|
||||||
|
error: e.message,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ class OpenAi {
|
||||||
constructor() {
|
constructor() {
|
||||||
const config = new Configuration({
|
const config = new Configuration({
|
||||||
apiKey: process.env.OPEN_AI_KEY,
|
apiKey: process.env.OPEN_AI_KEY,
|
||||||
// organization: "org-123xyz", // Optional
|
|
||||||
});
|
});
|
||||||
const openai = new OpenAIApi(config);
|
const openai = new OpenAIApi(config);
|
||||||
this.openai = openai;
|
this.openai = openai;
|
||||||
|
@ -23,6 +22,11 @@ class OpenAi {
|
||||||
if (res.results.length === 0)
|
if (res.results.length === 0)
|
||||||
throw new Error("OpenAI moderation: No results length!");
|
throw new Error("OpenAI moderation: No results length!");
|
||||||
return res.results[0];
|
return res.results[0];
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
throw new Error(
|
||||||
|
`OpenAI::CreateModeration failed with: ${error.message}`
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!flagged) return { safe: true, reasons: [] };
|
if (!flagged) return { safe: true, reasons: [] };
|
||||||
|
@ -65,6 +69,12 @@ class OpenAi {
|
||||||
if (res.choices.length === 0)
|
if (res.choices.length === 0)
|
||||||
throw new Error("OpenAI chat: No results length!");
|
throw new Error("OpenAI chat: No results length!");
|
||||||
return res.choices[0].message.content;
|
return res.choices[0].message.content;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log(error);
|
||||||
|
throw new Error(
|
||||||
|
`OpenAI::createChatCompletion failed with: ${error.message}`
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return textResponse;
|
return textResponse;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user