mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Add AI Assistant retry with shorter prompt
Summary: If the longer OpenAI model exceeds the OpenAPI context length, we now perform another retry with a shorter variant of the formula prompt. The shorter prompt excludes non-referenced tables and lookup method definitions, which should help reduce token usage in documents with larger schemas. Test Plan: Server test. Reviewers: JakubSerafin Reviewed By: JakubSerafin Subscribers: JakubSerafin Differential Revision: https://phab.getgrist.com/D4184
This commit is contained in:
@@ -160,7 +160,7 @@ def get_formula_prompt(engine, table_id, col_id, _description,
|
||||
other_tables = (all_other_tables(engine, table_id)
|
||||
if include_all_tables else referenced_tables(engine, table_id))
|
||||
for other_table_id in sorted(other_tables):
|
||||
result += class_schema(engine, other_table_id, lookups)
|
||||
result += class_schema(engine, other_table_id, None, lookups)
|
||||
|
||||
result += class_schema(engine, table_id, col_id, lookups)
|
||||
|
||||
|
||||
@@ -146,8 +146,9 @@ def run(sandbox):
|
||||
return objtypes.encode_object(eng.get_formula_error(table_id, col_id, row_id))
|
||||
|
||||
@export
|
||||
def get_formula_prompt(table_id, col_id, description):
|
||||
return formula_prompt.get_formula_prompt(eng, table_id, col_id, description)
|
||||
def get_formula_prompt(table_id, col_id, description, include_all_tables=True, lookups=True):
|
||||
return formula_prompt.get_formula_prompt(eng, table_id, col_id, description,
|
||||
include_all_tables, lookups)
|
||||
|
||||
@export
|
||||
def convert_formula_completion(completion):
|
||||
|
||||
Reference in New Issue
Block a user