-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathai-config.ts
More file actions
146 lines (133 loc) · 3.63 KB
/
ai-config.ts
File metadata and controls
146 lines (133 loc) · 3.63 KB
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
import type { Agent, NLQModelConfig, QueryTemplate } from '@objectstack/spec';
/**
* AI Data Analyst Agent
*/
export const DataAnalystAgent: Agent = {
name: 'data_analyst_ai',
label: 'AI Data Analyst',
role: 'Business Intelligence Analyst',
instructions: `You are a data analyst helping users understand their business metrics.
Skills:
- Interpret natural language questions about data
- Generate ObjectQL queries
- Create visualizations
- Provide actionable insights
Be precise, data-driven, and clear in explanations.`,
model: {
provider: 'openai',
model: 'gpt-4',
temperature: 0.3,
maxTokens: 4096,
},
tools: [
{
type: 'query',
name: 'execute_objectql',
description: 'Execute ObjectQL queries on data',
},
{
type: 'action',
name: 'create_dashboard',
description: 'Generate dashboard from metrics',
},
{
type: 'action',
name: 'generate_chart',
description: 'Create charts and visualizations',
},
{
type: 'query',
name: 'get_schema',
description: 'Get object schema information',
},
],
access: ['analysts', 'executives', 'managers'],
active: true,
};
/**
* NLQ Configuration for Business Intelligence
*/
export const AnalystNLQConfig: NLQModelConfig = {
modelId: 'gpt-4',
systemPrompt: `You are an expert at converting business questions into ObjectQL queries.
Available objects: account, opportunity, task, product, order
Be precise with field names and support timeframes like "last quarter", "this year".`,
includeSchema: true,
includeExamples: true,
enableIntentDetection: true,
intentThreshold: 0.75,
enableEntityRecognition: true,
enableFuzzyMatching: true,
fuzzyMatchThreshold: 0.85,
enableTimeframeDetection: true,
defaultTimeframe: 'current_month',
enableCaching: true,
cacheTTL: 3600,
};
/**
* Common Query Templates
*/
export const AnalystQueryTemplates: QueryTemplate[] = [
{
id: 'top-n-by-field',
name: 'top_n_by_field',
label: 'Top N Records by Field',
pattern: 'top {n} {object} by {field}',
variables: [
{ name: 'n', type: 'value', required: true },
{ name: 'object', type: 'object', required: true },
{ name: 'field', type: 'field', required: true },
],
astTemplate: {
object: '{object}',
sort: [{ field: '{field}', order: 'desc' }],
limit: '{n}',
},
category: 'ranking',
examples: [
'top 10 accounts by revenue',
'top 5 products by sales',
],
},
{
id: 'aggregate-by-group',
name: 'aggregate_by_group',
label: 'Aggregate by Group',
pattern: 'total {field} by {group_field}',
variables: [
{ name: 'field', type: 'field', required: true },
{ name: 'group_field', type: 'field', required: true },
],
astTemplate: {
fields: [
'{group_field}',
{ function: 'sum', field: '{field}', alias: 'total' },
],
groupBy: ['{group_field}'],
},
category: 'aggregation',
examples: [
'total revenue by region',
'total orders by product',
],
},
{
id: 'time-comparison',
name: 'time_comparison',
label: 'Time Period Comparison',
pattern: 'compare {metric} for {period1} vs {period2}',
variables: [
{ name: 'metric', type: 'field', required: true },
{ name: 'period1', type: 'timeframe', required: true },
{ name: 'period2', type: 'timeframe', required: true },
],
astTemplate: {
// Complex comparison logic
},
category: 'comparison',
examples: [
'compare revenue for this month vs last month',
'compare sales for Q1 vs Q2',
],
},
];