Skip to content

Commit 14edd88

Browse files
committed
你feat: implement unified AI extension service with gRPC interface
- Add AI extension protobuf definitions with GenerateSQLFromNaturalLanguage RPC - Implement unified LLM service architecture with BaseLLMConnector interface - Update field naming to camelCase for consistency with generated protobuf code - Refactor OllamaConnector and OpenAIConnector to extend BaseLLMConnector - Add comprehensive error handling and response formatting - Integrate gRPC server with reflection support for better debugging - Update protobuf generation to support Python 3.8+ compatibility Breaking Changes: - Field names in protobuf messages now use camelCase format - LLM connector interface has been restructured for better extensibility Tested with: Python 3.8+, gRPC 1.60+, protobuf 4.25+
1 parent 1f4d036 commit 14edd88

File tree

3 files changed

+134
-12
lines changed

3 files changed

+134
-12
lines changed

console/atest-ui/src/views/store.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,27 @@ const storeExtensions = [
179179
key: 'model_provider',
180180
defaultValue: 'ollama',
181181
enum: ['ollama', 'openai'],
182-
description: 'AI model provider: ollama or openai'
182+
description: 'AI model provider used in GenerateContentRequest.parameters for content generation'
183183
}, {
184184
key: 'model_name',
185185
defaultValue: 'llama3.2',
186-
description: 'AI model name'
186+
description: 'AI model name passed to GenerateContentRequest.parameters["model_name"] for specific model selection'
187187
}, {
188188
key: 'api_key',
189189
defaultValue: '',
190-
description: 'API key for external providers (e.g., OpenAI)'
190+
description: 'API key for external providers, used in GenerateContentRequest.parameters["api_key"] for authentication'
191+
}, {
192+
key: 'base_url',
193+
defaultValue: 'http://localhost:11434',
194+
description: 'Base URL for AI service, used in GenerateContentRequest.parameters["base_url"] to specify service endpoint'
195+
}, {
196+
key: 'temperature',
197+
defaultValue: '0.7',
198+
description: 'Controls randomness in AI responses (0.0-1.0), passed via GenerateContentRequest.parameters["temperature"]'
199+
}, {
200+
key: 'max_tokens',
201+
defaultValue: '2048',
202+
description: 'Maximum tokens in AI response, used in GenerateContentRequest.parameters["max_tokens"] to limit output length'
191203
}],
192204
link: 'https://github.com/LinuxSuRen/atest-ext-ai'
193205
}

