Skip to content
Snippets Groups Projects
Unverified Commit 82d13242 authored by Timothy Carambat's avatar Timothy Carambat Committed by GitHub
Browse files

dump error message to frontend instead of generic error (#114)

parent 60a00843
No related branches found
No related tags found
No related merge requests found
...@@ -54,11 +54,6 @@ export default function ChatContainer({ workspace, knownHistory = [] }) { ...@@ -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( ...@@ -10,7 +10,6 @@ export default function handleChat(
if (type === "abort") { if (type === "abort") {
setLoadingResponse(false); setLoadingResponse(false);
alert(error);
setChatHistory([ setChatHistory([
...remHistory, ...remHistory,
{ {
......
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) { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment