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.tsx53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/client/views/nodes/ChatBox/ChatBox.tsx b/src/client/views/nodes/ChatBox/ChatBox.tsx
index 3a2508c37..390f13ce7 100644
--- a/src/client/views/nodes/ChatBox/ChatBox.tsx
+++ b/src/client/views/nodes/ChatBox/ChatBox.tsx
@@ -49,7 +49,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
super(props);
makeObservable(this);
this.openai = this.initializeOpenAI();
- this.history = [];
+ this.history = [{ role: ASSISTANT_ROLE.ASSISTANT, text: 'Welcome to the Document Analyser Assistant! Link a document or ask questions to get started.' }];
this.threadID = StrCast(this.dataDoc.thread_id);
this.assistantID = StrCast(this.dataDoc.assistant_id);
this.vectorStoreID = StrCast(this.dataDoc.vector_store_id);
@@ -160,6 +160,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
}
};
+ @action
runAssistant = async (inputText: string) => {
// Ensure an assistant and thread are created
if (!this.assistantID || !this.threadID || !this.vectorStoreID) {
@@ -169,7 +170,6 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
let currentText: string = '';
let currentToolCallMessage: string = '';
- let current_message_id: string | null = null;
// Send the user's input to the assistant
await this.openai.beta.threads.messages.create(this.threadID, {
@@ -190,32 +190,32 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
});
})
.on('toolCallDelta', (toolCallDelta, snapshot) => {
- runInAction(() => {
- if (toolCallDelta.type === 'code_interpreter') {
- if (toolCallDelta.code_interpreter?.input) {
- currentToolCallMessage += toolCallDelta.code_interpreter.input;
+ if (toolCallDelta.type === 'code_interpreter') {
+ if (toolCallDelta.code_interpreter?.input) {
+ currentToolCallMessage += toolCallDelta.code_interpreter.input;
- if (this.current_message) {
- this.current_message.tool_logs = currentToolCallMessage;
- }
+ if (this.current_message) {
+ this.current_message.tool_logs = currentToolCallMessage;
}
+ }
- if (toolCallDelta.code_interpreter?.outputs) {
- currentToolCallMessage += '\n Code interpreter output:';
- toolCallDelta.code_interpreter.outputs.forEach(output => {
- if (output.type === 'logs') {
+ if (toolCallDelta.code_interpreter?.outputs) {
+ currentToolCallMessage += '\n Code interpreter output:';
+ toolCallDelta.code_interpreter.outputs.forEach(output => {
+ if (output.type === 'logs') {
+ runInAction(() => {
if (this.current_message) {
this.current_message.tool_logs += '\n|' + output.logs;
}
- }
- });
- }
+ });
+ }
+ });
}
- });
+ }
})
.on('textDelta', (textDelta, snapshot) => {
+ currentText += textDelta.value;
runInAction(() => {
- currentText += textDelta.value;
if (this.current_message) {
this.current_message.text = currentText;
}
@@ -431,6 +431,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
}
if (doc) {
doc && this._props.addDocument?.(doc);
+ //add to overlay
await DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {});
}
};
@@ -505,13 +506,15 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
try {
const storedHistory = JSON.parse(StrCast(this.dataDoc.data));
runInAction(() => {
- this.history = storedHistory.map((msg: AssistantMessage) => ({
- role: msg.role,
- text: msg.text,
- quote: msg.quote,
- tool_logs: msg.tool_logs,
- image: msg.image,
- }));
+ this.history.push(
+ ...storedHistory.map((msg: AssistantMessage) => ({
+ role: msg.role,
+ text: msg.text,
+ quote: msg.quote,
+ tool_logs: msg.tool_logs,
+ image: msg.image,
+ }))
+ );
});
} catch (e) {
console.error('Failed to parse history from dataDoc:', e);