MCPcopy Create free account
hub / github.com/antvis/AVA / getDSL

Method getDSL

src/query/python.ts:23–44  ·  view source on GitHub ↗
(query: string, dataModel: DataModel)

Source from the content-addressed store, hash-verified

21 constructor(private readonly llmConfig: LLMConfig, private readonly execute?: PythonEngineOptions['execute']) {}
22
23 async getDSL(query: string, dataModel: DataModel): Promise<TranslationResult> {
24 const { text, usage, finishReason } = await generateText({
25 model: languageModel(this.llmConfig),
26 maxRetries: this.llmConfig.maxRetries ?? 3,
27 prompt: `You are a data analysis expert. Generate Python code to answer the question.
28
29Dataset Context:
30${stringifyDataModel(dataModel)}
31
32User Query: ${query}
33
34${this.rules}
35
36Return only executable Python code, without explanation or Markdown.`,
37 });
38 if (finishReason !== 'stop' && finishReason !== 'other') {
39 throw new Error(`Python generation did not complete (${finishReason})`);
40 }
41 const dsl = text.trim().match(/^```(?:python|py)?[ \t]*\r?\n([\s\S]*?)\r?\n```$/i)?.[1] ?? text;
42 if (!dsl.trim()) throw new Error('Python generation returned empty code');
43 return { dsl, usage };
44 }
45
46 async validateDSL(code: string): Promise<string> {
47 if (!code.trim()) throw new Error('Python query must contain code');

Callers

nothing calls this directly

Calls 2

languageModelFunction · 0.90
stringifyDataModelFunction · 0.90

Tested by

no test coverage detected