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

Method getDSL

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

Source from the content-addressed store, hash-verified

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