mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(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
This commit is contained in:
parent
f7fdfab6bf
commit
3f71c9c488
@ -629,22 +629,17 @@ export class FormulaAssistant extends Disposable {
|
||||
await this._preview();
|
||||
}
|
||||
|
||||
private async _sendMessage(description: string, regenerate = false): Promise<ChatMessage> {
|
||||
private async _sendMessage(description: string): Promise<ChatMessage> {
|
||||
// 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<AssistanceResponse> {
|
||||
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. */
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,
|
||||
});
|
||||
}
|
||||
const completion = request.text;
|
||||
const history = { messages };
|
||||
history.messages.push({
|
||||
@ -412,9 +403,6 @@ export async function sendForCompletion(
|
||||
doc: AssistanceDoc,
|
||||
request: AssistanceRequest,
|
||||
): Promise<AssistanceResponse> {
|
||||
if (request.regenerate) {
|
||||
throw new Error('regenerate no longer supported');
|
||||
}
|
||||
const assistant = getAssistant();
|
||||
return await assistant.apply(optSession, doc, request);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user