(query: string, dataModel: DataModel, signal?: AbortSignal)
| 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 | |
| 34 | Dataset Context: |
| 35 | ${stringifyDataModel(dataModel)} |
| 36 | |
| 37 | User Query: ${query} |
| 38 | |
| 39 | ${this.rules} |
| 40 | |
| 41 | Return 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); |
nothing calls this directly
no test coverage detected