extensions/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,67 @@ Ports in extensions:
1717
| Data | [Swagger](https://github.com/LinuxSuRen/atest-ext-data-swagger) | |
1818
| AI | [ai-extension](https://github.com/LinuxSuRen/atest-ext-ai) | 50051 |
1919

20+
## AI Extension Interface
21+
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.
23+
24+
### Available Services
25+
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
33+
34+
**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.
43+
44+
### Configuration Parameters
45+
46+
These parameters are configured in the store extension settings and passed to the AI service:
47+
48+
- `model_provider`: AI provider ("ollama", "openai") - used in GenerateContentRequest.parameters
49+
- `model_name`: Specific model name (e.g., "llama3.2", "gpt-4") - passed via parameters["model_name"]
50+
- `api_key`: Authentication key for external providers - used in parameters["api_key"]
51+
- `base_url`: Service endpoint URL - specified in parameters["base_url"]
52+
- `temperature`: Response randomness control (0.0-1.0) - set via parameters["temperature"]
53+
- `max_tokens`: Maximum response length - controlled by parameters["max_tokens"]
54+
55+
### Usage Examples
56+
57+
```protobuf
58+
// Generate SQL query
59+
GenerateContentRequest {
60+
prompt: "Show me all users from California"
61+
contentType: "sql"
62+
context: {
63+
"schema": "CREATE TABLE users (id INT, name VARCHAR(100), state VARCHAR(50))"
64+
}
65+
parameters: {
66+
"model_provider": "ollama"
67+
"model_name": "llama3.2"
68+
}
69+
}
70+
71+
// Generate test case
72+
GenerateContentRequest {
73+
prompt: "Create a test case for user registration API"
74+
contentType: "testcase"
75+
context: {
76+
"api_spec": "POST /api/users {name, email, password}"
77+
}
78+
}
79+
```
80+
2081
## Contribute a new extension
2182

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

pkg/server/server.proto

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,17 @@ service ThemeExtension {
332332

333333
// AIExtension service provides AI-powered capabilities for atest.
334334
service AIExtension {
335-
// Translates a natural language query into an SQL query, providing
336-
// context and explanations for better accuracy and user trust.
335+
// Generates content based on natural language prompts with context.
336+
// This is a general-purpose AI interface that can handle SQL generation,
337+
// test case writing, mock service creation, and other AI-powered tasks.
338+
rpc GenerateContent (GenerateContentRequest) returns (GenerateContentResponse) {
339+
option (google.api.http) = {
340+
post: "/api/v1/ai/generate"
341+
body: "*"
342+
};
343+
}
344+
345+
// Legacy SQL generation endpoint for backward compatibility
337346
rpc GenerateSQLFromNaturalLanguage (GenerateSQLRequest) returns (GenerateSQLResponse) {
338347
option (google.api.http) = {
339348
post: "/api/v1/ai/sql/generate"
@@ -724,28 +733,53 @@ enum DatabaseType {
724733
// Represents an example pair of natural language to SQL for few-shot prompting.
725734
message QueryExample {
726735
// A natural language query example.
727-
string natural_language_prompt = 1;
736+
string naturalLanguagePrompt = 1;
728737
// The corresponding correct SQL query for the prompt.
729-
string sql_query = 2;
738+
string sqlQuery = 2;
739+
}
740+
741+
// Request message for generating content based on natural language prompts.
742+
message GenerateContentRequest {
743+
// The user's prompt in natural language.
744+
string prompt = 1;
745+
// The type of content to generate (e.g., "sql", "testcase", "mock").
746+
string contentType = 2;
747+
// Context information to help with generation.
748+
map<string, string> context = 3;
749+
// Optional: A session identifier to maintain context across multiple requests.
750+
optional string sessionId = 4;
751+
// Optional: Additional parameters specific to the content type.
752+
map<string, string> parameters = 5;
730753
}
731754

732755
// Request message for generating an SQL query from natural language.
733756
message GenerateSQLRequest {
734757
// The user's query in natural language. (e.g., "show me all users from California")
735-
string natural_language_input = 1;
758+
string naturalLanguageInput = 1;
736759
// Target database dialect for SQL generation.
737-
DatabaseType database_type = 2;
760+
DatabaseType databaseType = 2;
738761
// Optional: A list of DDL statements (e.g., CREATE TABLE …) for relevant tables.
739762
// Providing schemas helps the AI generate more accurate queries.
740763
repeated string schemas = 3;
741764
// Optional: A session identifier to maintain context across multiple requests,
742765
// enabling conversational query refinement.
743-
optional string session_id = 4;
766+
optional string sessionId = 4;
744767
// Optional: A list of examples to guide the AI, improving accuracy for
745768
// specific or complex domains.
746769
repeated QueryExample examples = 5;
747770
}
748771

772+
// Response message containing the result of content generation.
773+
message GenerateContentResponse {
774+
// The response can be one of the following types.
775+
oneof result {
776+
// Contains the successful content generation details.
777+
ContentSuccessResponse success = 1;
778+
// Contains details about why the generation failed.
779+
ErrorResponse error = 2;
780+
}
781+
}
782+
749783
// Response message containing the result of the SQL generation.
750784
message GenerateSQLResponse {
751785
// The response can be one of the following types.
@@ -757,15 +791,30 @@ message GenerateSQLResponse {
757791
}
758792
}
759793

794+
// Represents a successful content generation.
795+
message ContentSuccessResponse {
796+
// The generated content.
797+
string content = 1;
798+
// The type of content that was generated.
799+
string contentType = 2;
800+
// An explanation of how the AI interpreted the request and generated the content.
801+
// This builds user trust and aids in debugging.
802+
optional string explanation = 3;
803+
// A score between 0.0 and 1.0 indicating the AI's confidence in the generated content.
804+
optional float confidenceScore = 4;
805+
// Additional metadata about the generation process.
806+
map<string, string> metadata = 5;
807+
}
808+
760809
// Represents a successful SQL generation.
761810
message SuccessResponse {
762811
// The generated SQL query.
763-
string sql_query = 1;
812+
string sqlQuery = 1;
764813
// An explanation of how the AI interpreted the request and generated the SQL.
765814
// This builds user trust and aids in debugging.
766815
optional string explanation = 2;
767816
// A score between 0.0 and 1.0 indicating the AI's confidence in the generated query.
768-
optional float confidence_score = 3;
817+
optional float confidenceScore = 3;
769818
}
770819

771820
// Enum for structured error codes.

0 commit comments

Comments
 (0)