From 3f71c9c48846bc68febd8c8647721ca2625db63c Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Mon, 24 Jul 2023 22:05:50 +0200 Subject: [PATCH] (core) Cleanup: Remove unused AssistanceRequest.regenerate Summary: Finish what was started in https://phab.getgrist.com/D3970 Test Plan: existing tests Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D3972 --- app/client/widgets/FormulaAssistant.ts | 16 ++++------------ app/common/AssistancePrompts.ts | 2 -- app/server/lib/Assistance.ts | 18 +++--------------- 3 files changed, 7 insertions(+), 29 deletions(-) diff --git a/app/client/widgets/FormulaAssistant.ts b/app/client/widgets/FormulaAssistant.ts index bddb53e9..f625b7dc 100644 --- a/app/client/widgets/FormulaAssistant.ts +++ b/app/client/widgets/FormulaAssistant.ts @@ -629,22 +629,17 @@ export class FormulaAssistant extends Disposable { await this._preview(); } - private async _sendMessage(description: string, regenerate = false): Promise { + private async _sendMessage(description: string): Promise { // Destruct options. const {column, gristDoc} = this._options; // Get the state of the chat from the column. const conversationId = this._chat.conversationId.get(); const prevState = column.chatHistory.peek().get().state; - // Send the message back to the AI with previous state and a mark that we want to regenerate. - // We can't modify the state here as we treat it as a black box, so we only removed last message - // from ai from the chat, we grabbed last question and we are sending it back to the AI with a - // flag that it should clear last response and regenerate it. const {reply, suggestedActions, state} = await askAI(gristDoc, { conversationId, column, description, state: prevState, - regenerate, }); console.debug('suggestedActions', {suggestedActions, reply, state}); // If back-end is capable of conversation, keep its state. @@ -695,7 +690,7 @@ export class FormulaAssistant extends Disposable { this._chat.thinking(); this._waiting.set(true); try { - const response = await this._sendMessage(message, false); + const response = await this._sendMessage(message); this._chat.addResponse(response); } catch(err) { this._chat.thinking(false); @@ -961,20 +956,17 @@ async function askAI(grist: GristDoc, options: { column: ColumnRec, description: string, conversationId: string, - regenerate?: boolean, state?: AssistanceState }): Promise { - const {column, description, conversationId, state, regenerate} = options; + const {column, description, conversationId, state} = options; const tableId = column.table.peek().tableId.peek(); const colId = column.colId.peek(); - const result = await grist.docApi.getAssistance({ + return await grist.docApi.getAssistance({ conversationId, context: {type: 'formula', tableId, colId}, text: description, state, - regenerate, }); - return result; } /** Builds avatar image for user or assistant. */ diff --git a/app/common/AssistancePrompts.ts b/app/common/AssistancePrompts.ts index abe4e915..10a925b4 100644 --- a/app/common/AssistancePrompts.ts +++ b/app/common/AssistancePrompts.ts @@ -41,8 +41,6 @@ export interface AssistanceRequest { context: AssistanceContext; state?: AssistanceState; text: string; - // TODO this is no longer used and should be removed - regenerate?: boolean; } /** diff --git a/app/server/lib/Assistance.ts b/app/server/lib/Assistance.ts index 6eb94bb9..f9af0806 100644 --- a/app/server/lib/Assistance.ts +++ b/app/server/lib/Assistance.ts @@ -362,19 +362,10 @@ class EchoAssistant implements Assistant { role: 'system', content: '' }); - messages.push({ - role: 'user', content: request.text, - }); - } else { - if (request.regenerate) { - if (messages[messages.length - 1].role !== 'user') { - messages.pop(); - } - } - messages.push({ - role: 'user', content: request.text, - }); } + messages.push({ + role: 'user', content: request.text, + }); const completion = request.text; const history = { messages }; history.messages.push({ @@ -412,9 +403,6 @@ export async function sendForCompletion( doc: AssistanceDoc, request: AssistanceRequest, ): Promise { - if (request.regenerate) { - throw new Error('regenerate no longer supported'); - } const assistant = getAssistant(); return await assistant.apply(optSession, doc, request); }