Skip to content

Commit 2d9f356

Browse files
Copilothuangyiirene
andcommitted
feat: Add 4 AI-powered example applications (Support, Analyst, CodeGen, Sales)
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 5d73b22 commit 2d9f356

12 files changed

Lines changed: 1107 additions & 0 deletions

File tree

examples/ai-analyst/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# AI Data Analyst
2+
3+
> **Natural Language Query system for business intelligence**
4+
5+
## Overview
6+
7+
AI-powered data analyst that transforms natural language questions into ObjectQL queries and generates insights.
8+
9+
## Features
10+
11+
- **Natural Language Queries**: Ask questions in plain English
12+
- **Auto-generate Dashboards**: Create visualizations from queries
13+
- **Insights Generation**: AI-powered data analysis
14+
- **Query Templates**: Pre-built query patterns
15+
16+
## Example Queries
17+
18+
- "What's our total revenue by region for Q1?"
19+
- "Show me the top 10 customers by lifetime value"
20+
- "Compare this month's sales to last month"
21+
- "Which products have declining sales?"
22+
23+
## NLQ Configuration
24+
25+
```typescript
26+
export const AnalystNLQConfig: NLQModelConfig = {
27+
modelId: 'gpt-4-turbo',
28+
includeSchema: true,
29+
includeExamples: true,
30+
enableIntentDetection: true,
31+
enableTimeframeDetection: true,
32+
enableFuzzyMatching: true,
33+
};
34+
```
35+
36+
## Agent
37+
38+
```typescript
39+
export const DataAnalystAgent: Agent = {
40+
name: 'data_analyst_ai',
41+
role: 'Business Intelligence Analyst',
42+
tools: [
43+
{ type: 'query', name: 'execute_sql' },
44+
{ type: 'action', name: 'create_dashboard' },
45+
{ type: 'action', name: 'generate_chart' },
46+
],
47+
};
48+
```
49+
50+
## Use Cases
51+
52+
1. **Executive Dashboards**: Auto-generate KPI dashboards
53+
2. **Ad-hoc Analysis**: Answer business questions instantly
54+
3. **Report Generation**: Create formatted reports from queries
55+
4. **Data Exploration**: Discover patterns and anomalies

examples/ai-analyst/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@objectstack/example-ai-analyst",
3+
"version": "1.0.0",
4+
"description": "AI-powered data analyst with natural language query capabilities",
5+
"private": true,
6+
"main": "objectstack.config.ts",
7+
"scripts": {
8+
"dev": "tsx watch objectstack.config.ts",
9+
"build": "tsc"
10+
},
11+
"dependencies": {
12+
"@objectstack/spec": "workspace:*"
13+
}
14+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import type { Agent, NLQModelConfig, QueryTemplate } from '@objectstack/spec';
2+
3+
/**
4+
* AI Data Analyst Agent
5+
*/
6+
export const DataAnalystAgent: Agent = {
7+
name: 'data_analyst_ai',
8+
label: 'AI Data Analyst',
9+
role: 'Business Intelligence Analyst',
10+
11+
instructions: `You are a data analyst helping users understand their business metrics.
12+
13+
Skills:
14+
- Interpret natural language questions about data
15+
- Generate ObjectQL queries
16+
- Create visualizations
17+
- Provide actionable insights
18+
19+
Be precise, data-driven, and clear in explanations.`,
20+
21+
model: {
22+
provider: 'openai',
23+
model: 'gpt-4',
24+
temperature: 0.3,
25+
maxTokens: 4096,
26+
},
27+
28+
tools: [
29+
{
30+
type: 'query',
31+
name: 'execute_objectql',
32+
description: 'Execute ObjectQL queries on data',
33+
},
34+
{
35+
type: 'action',
36+
name: 'create_dashboard',
37+
description: 'Generate dashboard from metrics',
38+
},
39+
{
40+
type: 'action',
41+
name: 'generate_chart',
42+
description: 'Create charts and visualizations',
43+
},
44+
{
45+
type: 'query',
46+
name: 'get_schema',
47+
description: 'Get object schema information',
48+
},
49+
],
50+
51+
access: ['analysts', 'executives', 'managers'],
52+
active: true,
53+
};
54+
55+
/**
56+
* NLQ Configuration for Business Intelligence
57+
*/
58+
export const AnalystNLQConfig: NLQModelConfig = {
59+
modelId: 'gpt-4',
60+
systemPrompt: `You are an expert at converting business questions into ObjectQL queries.
61+
62+
Available objects: account, opportunity, task, product, order
63+
Be precise with field names and support timeframes like "last quarter", "this year".`,
64+
65+
includeSchema: true,
66+
includeExamples: true,
67+
enableIntentDetection: true,
68+
intentThreshold: 0.75,
69+
enableEntityRecognition: true,
70+
enableFuzzyMatching: true,
71+
fuzzyMatchThreshold: 0.85,
72+
enableTimeframeDetection: true,
73+
defaultTimeframe: 'current_month',
74+
enableCaching: true,
75+
cacheTTL: 3600,
76+
};
77+
78+
/**
79+
* Common Query Templates
80+
*/
81+
export const AnalystQueryTemplates: QueryTemplate[] = [
82+
{
83+
id: 'top-n-by-field',
84+
name: 'top_n_by_field',
85+
label: 'Top N Records by Field',
86+
pattern: 'top {n} {object} by {field}',
87+
variables: [
88+
{ name: 'n', type: 'value', required: true },
89+
{ name: 'object', type: 'object', required: true },
90+
{ name: 'field', type: 'field', required: true },
91+
],
92+
astTemplate: {
93+
object: '{object}',
94+
sort: [{ field: '{field}', order: 'desc' }],
95+
limit: '{n}',
96+
},
97+
category: 'ranking',
98+
examples: [
99+
'top 10 accounts by revenue',
100+
'top 5 products by sales',
101+
],
102+
},
103+
104+
{
105+
id: 'aggregate-by-group',
106+
name: 'aggregate_by_group',
107+
label: 'Aggregate by Group',
108+
pattern: 'total {field} by {group_field}',
109+
variables: [
110+
{ name: 'field', type: 'field', required: true },
111+
{ name: 'group_field', type: 'field', required: true },
112+
],
113+
astTemplate: {
114+
fields: [
115+
'{group_field}',
116+
{ function: 'sum', field: '{field}', alias: 'total' },
117+
],
118+
groupBy: ['{group_field}'],
119+
},
120+
category: 'aggregation',
121+
examples: [
122+
'total revenue by region',
123+
'total orders by product',
124+
],
125+
},
126+
127+
{
128+
id: 'time-comparison',
129+
name: 'time_comparison',
130+
label: 'Time Period Comparison',
131+
pattern: 'compare {metric} for {period1} vs {period2}',
132+
variables: [
133+
{ name: 'metric', type: 'field', required: true },
134+
{ name: 'period1', type: 'timeframe', required: true },
135+
{ name: 'period2', type: 'timeframe', required: true },
136+
],
137+
astTemplate: {
138+
// Complex comparison logic
139+
},
140+
category: 'comparison',
141+
examples: [
142+
'compare revenue for this month vs last month',
143+
'compare sales for Q1 vs Q2',
144+
],
145+
},
146+
];

