-
Notifications
You must be signed in to change notification settings - Fork 629
/
Copy pathadaptor.ts
236 lines (204 loc) Β· 4.79 KB
/
adaptor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import * as Errors from '@server/utils/error';
import { Manifest } from '@server/mdl/type';
export interface WrenAIError {
code: Errors.GeneralErrorCodes;
message: string;
}
export enum WrenAIDeployStatusEnum {
SUCCESS = 'SUCCESS',
FAILED = 'FAILED',
}
export interface WrenAIDeployResponse {
status: WrenAIDeployStatusEnum;
error?: string;
}
export enum WrenAISystemStatus {
INDEXING = 'INDEXING',
FINISHED = 'FINISHED',
FAILED = 'FAILED',
}
export enum WrenAILanguage {
EN = 'English',
ES = 'Spanish',
FR = 'French',
ZH_TW = 'Traditional Chinese',
ZH_CN = 'Simplified Chinese',
DE = 'German',
PT = 'Portuguese',
RU = 'Russian',
JA = 'Japanese',
KO = 'Korean',
}
export interface DeployData {
manifest: Manifest;
hash: string;
}
// ask
export interface AskStep {
summary: string;
sql: string;
cteName: string;
}
export interface AskHistory {
sql: string;
steps: Array<AskStep>;
}
export interface AskConfigurations {
language?: string;
timezone?: { name: string };
}
export interface AskInput {
query: string;
deployId: string;
history?: AskHistory;
configurations?: AskConfigurations;
}
export interface AsyncQueryResponse {
queryId: string;
}
export enum AskResultStatus {
UNDERSTANDING = 'UNDERSTANDING',
SEARCHING = 'SEARCHING',
GENERATING = 'GENERATING',
CORRECTING = 'CORRECTING',
FINISHED = 'FINISHED',
FAILED = 'FAILED',
STOPPED = 'STOPPED',
}
export enum AskResultType {
GENERAL = 'GENERAL',
TEXT_TO_SQL = 'TEXT_TO_SQL',
MISLEADING_QUERY = 'MISLEADING_QUERY',
}
// if it's view, viewId will be returned as well. It means the candidate is originally saved in mdl as a view.
// if it's llm, viewId will not be returned. It means the candidate is generated by AI service.
export enum AskCandidateType {
VIEW = 'VIEW',
LLM = 'LLM',
}
export interface AskResponse<R, S> {
type: AskResultType | null;
status: S;
response: R | null;
error: WrenAIError | null;
}
export interface AskDetailInput {
query: string;
sql: string;
configurations?: AskConfigurations;
}
export type AskDetailResult = AskResponse<
{
description: string;
steps: AskStep[];
},
AskResultStatus
>;
export type AskResult = AskResponse<
Array<{
type: AskCandidateType;
sql: string;
viewId?: number | null;
}>,
AskResultStatus
> & {
intentReasoning?: string;
};
export enum RecommendationQuestionStatus {
GENERATING = 'GENERATING',
FINISHED = 'FINISHED',
FAILED = 'FAILED',
}
export type RecommendationQuestionsInput = {
// JSON string of the MDL (Model Definition Language)
manifest: Manifest;
// Optional list of previous questions
previousQuestions?: string[];
// Optional project ID
projectId?: string;
// Optional max number of questions to generate (default: 5)
maxQuestions?: number;
// Optional max number of categories (default: 3)
maxCategories?: number;
regenerate?: boolean; // Optional regenerate questions (default: false)
// Optional configuration settings
configuration?: AskConfigurations;
};
export type RecommendationQuestion = {
question: string;
category: string; // category for the question
sql: string; // validated sql for this question, can be used in generateAskDetail
};
export type RecommendationQuestionsResult = AskResponse<
{
questions: RecommendationQuestion[];
},
RecommendationQuestionStatus
>;
// text-based answer
export interface TextBasedAnswerInput {
query: string;
sql: string;
sqlData: any;
threadId?: string;
userId?: string;
configurations?: AskConfigurations;
}
export enum TextBasedAnswerStatus {
PREPROCESSING = 'PREPROCESSING',
SUCCEEDED = 'SUCCEEDED',
FAILED = 'FAILED',
}
export interface TextBasedAnswerResult {
status: TextBasedAnswerStatus;
numRowsUsedInLLM?: number;
error?: WrenAIError;
}
export enum ChartStatus {
FETCHING = 'FETCHING',
GENERATING = 'GENERATING',
FINISHED = 'FINISHED',
FAILED = 'FAILED',
STOPPED = 'STOPPED',
}
export enum ChartType {
BAR = 'bar',
GROUPED_BAR = 'grouped_bar',
STACKED_BAR = 'stacked_bar',
LINE = 'line',
MULTI_LINE = 'multi_line',
PIE = 'pie',
AREA = 'area',
}
export interface ChartInput {
query: string;
sql: string;
projectId?: string;
configurations?: AskConfigurations;
}
export interface ChartAdjustmentOption {
chartType: ChartType;
xAxis?: string;
yAxis?: string;
xOffset?: string;
color?: string;
theta?: string;
}
export interface ChartAdjustmentInput {
query: string;
sql: string;
adjustmentOption: ChartAdjustmentOption;
chartSchema: Record<string, any>;
projectId?: string;
configurations?: AskConfigurations;
}
export interface ChartResponse {
reasoning: string;
chartType: ChartType;
chartSchema: Record<string, any>;
}
export interface ChartResult {
status: ChartStatus;
response?: ChartResponse;
error?: WrenAIError;
}