diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/nodes/ChatBox/ChatBox.scss | 77 | ||||
-rw-r--r-- | src/client/views/nodes/ChatBox/ChatBox.tsx | 53 |
2 files changed, 65 insertions, 65 deletions
diff --git a/src/client/views/nodes/ChatBox/ChatBox.scss b/src/client/views/nodes/ChatBox/ChatBox.scss index f1ad3d074..a08b98f50 100644 --- a/src/client/views/nodes/ChatBox/ChatBox.scss +++ b/src/client/views/nodes/ChatBox/ChatBox.scss @@ -24,15 +24,14 @@ $border-radius: 8px; padding: 10px; display: flex; flex-direction: column-reverse; - + &::-webkit-scrollbar { - width: 8px; + width: 8px; } &::-webkit-scrollbar-thumb { - background-color: darken($background-color, 10%); - border-radius: $border-radius; + background-color: darken($background-color, 10%); + border-radius: $border-radius; } - .chat-content { display: flex; @@ -52,10 +51,10 @@ $border-radius: 8px; align-items: center; max-width: 70%; word-break: break-word; - .message-footer { // Assuming this is the container for the toggle button + .message-footer { + // Assuming this is the container for the toggle button //max-width: 70%; - - + .toggle-logs-button { margin-top: 10px; // Padding on sides to align with the text above width: 95%; @@ -88,35 +87,34 @@ $border-radius: 8px; max-height: 150px; // Ensuring it does not grow too large overflow-y: auto; } - - } - + } + .custom-link { color: lightblue; text-decoration: underline; cursor: pointer; - } + } &.user { - align-self: flex-end; - background-color: $button-color; - color: #fff; + align-self: flex-end; + background-color: $button-color; + color: #fff; } - + &.chatbot { - align-self: flex-start; - background-color: $input-background; - color: $text-color; + align-self: flex-start; + background-color: $input-background; + color: $text-color; } - + span { - flex-grow: 1; - padding-right: 10px; + flex-grow: 1; + padding-right: 10px; } - + img { - max-width: 50px; - max-height: 50px; - border-radius: 50%; + max-width: 50px; + max-height: 50px; + border-radius: 50%; } } } @@ -132,8 +130,8 @@ $border-radius: 8px; padding: 10px; background-color: $input-background; box-shadow: inset 0 -1px 2px $shadow-color; - - input[type="text"] { + + input[type='text'] { flex-grow: 1; border: 1px solid darken($input-background, 10%); border-radius: $border-radius; @@ -143,16 +141,16 @@ $border-radius: 8px; button { padding: 8px 16px; - background-color: $button-color; - color: #fff; - border: none; - border-radius: $border-radius; - cursor: pointer; - transition: background-color 0.3s; - - &:hover { - background-color: $button-hover-color; - } + background-color: $button-color; + color: #fff; + border: none; + border-radius: $border-radius; + cursor: pointer; + transition: background-color 0.3s; + + &:hover { + background-color: $button-hover-color; + } } margin-bottom: 0; } @@ -178,7 +176,6 @@ $border-radius: 8px; } } - .modal { position: fixed; top: 0; @@ -217,7 +214,7 @@ $border-radius: 8px; border: none; border-radius: $border-radius; cursor: pointer; - margin: 5px; + //margin: 5px; transition: background-color 0.3s; &:hover { 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); |