examples/ai-codegen/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# AI Code Generator
2+
3+
> **Generate ObjectStack applications from natural language descriptions**
4+
5+
## Overview
6+
7+
AI-powered code generator that creates complete ObjectStack applications from high-level requirements.
8+
9+
## Features
10+
11+
- **App Generation**: Create full apps from descriptions
12+
- **Schema Generation**: Generate object definitions
13+
- **Validation**: Ensure generated code follows best practices
14+
- **Test Generation**: Auto-generate tests for objects
15+
16+
## Example Usage
17+
18+
**Input**: "Create a project management app with projects, tasks, and team members. Projects should have milestones and budgets. Tasks can be assigned to team members with due dates and priorities."
19+
20+
**Output**: Complete ObjectStack application with:
21+
- Object definitions (Project, Task, TeamMember, Milestone)
22+
- Relationships (lookup fields)
23+
- Validation rules
24+
- List views and forms
25+
- Navigation structure
26+
- Reports and dashboards
27+
28+
## Agent Configuration
29+
30+
```typescript
31+
export const CodeGenAgent: Agent = {
32+
name: 'objectstack_code_generator',
33+
role: 'Senior ObjectStack Developer',
34+
35+
tools: [
36+
{ type: 'action', name: 'generate_object' },
37+
{ type: 'action', name: 'generate_field' },
38+
{ type: 'action', name: 'generate_view' },
39+
{ type: 'action', name: 'validate_schema' },
40+
],
41+
42+
knowledge: {
43+
topics: ['objectstack_patterns', 'best_practices', 'examples'],
44+
indexes: ['objectstack_docs'],
45+
},
46+
};
47+
```
48+
49+
## Capabilities
50+
51+
1. **Object Schema Generation**: Field types, validation, relationships
52+
2. **UI Generation**: Views, forms, dashboards
53+
3. **Logic Generation**: Workflows, validations, triggers
54+
4. **Best Practices**: Follows naming conventions and patterns
55+
56+
## Success Criteria
57+
58+
- Generated code passes all validations
59+
- Follows ObjectStack conventions (camelCase, snake_case)
60+
- Includes appropriate indexes and constraints
61+
- Complete with UI configuration

examples/ai-codegen/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@objectstack/example-ai-codegen",
3+
"version": "1.0.0",
4+
"description": "AI code generator - Generate ObjectStack apps from natural language",
5+
"private": true,
6+
"main": "objectstack.config.ts",
7+
"dependencies": {
8+
"@objectstack/spec": "workspace:*"
9+
}
10+
}

0 commit comments

Comments
 (0)