Skip to content

Commit

Permalink
fix: a few bugs from refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
shibbas committed Nov 29, 2023
1 parent a8e4c84 commit 52dbf6c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/chat-component/src/components/chat-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,38 +124,41 @@ export class ChatController implements ReactiveController {

// Check if message is a bot message to process citations and follow-up questions

let messageToUpdate = response;

if (!useStream && !isUserMessage && typeof response !== 'string') {
const generatedResponse = (response as BotResponse).choices[0].message;
if (isUserMessage || typeof response === 'string') {
await updateChatWithMessageOrChunk(response, false);
} else if (useStream) {
await updateChatWithMessageOrChunk(response, true);
} else {
// non-streamed response
const generatedResponse = (response as BotResponse).choices[0].message;
const processedText = processText(generatedResponse.content, [citations, followingSteps, followupQuestions]);
messageToUpdate = processedText.replacedText;
const messageToUpdate = processedText.replacedText;
// Push all lists coming from processText to the corresponding arrays
citations.push(...(processedText.arrays[0] as unknown as Citation[]));
followingSteps.push(...(processedText.arrays[1] as string[]));
followupQuestions.push(...(processedText.arrays[2] as string[]));
thoughts = generatedResponse.context?.thoughts ?? '';
dataPoints = generatedResponse.context?.data_points ?? [];
}

await updateChatWithMessageOrChunk(messageToUpdate, !isUserMessage && useStream);
await updateChatWithMessageOrChunk(messageToUpdate, false);
}
}

async generateAnswer(requestOptions: ChatRequestOptions, httpOptions: ChatHttpOptions) {
const { question } = requestOptions;

if (question) {
try {
this.processingMessage = undefined;
this.generatingAnswer = true;
this.isAwaitingResponse = true;

// for chat messages, process user question as a chat entry
if (requestOptions.type === 'chat') {
await this.processResponse(question, true, false);
}

this.isAwaitingResponse = true;
this.processingMessage = undefined;

const response = (await getAPIResponse(requestOptions, httpOptions)) as BotResponse;
this.isAwaitingResponse = false;

Expand Down

0 comments on commit 52dbf6c

Please sign in to comment.