Skip to content

Commit dda0d50

Browse files
author
xueren.dt
committed
fix(ava): fix render bug
1 parent 3e12bee commit dda0d50

4 files changed

Lines changed: 22 additions & 17 deletions

File tree

packages/ava/src/advisor/advisor.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-dupe-class-members */
12
import {
23
AdviseChartParams,
34
AdviseStageOutput,
@@ -10,14 +11,14 @@ import { extractData } from '@ava/extract';
1011

1112
import { logError } from '../utils';
1213
import { getRenderer, type Spec } from '../bind';
14+
1315
import { AdviseChartPipeline } from './advise-chart-pipeline/pipeline';
1416

1517
/**
1618
* The 1st level advisor class.
1719
* Used to extract data, recommend charts, and render charts. All functionalities are AI-driven.
1820
*/
1921
export class Advisor {
20-
2122
/**
2223
* Configuration for the advisor. Includes LLM settings, chart inclusion/exclusion lists.
2324
*/
@@ -36,13 +37,13 @@ export class Advisor {
3637

3738
/**
3839
* Extract data shards from raw data or user query.
39-
*
40+
*
4041
* Case 1 - User provides a text query, extract relevant data shards:
41-
*
42+
*
4243
advisor.extract('What is the average age of people who work as engineers?');
43-
*
44+
*
4445
* Case 2 - User provides a query with raw data:
45-
*
46+
*
4647
advisor.extract(`帮我可视化以下数据:
4748
城市 类别 渠道 销售额 价格
4849
杭州 体育 A 100 80
@@ -51,9 +52,9 @@ export class Advisor {
5152
广州 体育 B 120 70
5253
深圳 体育 C 180 95
5354
`);
54-
*
55+
*
5556
* Case 3 - User provides raw data, extract data shards directly:
56-
*
57+
*
5758
advisor.extract({ type: 'A', value: 2 });
5859
*/
5960
async extract(params: AdviseChartParams) {
@@ -66,41 +67,42 @@ export class Advisor {
6667
/**
6768
* Advise charts based on the data shards, which are extracted from the `advisor.extract` API.
6869
* This is the core function of the Advisor class, which leverages LLMs to recommend suitable chart types and encodings based on the provided data and user purpose.
69-
*
70+
*
7071
* const advises = advisor.advise(dataShards);
7172
*/
7273
advise(params: AdviseChartParams): Promise<AdviseStageOutput>;
74+
7375
advise(params: AdviseTextParams): Promise<AdviseText>;
76+
7477
async advise(params: AdviseChartParams | AdviseTextParams): Promise<AdviseStageOutput | AdviseText> {
7578
const result = await this.adviseChartPipeline.execute(params as AdviseChartParams);
7679
return result;
7780
}
7881

7982
/**
8083
* Render the chart recommendation spec into a chart dom. We can use different renderers by customizing the renderer.
81-
*
84+
*
8285
* Case 1 - Using default renderer (AVA built-in):
83-
*
86+
*
8487
advisor.render({
8588
container: '#chart',
8689
spec: chartSpec,
8790
});
88-
*
91+
*
8992
* Case 2 - Using custom renderer:
90-
*
93+
*
9194
const customRenderer: Renderer = (container, spec) => { ... };
9295
bindRenderer(customRenderer);
9396
advisor.render({
9497
container: '#chart',
9598
spec: chartSpec,
9699
});
97-
*
100+
*
98101
*/
99102
render(params: { container: string; spec: Spec }) {
100103
const renderer = getRenderer();
101104
if (renderer) {
102-
const { container, spec } = params;
103-
return renderer(container, spec);
105+
return renderer(params);
104106
}
105107
logError('Chart render not configured, please bind a renderer first, GPT-Vis is recommended.');
106108
return null;

packages/ava/src/advisor/chartAdvise/prompt/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ Output the “best chart type (chartId)” with the rationale for selection, and
236236
237237
# Response Format (JSON)
238238
- Only output a JSON two-dimensional array of “short codes”. Each item is a string array (up to 3, ordered from highest to lowest match). Do not output any extra text, e.g., [["l", "a", "c"], ["b", "c"]].
239+
- Output MUST be a plain JSON string; do not use Markdown code fences (e.g., \`\`\`JSON).
239240
240241
# Chart Knowledge Base (CKB)
241242
## Chart Types and Codes (object array)
@@ -341,6 +342,7 @@ export const getSpecGeneratePrompt = (params: { chartId: string; data: PlainLike
341342
- Single input: return only the JSON configuration object.
342343
- Batch input: return only the JSON array of configuration objects in the same order as input.
343344
- In all cases, do not include extra text, explanations, or code fences.
345+
- Output MUST be a plain JSON string; do not use Markdown code fences (e.g., \`\`\`JSON).
344346
345347
# Chart InputSchema
346348
${inputSchema}

packages/ava/src/bind.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// import type { Spec } from '@antv/gpt-vis';
33
export type Spec = any;
44

5-
export type Renderer = (container: string, spec: Spec) => void;
5+
export type Renderer = (params: { container: string; spec: Spec }) => void;
66

77
// The renderer function bound from outside.
88
// Default is null.

playground/src/utils/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import React from 'react';
22

33
import ReactDOM from 'react-dom/client';
44
import { DEFAULT_CHART_COMPONENTS } from '@antv/gpt-vis';
5+
import { Spec } from '../../../packages/ava/src/bind';
56

6-
export const render = (params: any) => {
7+
export const render = (params: { container: string; spec: Spec }) => {
78
const { container, spec } = params || {};
89
const mount =
910
typeof container === 'string' ? (document.querySelector(container) as HTMLElement) : (container as HTMLElement);

0 commit comments

Comments
 (0)