Skip to content

Commit

Permalink
add validation on rag search result to avoid crash
Browse files Browse the repository at this point in the history
Signed-off-by: cbh778899 <[email protected]>
  • Loading branch information
cbh778899 committed Aug 23, 2024
1 parent 021b86b commit 4c7e57d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions actions/inference.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,12 @@ export async function ragChatCompletion(req, res) {
const latest_message = messages.slice(-1)[0].content;
const rag_result = await searchByMessage(dataset_name, latest_message);

request_body.prompt = formatOpenAIContext([
...messages,
{ role: "system", content: `This background information is useful for your next answer: "${rag_result.context}"` }
])
const context = [...messages];
if(rag_result) context.push({
role: "system",
content: `This background information is useful for your next answer: "${rag_result.context}"`
})
request_body.prompt = formatOpenAIContext(context);

const isStream = !!request_body.stream;
if(isStream) {
Expand Down

0 comments on commit 4c7e57d

Please sign in to comment.