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