Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 21 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,24 @@ 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: ollama or openai'
}, {
key: 'model_name',
defaultValue: 'llama3.2',
description: 'AI model name'
}, {
key: 'api_key',
defaultValue: '',
description: 'API key for external providers (e.g., OpenAI)'
}],
link: 'https://github.com/LinuxSuRen/atest-ext-ai'
}
] as Store[]

Expand Down
1 change: 1 addition & 0 deletions extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Ports in extensions:
| 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 |

## Contribute a new extension

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

// AIExtension service provides AI-powered capabilities for atest.
service AIExtension {
// Translates a natural language query into an SQL query, providing
// context and explanations for better accuracy and user trust.
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.

接口测试用例的编写、Mock 服务的编写后续也要有 AI 的支持,到时候该怎么做呢?新增接口?还是可以提供一个更加通用的接口呢?本质上都是根据提示(prompt)生成 thinking 和最终的反馈(SQL,或者是其他的)。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到. 考虑到后续的延展性, 我选择升级提供一个更加通用的接口GenerateContent来处理此类任务.


message Suites {
map<string, Items> data = 1;
}
Expand Down Expand Up @@ -697,3 +709,82 @@ 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 natural_language_prompt = 1;
// The corresponding correct SQL query for the prompt.
string sql_query = 2;
}

// 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 natural_language_input = 1;
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
Contributor Author

Choose a reason for hiding this comment

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

收到,已按要求改动.

// Target database dialect for SQL generation.
DatabaseType database_type = 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 session_id = 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 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 SQL generation.
message SuccessResponse {
// The generated SQL query.
string sql_query = 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 confidence_score = 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