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

Method getDSL

src/query/python.ts:27–49  ·  view source on GitHub ↗
(query: string, dataModel: DataModel, signal?: AbortSignal)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

languageModelFunction · 0.90
stringifyDataModelFunction · 0.90

Tested by

no test coverage detected