aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/ChatBox/ChatBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/ChatBox/ChatBox.tsx')
-rw-r--r--src/client/views/nodes/ChatBox/ChatBox.tsx43
1 files changed, 11 insertions, 32 deletions
diff --git a/src/client/views/nodes/ChatBox/ChatBox.tsx b/src/client/views/nodes/ChatBox/ChatBox.tsx
index d38c71810..099c0298e 100644
--- a/src/client/views/nodes/ChatBox/ChatBox.tsx
+++ b/src/client/views/nodes/ChatBox/ChatBox.tsx
@@ -149,45 +149,24 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
if (trimmedText) {
try {
- //Make everything go through the answer parser
- //Pass in all the updates to the AnswrParser and it will create the assistant messasge that will be the current message including adding in the thoughts and also waiting for the asnwer and also showing tool progress
textInput.value = '';
this.history.push({ role: ASSISTANT_ROLE.USER, content: [{ index: 0, type: TEXT_TYPE.NORMAL, text: trimmedText, citation_ids: null }] });
this.isLoading = true;
- this.current_message = { role: ASSISTANT_ROLE.ASSISTANT, content: [], thoughts: [] };
-
- let currentThought = '';
-
- this.current_message?.thoughts?.push(currentThought);
-
- const onUpdate = (update: string) => {
- const thoughtNumber = Number(update.match(/^THOUGHT(\d+):/)?.[1] ?? 0);
- const regex = /<thought>\s*([\s\S]*?)(?:<\/thought>|$)/;
- const match = update.match(regex);
- const currentThought = match ? match[1].trim() : '';
- //const numericPrefix = Number(update.match(/^\d+/)?.[0]);
- if (update.startsWith('THOUGHT')) {
- console.log('Thought:', currentThought, thoughtNumber);
- if (this.current_message?.thoughts) {
- if (this.current_message.thoughts.length <= thoughtNumber) {
- this.current_message.thoughts.push(currentThought);
- } else {
- this.current_message.thoughts[thoughtNumber] = currentThought;
- }
- }
- console.log('Thoughts:', this.current_message?.thoughts);
- }
+ this.current_message = { role: ASSISTANT_ROLE.ASSISTANT, content: [], thoughts: [], actions: [], citations: [] };
+
+ const onUpdate = (update: AssistantMessage) => {
+ runInAction(() => {
+ this.current_message = { ...update };
+ });
};
- const response = await this.agent.askAgent(trimmedText, 20, onUpdate);
- const parsedAnswer = AnswerParser.parse(response);
- parsedAnswer.thoughts = this.current_message?.thoughts;
+ const finalMessage = await this.agent.askAgent(trimmedText, 20, onUpdate);
- if (this.current_message) {
- this.history.push(parsedAnswer);
+ runInAction(() => {
+ this.history.push({ ...finalMessage });
this.current_message = undefined;
- }
- this.dataDoc.data = JSON.stringify(this.history);
+ this.dataDoc.data = JSON.stringify(this.history);
+ });
} catch (err) {
console.error('Error:', err);
this.history.push({ role: ASSISTANT_ROLE.ASSISTANT, content: [{ index: 0, type: TEXT_TYPE.NORMAL, text: 'Sorry, I encountered an error while processing your request.', citation_ids: null }] });