Skip to content

Commit e0bdb76

Browse files
committed
Refactor: Removed legacy SQL generation APIs and unified with GenerateContent.
Migrated all SQL generation functionality to the unified GenerateContent API, using the contentType parameter to differentiate between task types. Removed the deprecated GenerateSQLFromNaturalLanguage API and related data structures to simplify the code structure. Updated documentation to explain how to use the new unified API, including supported content types and migration guidelines.
1 parent e955c68 commit e0bdb76

File tree

6 files changed

+393
-977
lines changed

6 files changed

+393
-977
lines changed

extensions/README.md

Lines changed: 107 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,76 @@ Ports in extensions:
1919

2020
## AI Extension Interface
2121

22-
The AI extension provides intelligent testing capabilities through gRPC interface on port 50051. It offers a unified AI interface that can handle various content generation tasks.
22+
This extension provides AI-powered content generation capabilities through a unified gRPC interface.
2323

24-
### Available Services
24+
### Unified Interface Design
2525

26-
#### GenerateContent (Recommended)
27-
A general-purpose AI interface that can handle multiple content types:
28-
- **SQL Generation**: Convert natural language to SQL queries
29-
- **Test Case Generation**: Automatically generate test cases based on API specifications
30-
- **Mock Service Creation**: Generate mock services and responses
31-
- **Test Data Generation**: Create realistic test data using AI models
32-
- **Result Analysis**: Intelligent analysis of test results and failure patterns
26+
#### `GenerateContent`
27+
The single, unified interface for all AI content generation tasks. This interface can handle various content types including SQL generation, test case writing, mock service creation, and more through a single endpoint.
3328

3429
**Request Parameters:**
35-
- `prompt`: Natural language description of what to generate
36-
- `contentType`: Type of content ("sql", "testcase", "mock", "analysis")
37-
- `context`: Additional context information (schemas, API specs, etc.)
38-
- `sessionId`: Optional session ID for conversational context
39-
- `parameters`: AI model configuration (model_provider, model_name, api_key, etc.)
40-
41-
#### GenerateSQLFromNaturalLanguage (Legacy)
42-
Specific interface for SQL generation, maintained for backward compatibility.
30+
- `prompt`: Natural language description of what you want to generate
31+
- `contentType`: Type of content to generate (e.g., "sql", "testcase", "mock")
32+
- `context`: Additional context information as key-value pairs
33+
- `parameters`: Additional parameters specific to the content type
34+
35+
**Response:**
36+
- `success.content`: Generated content
37+
- `success.explanation`: Explanation of the generated content
38+
- `success.confidenceScore`: Confidence score (0.0 to 1.0)
39+
- `success.metadata`: Additional metadata about the generation
40+
- `error`: Error information if generation fails
41+
42+
### Content Types and Task Identification
43+
44+
The `contentType` parameter serves as the task identifier, allowing the system to:
45+
46+
1. **Apply appropriate prompting strategies** for different content types
47+
2. **Use specialized processing logic** for each task type
48+
3. **Provide task-specific validation and post-processing**
49+
4. **Generate relevant metadata** for each content type
50+
51+
#### Supported Content Types:
52+
53+
1. **SQL Generation** (`contentType: "sql"`)
54+
- Generates SQL queries from natural language
55+
- Supports multiple database types via parameters
56+
- Context can include schema information
57+
- Applies SQL-specific validation and dialect adaptation
58+
59+
2. **Test Case Generation** (`contentType: "testcase"`)
60+
- Generates comprehensive test cases
61+
- Context can include code specifications
62+
- Uses test-specific prompting strategies
63+
64+
3. **Mock Service Generation** (`contentType: "mock"`)
65+
- Generates mock services and API responses
66+
- Context can include API specifications
67+
- Applies service-specific formatting
68+
69+
4. **Generic Content** (any other `contentType`)
70+
- Handles any other content generation requests
71+
- Flexible prompt-based generation
72+
- Extensible for future content types
73+
74+
### Architecture Benefits
75+
76+
**Single Interface Advantages:**
77+
- **Consistency**: All content generation follows the same request/response pattern
78+
- **Extensibility**: New content types can be added without API changes
79+
- **Simplicity**: Clients only need to integrate with one interface
80+
- **Flexibility**: Rich context and parameter support for all content types
81+
82+
**Task Differentiation:**
83+
While using a single interface, the system internally routes requests to specialized handlers based on `contentType`, ensuring:
84+
- Appropriate AI model prompting for each task
85+
- Task-specific validation and processing
86+
- Relevant metadata and confidence scoring
87+
- Optimized performance for different content types
4388

4489
### Configuration Parameters
4590

46-
These parameters are configured in the store extension settings and passed to the AI service:
91+
The following parameters can be passed via `GenerateContentRequest.parameters`:
4792

4893
- `model_provider`: AI provider ("ollama", "openai") - used in GenerateContentRequest.parameters
4994
- `model_name`: Specific model name (e.g., "llama3.2", "gpt-4") - passed via parameters["model_name"]
@@ -65,6 +110,7 @@ GenerateContentRequest {
65110
parameters: {
66111
"model_provider": "ollama"
67112
"model_name": "llama3.2"
113+
"database_type": "mysql"
68114
}
69115
}
70116
@@ -76,8 +122,51 @@ GenerateContentRequest {
76122
"api_spec": "POST /api/users {name, email, password}"
77123
}
78124
}
125+
126+
// Generate mock service
127+
GenerateContentRequest {
128+
prompt: "Create a mock REST API for user management"
129+
contentType: "mock"
130+
context: {
131+
"endpoints": "GET /users, POST /users, PUT /users/{id}, DELETE /users/{id}"
132+
"response_format": "JSON"
133+
}
134+
}
135+
```
136+
137+
### Migration Notes
138+
139+
This version removes the legacy `GenerateSQLFromNaturalLanguage` interface in favor of the unified `GenerateContent` approach. All SQL generation should now use:
140+
141+
```protobuf
142+
GenerateContentRequest {
143+
prompt: "your natural language query"
144+
contentType: "sql"
145+
parameters: {"database_type": "mysql|postgresql|sqlite"}
146+
context: {"schemas": "table definitions"}
147+
}
79148
```
80149

150+
### Frequently Asked Questions
151+
152+
**Q1: Do I need different interfaces for different tasks (SQL generation, test case writing, mock service creation)?**
153+
154+
A: No, you only need the single `GenerateContent` interface. The `contentType` parameter tells the system what kind of content you want to generate, and the system internally routes your request to the appropriate specialized handler. This design provides:
155+
- **Task identification**: The system knows exactly what you're trying to accomplish
156+
- **Specialized processing**: Each content type gets optimized prompting and validation
157+
- **Consistent API**: You always use the same interface regardless of the task
158+
- **Future extensibility**: New content types can be added without changing the API
159+
160+
**Q2: Will removing the SQL-specific interface affect other files?**
161+
162+
A: The removal has been carefully implemented to ensure minimal impact:
163+
- **Protobuf files**: All generated code (Go, Python, gRPC-gateway, OpenAPI) has been updated
164+
- **Implementation files**: The Python gRPC server has been updated to use the new unified interface
165+
- **Backward compatibility**: While the old interface is removed, the same functionality is available through `GenerateContent` with `contentType: "sql"`
166+
- **No breaking changes**: The core functionality remains the same, just accessed through a cleaner, unified interface
167+
168+
The migration ensures that all SQL generation capabilities are preserved while providing a more maintainable and extensible architecture.
169+
81170
## Contribute a new extension
82171

83172
* First, create a repository. And please keep the same naming convertion.

0 commit comments

Comments
 (0)