mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
add support for conversational state to assistance endpoint (#506)
* add support for conversational state to assistance endpoint This refactors the assistance code somewhat, to allow carrying along some conversational state. It extends the OpenAI-flavored assistant to make use of that state to have a conversation. The front-end is tweaked a little bit to allow for replies that don't have any code in them (though I didn't get into formatting such replies nicely). Currently tested primarily through the runCompletion script, which has been extended a bit to allow testing simulated conversations (where an error is pasted in follow-up, or an expected-vs-actual comparison). Co-authored-by: George Gevoian <85144792+georgegevoian@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {ActionGroup} from 'app/common/ActionGroup';
|
||||
import {Prompt, Suggestion} from 'app/common/AssistancePrompts';
|
||||
import {AssistanceRequest, AssistanceResponse} from 'app/common/AssistancePrompts';
|
||||
import {BulkAddRecord, CellValue, TableDataAction, UserAction} from 'app/common/DocActions';
|
||||
import {FormulaProperties} from 'app/common/GranularAccessClause';
|
||||
import {UIRowId} from 'app/common/UIRowId';
|
||||
@@ -323,7 +323,7 @@ export interface ActiveDocAPI {
|
||||
/**
|
||||
* Generates a formula code based on the AI suggestions, it also modifies the column and sets it type to a formula.
|
||||
*/
|
||||
getAssistance(userPrompt: Prompt): Promise<Suggestion>;
|
||||
getAssistance(request: AssistanceRequest): Promise<AssistanceResponse>;
|
||||
|
||||
/**
|
||||
* Fetch content at a url.
|
||||
|
||||
@@ -1,11 +1,56 @@
|
||||
import {DocAction} from 'app/common/DocActions';
|
||||
|
||||
export interface Prompt {
|
||||
tableId: string;
|
||||
colId: string
|
||||
description: string;
|
||||
/**
|
||||
* State related to a request for assistance.
|
||||
*
|
||||
* If an AssistanceResponse contains state, that state can be
|
||||
* echoed back in an AssistanceRequest to continue a "conversation."
|
||||
*
|
||||
* Ideally, the state should not be modified or relied upon
|
||||
* by the client, so as not to commit too hard to a particular
|
||||
* model at this time (it is a bit early for that).
|
||||
*/
|
||||
export interface AssistanceState {
|
||||
messages?: Array<{
|
||||
role: string;
|
||||
content: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface Suggestion {
|
||||
suggestedActions: DocAction[];
|
||||
/**
|
||||
* Currently, requests for assistance always happen in the context
|
||||
* of the column of a particular table.
|
||||
*/
|
||||
export interface FormulaAssistanceContext {
|
||||
type: 'formula';
|
||||
tableId: string;
|
||||
colId: string;
|
||||
}
|
||||
|
||||
export type AssistanceContext = FormulaAssistanceContext;
|
||||
|
||||
/**
|
||||
* A request for assistance.
|
||||
*/
|
||||
export interface AssistanceRequest {
|
||||
context: AssistanceContext;
|
||||
state?: AssistanceState;
|
||||
text: string;
|
||||
regenerate?: boolean; // Set if there was a previous request
|
||||
// and response that should be omitted
|
||||
// from history, or (if available) an
|
||||
// alternative response generated.
|
||||
}
|
||||
|
||||
/**
|
||||
* A response to a request for assistance.
|
||||
* The client should preserve the state and include it in
|
||||
* any follow-up requests.
|
||||
*/
|
||||
export interface AssistanceResponse {
|
||||
suggestedActions: DocAction[];
|
||||
state?: AssistanceState;
|
||||
// If the model can be trusted to issue a self-contained
|
||||
// markdown-friendly string, it can be included here.
|
||||
reply?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user