Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion console/atest-ui/src/views/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const ExtensionKindRedis = "atest-store-redis"
const ExtensionKindMongoDB = "atest-store-mongodb"
const ExtensionKindElasticsearch = "atest-store-elasticsearch"
const ExtensionKindOpengeMini = "atest-store-opengemini"
const ExtensionKindAI = "atest-ext-ai"

export const ExtensionKind = {
ExtensionKindGit,
Expand All @@ -68,7 +69,8 @@ export const ExtensionKind = {
ExtensionKindRedis,
ExtensionKindMongoDB,
ExtensionKindElasticsearch,
ExtensionKindOpengeMini
ExtensionKindOpengeMini,
ExtensionKindAI
}

const storeExtensions = [
Expand Down Expand Up @@ -170,6 +172,36 @@ const storeExtensions = [
name: ExtensionKindOpengeMini,
params: [],
link: 'https://github.com/LinuxSuRen/atest-ext-store-opengemini'
},
{
name: ExtensionKindAI,
params: [{
key: 'model_provider',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个变量该怎么用呢?下面的接口里没有体现到。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另外,接口的定义后续会重构。大体的思路是:

  1. 在单独的仓库里定义;
  2. 启动的时候,下载并解析相关文件
  3. 提供对应的接口,前端获取所有支持的插件

LinuxSuRen/atest-ext-data-swagger#1
#803

重构完成后再调整即可。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个变量该怎么用呢?下面的接口里没有体现到。

ExtensionKindAI 变量定义了AI扩展的配置参数:

  • model_provider : AI模型提供商(ollama, openai)
  • model_name : 具体模型名称(如llama3.2)
  • api_key : 外部提供商的认证密钥
  • base_url : AI服务端点URL
  • temperature : 控制响应随机性(0.0-1.0)
  • max_tokens : 最大响应长度

这些参数通过 GenerateContentRequest.parameters 字段传递给AI服务,用于配置AI模型的行为。在接口中作为 parameters 映射传递给AI扩展服务。

defaultValue: 'ollama',
enum: ['ollama', 'openai'],
description: 'AI model provider used in GenerateContentRequest.parameters for content generation'
}, {
key: 'model_name',
defaultValue: 'llama3.2',
description: 'AI model name passed to GenerateContentRequest.parameters["model_name"] for specific model selection'
}, {
key: 'api_key',
defaultValue: '',
description: 'API key for external providers, used in GenerateContentRequest.parameters["api_key"] for authentication'
}, {
key: 'base_url',
defaultValue: 'http://localhost:11434',
description: 'Base URL for AI service, used in GenerateContentRequest.parameters["base_url"] to specify service endpoint'
}, {
key: 'temperature',
defaultValue: '0.7',
description: 'Controls randomness in AI responses (0.0-1.0), passed via GenerateContentRequest.parameters["temperature"]'
}, {
key: 'max_tokens',
defaultValue: '2048',
description: 'Maximum tokens in AI response, used in GenerateContentRequest.parameters["max_tokens"] to limit output length'
}],
link: 'https://github.com/LinuxSuRen/atest-ext-ai'
}
] as Store[]

Expand Down
62 changes: 62 additions & 0 deletions extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,68 @@
| Agent | [collector](https://github.com/LinuxSuRen/atest-ext-collector) | |
| Secret | [Vault](https://github.com/LinuxSuRen/api-testing-vault-extension) | |
| Data | [Swagger](https://github.com/LinuxSuRen/atest-ext-data-swagger) | |
| AI | [ai-extension](https://github.com/LinuxSuRen/atest-ext-ai) | 50051 |

## AI Extension Interface

Check notice on line 20 in extensions/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

extensions/README.md#L20

Expected: [None]; Actual: ## AI Extension Interface

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.

Check notice on line 22 in extensions/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

extensions/README.md#L22

Expected: 80; Actual: 179

### Available Services

#### GenerateContent (Recommended)

Check notice on line 26 in extensions/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

extensions/README.md#L26

Expected: 1; Actual: 0; Below
A general-purpose AI interface that can handle multiple content types:
- **SQL Generation**: Convert natural language to SQL queries

Check notice on line 28 in extensions/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

extensions/README.md#L28

Lists should be surrounded by blank lines
- **Test Case Generation**: Automatically generate test cases based on API specifications
- **Mock Service Creation**: Generate mock services and responses
- **Test Data Generation**: Create realistic test data using AI models
- **Result Analysis**: Intelligent analysis of test results and failure patterns

**Request Parameters:**
- `prompt`: Natural language description of what to generate

Check notice on line 35 in extensions/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

extensions/README.md#L35

Lists should be surrounded by blank lines
- `contentType`: Type of content ("sql", "testcase", "mock", "analysis")
- `context`: Additional context information (schemas, API specs, etc.)
- `sessionId`: Optional session ID for conversational context
- `parameters`: AI model configuration (model_provider, model_name, api_key, etc.)

#### GenerateSQLFromNaturalLanguage (Legacy)

Check notice on line 41 in extensions/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

extensions/README.md#L41

Expected: 1; Actual: 0; Below
Specific interface for SQL generation, maintained for backward compatibility.

### Configuration Parameters

These parameters are configured in the store extension settings and passed to the AI service:

Check notice on line 46 in extensions/README.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

extensions/README.md#L46

Expected: 80; Actual: 93

- `model_provider`: AI provider ("ollama", "openai") - used in GenerateContentRequest.parameters
- `model_name`: Specific model name (e.g., "llama3.2", "gpt-4") - passed via parameters["model_name"]
- `api_key`: Authentication key for external providers - used in parameters["api_key"]
- `base_url`: Service endpoint URL - specified in parameters["base_url"]
- `temperature`: Response randomness control (0.0-1.0) - set via parameters["temperature"]
- `max_tokens`: Maximum response length - controlled by parameters["max_tokens"]

### Usage Examples

```protobuf
// Generate SQL query
GenerateContentRequest {
prompt: "Show me all users from California"
contentType: "sql"
context: {
"schema": "CREATE TABLE users (id INT, name VARCHAR(100), state VARCHAR(50))"
}
parameters: {
"model_provider": "ollama"
"model_name": "llama3.2"
}
}

// Generate test case
GenerateContentRequest {
prompt: "Create a test case for user registration API"
contentType: "testcase"
context: {
"api_spec": "POST /api/users {name, email, password}"
}
}
```

## Contribute a new extension

Expand Down
140 changes: 140 additions & 0 deletions pkg/server/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,27 @@ service ThemeExtension {
}
}

// AIExtension service provides AI-powered capabilities for atest.
service AIExtension {
// Generates content based on natural language prompts with context.
// This is a general-purpose AI interface that can handle SQL generation,
// test case writing, mock service creation, and other AI-powered tasks.
rpc GenerateContent (GenerateContentRequest) returns (GenerateContentResponse) {
option (google.api.http) = {
post: "/api/v1/ai/generate"
body: "*"
};
}

// Legacy SQL generation endpoint for backward compatibility
rpc GenerateSQLFromNaturalLanguage (GenerateSQLRequest) returns (GenerateSQLResponse) {
option (google.api.http) = {
post: "/api/v1/ai/sql/generate"
body: "*"
};
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

既然有一个通用的内容升成的接口了,为什么还需要一个SQL这种特定的内容生成接口呢?这里有两个疑问:

  1. 通用的是否可以包含 SQL 这种特定场景的使用
  2. 把通用的一个接口和特定领域的接口放在一起不是很和谐,就好比把水果和苹果放在一起一样

Copy link
Contributor Author

@KariHall619 KariHall619 Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

既然有一个通用的内容升成的接口了,为什么还需要一个SQL这种特定的内容生成接口呢?这里有两个疑问:

  1. 通用的是否可以包含 SQL 这种特定场景的使用
  2. 把通用的一个接口和特定领域的接口放在一起不是很和谐,就好比把水果和苹果放在一起一样

1.为何保留: 本想保留SQL接口仅作为向后兼容 :在代码注释中标记为"Legacy",计划在未来版本中废弃(其实可以不用, 主要是培养良好习惯预防在发行的项目中直接更新导致出现问题.
2.为何出现这样的情况: 当时编码时有一个疑惑;“在做“SQL generation,test case writing, mock service creation”这些不同任务的时候, 需不需要不同的接口来提示我在执行的时候是在做哪一个任务?”, 在思考时有些混乱, 导致这个地方修改时候的逻辑有些混乱.

已在commit-e0bdb7中解决此问题


message Suites {
map<string, Items> data = 1;
}
Expand Down Expand Up @@ -697,3 +718,122 @@ message DataMeta {
string duration = 4;
repeated Pair labels = 5;
}

// AI Extension related messages

// Enum for supported database dialects to ensure type safety.
enum DatabaseType {
// DATABASE_TYPE_UNSPECIFIED indicates a missing or unknown database type.
DATABASE_TYPE_UNSPECIFIED = 0;
MYSQL = 1;
POSTGRESQL = 2;
SQLITE = 3;
}

// Represents an example pair of natural language to SQL for few-shot prompting.
message QueryExample {
// A natural language query example.
string naturalLanguagePrompt = 1;
// The corresponding correct SQL query for the prompt.
string sqlQuery = 2;
}

// Request message for generating content based on natural language prompts.
message GenerateContentRequest {
// The user's prompt in natural language.
string prompt = 1;
// The type of content to generate (e.g., "sql", "testcase", "mock").
string contentType = 2;
// Context information to help with generation.
map<string, string> context = 3;
// Optional: A session identifier to maintain context across multiple requests.
optional string sessionId = 4;
// Optional: Additional parameters specific to the content type.
map<string, string> parameters = 5;
}

// Request message for generating an SQL query from natural language.
message GenerateSQLRequest {
// The user's query in natural language. (e.g., "show me all users from California")
string naturalLanguageInput = 1;
// Target database dialect for SQL generation.
DatabaseType databaseType = 2;
// Optional: A list of DDL statements (e.g., CREATE TABLE …) for relevant tables.
// Providing schemas helps the AI generate more accurate queries.
repeated string schemas = 3;
// Optional: A session identifier to maintain context across multiple requests,
// enabling conversational query refinement.
optional string sessionId = 4;
// Optional: A list of examples to guide the AI, improving accuracy for
// specific or complex domains.
repeated QueryExample examples = 5;
}

// Response message containing the result of content generation.
message GenerateContentResponse {
// The response can be one of the following types.
oneof result {
// Contains the successful content generation details.
ContentSuccessResponse success = 1;
// Contains details about why the generation failed.
ErrorResponse error = 2;
}
}

// Response message containing the result of the SQL generation.
message GenerateSQLResponse {
// The response can be one of the following types.
oneof result {
// Contains the successful SQL generation details.
SuccessResponse success = 1;
// Contains details about why the generation failed.
ErrorResponse error = 2;
}
}

// Represents a successful content generation.
message ContentSuccessResponse {
// The generated content.
string content = 1;
// The type of content that was generated.
string contentType = 2;
// An explanation of how the AI interpreted the request and generated the content.
// This builds user trust and aids in debugging.
optional string explanation = 3;
// A score between 0.0 and 1.0 indicating the AI's confidence in the generated content.
optional float confidenceScore = 4;
// Additional metadata about the generation process.
map<string, string> metadata = 5;
}

// Represents a successful SQL generation.
message SuccessResponse {
// The generated SQL query.
string sqlQuery = 1;
// An explanation of how the AI interpreted the request and generated the SQL.
// This builds user trust and aids in debugging.
optional string explanation = 2;
// A score between 0.0 and 1.0 indicating the AI's confidence in the generated query.
optional float confidenceScore = 3;
}

// Enum for structured error codes.
enum ErrorCode {
ERROR_CODE_UNSPECIFIED = 0;
// The input was invalid (e.g., empty prompt).
INVALID_ARGUMENT = 1;
// The AI model failed to translate the query.
TRANSLATION_FAILED = 2;
// The requested database type is not supported.
UNSUPPORTED_DATABASE = 3;
// An internal error occurred in the service.
INTERNAL_ERROR = 4;
}

// Represents a failed SQL generation attempt.
message ErrorResponse {
// A structured error code for programmatic handling.
ErrorCode code = 1;
// A human-readable message describing the error.
string message = 2;
}
Loading