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

Method getDSL

src/query/javascript.ts:65–87  ·  view source on GitHub ↗
(query: string, dataModel: DataModel)

Source from the content-addressed store, hash-verified

63 constructor(private readonly llmConfig: LLMConfig) {}
64
65 async getDSL(query: string, dataModel: DataModel): Promise<TranslationResult> {
66 const { text, usage, finishReason } = await generateText({
67 model: languageModel(this.llmConfig),
68 maxRetries: this.llmConfig.maxRetries ?? 3,
69 prompt: `You are a data analysis expert. Generate JavaScript code to answer the question.
70
71Dataset Context:
72${stringifyDataModel(dataModel)}
73
74User Query: ${query}
75
76${this.rules}
77
78Return only executable JavaScript code, without explanation or Markdown.`,
79 });
80 if (finishReason !== 'stop' && finishReason !== 'other') {
81 throw new Error(`JavaScript generation did not complete (${finishReason})`);
82 }
83 const trimmed = text.trim();
84 const dsl = (trimmed.match(/^```(?:javascript|js)?[ \t]*\r?\n([\s\S]*?)\r?\n```$/i)?.[1] ?? trimmed).trim();
85 if (!dsl) throw new Error('JavaScript generation returned empty code');
86 return { dsl, usage };
87 }
88
89 async validateDSL(code: string): Promise<string> {
90 if (!code.trim()) throw new Error('JavaScript query must contain code');

Callers

nothing calls this directly

Calls 2

languageModelFunction · 0.90
stringifyDataModelFunction · 0.90

Tested by

no test coverage detected