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();
|
await this._preview();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _sendMessage(description: string, regenerate = false): Promise<ChatMessage> {
|
private async _sendMessage(description: string): Promise<ChatMessage> {
|
||||||
// Destruct options.
|
// Destruct options.
|
||||||
const {column, gristDoc} = this._options;
|
const {column, gristDoc} = this._options;
|
||||||
// Get the state of the chat from the column.
|
// Get the state of the chat from the column.
|
||||||
const conversationId = this._chat.conversationId.get();
|
const conversationId = this._chat.conversationId.get();
|
||||||
const prevState = column.chatHistory.peek().get().state;
|
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, {
|
const {reply, suggestedActions, state} = await askAI(gristDoc, {
|
||||||
conversationId,
|
conversationId,
|
||||||
column,
|
column,
|
||||||
description,
|
description,
|
||||||
state: prevState,
|
state: prevState,
|
||||||
regenerate,
|
|
||||||
});
|
});
|
||||||
console.debug('suggestedActions', {suggestedActions, reply, state});
|
console.debug('suggestedActions', {suggestedActions, reply, state});
|
||||||
// If back-end is capable of conversation, keep its state.
|
// If back-end is capable of conversation, keep its state.
|
||||||
@ -695,7 +690,7 @@ export class FormulaAssistant extends Disposable {
|
|||||||
this._chat.thinking();
|
this._chat.thinking();
|
||||||
this._waiting.set(true);
|
this._waiting.set(true);
|
||||||
try {
|
try {
|
||||||
const response = await this._sendMessage(message, false);
|
const response = await this._sendMessage(message);
|
||||||
this._chat.addResponse(response);
|
this._chat.addResponse(response);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
this._chat.thinking(false);
|
this._chat.thinking(false);
|
||||||
@ -961,20 +956,17 @@ async function askAI(grist: GristDoc, options: {
|
|||||||
column: ColumnRec,
|
column: ColumnRec,
|
||||||
description: string,
|
description: string,
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
regenerate?: boolean,
|
|
||||||
state?: AssistanceState
|
state?: AssistanceState
|
||||||
}): Promise<AssistanceResponse> {
|
}): Promise<AssistanceResponse> {
|
||||||
const {column, description, conversationId, state, regenerate} = options;
|
const {column, description, conversationId, state} = options;
|
||||||
const tableId = column.table.peek().tableId.peek();
|
const tableId = column.table.peek().tableId.peek();
|
||||||
const colId = column.colId.peek();
|
const colId = column.colId.peek();
|
||||||
const result = await grist.docApi.getAssistance({
|
return await grist.docApi.getAssistance({
|
||||||
conversationId,
|
conversationId,
|
||||||
context: {type: 'formula', tableId, colId},
|
context: {type: 'formula', tableId, colId},
|
||||||
text: description,
|
text: description,
|
||||||
state,
|
state,
|
||||||
regenerate,
|
|
||||||
});
|
});
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Builds avatar image for user or assistant. */
|
/** Builds avatar image for user or assistant. */
|
||||||
|
@ -41,8 +41,6 @@ export interface AssistanceRequest {
|
|||||||
context: AssistanceContext;
|
context: AssistanceContext;
|
||||||
state?: AssistanceState;
|
state?: AssistanceState;
|
||||||
text: string;
|
text: string;
|
||||||
// TODO this is no longer used and should be removed
|
|
||||||
regenerate?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -362,19 +362,10 @@ class EchoAssistant implements Assistant {
|
|||||||
role: 'system',
|
role: 'system',
|
||||||
content: ''
|
content: ''
|
||||||
});
|
});
|
||||||
messages.push({
|
|
||||||
role: 'user', content: request.text,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (request.regenerate) {
|
|
||||||
if (messages[messages.length - 1].role !== 'user') {
|
|
||||||
messages.pop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
messages.push({
|
messages.push({
|
||||||
role: 'user', content: request.text,
|
role: 'user', content: request.text,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
const completion = request.text;
|
const completion = request.text;
|
||||||
const history = { messages };
|
const history = { messages };
|
||||||
history.messages.push({
|
history.messages.push({
|
||||||
@ -412,9 +403,6 @@ export async function sendForCompletion(
|
|||||||
doc: AssistanceDoc,
|
doc: AssistanceDoc,
|
||||||
request: AssistanceRequest,
|
request: AssistanceRequest,
|
||||||
): Promise<AssistanceResponse> {
|
): Promise<AssistanceResponse> {
|
||||||
if (request.regenerate) {
|
|
||||||
throw new Error('regenerate no longer supported');
|
|
||||||
}
|
|
||||||
const assistant = getAssistant();
|
const assistant = getAssistant();
|
||||||
return await assistant.apply(optSession, doc, request);
|
return await assistant.apply(optSession, doc, request);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user