-
Notifications
You must be signed in to change notification settings - Fork 61
feat: Added AI extension support and SQL generation APIs #804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
1f4d036
14edd88
e955c68
e0bdb76
4eddc7b
eff1d43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: "*" | ||
| }; | ||
| } | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 既然有一个通用的内容升成的接口了,为什么还需要一个SQL这种特定的内容生成接口呢?这里有两个疑问:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
1.为何保留: 本想保留SQL接口仅作为向后兼容 :在代码注释中标记为"Legacy",计划在未来版本中废弃(其实可以不用, 主要是培养良好习惯预防在发行的项目中直接更新导致出现问题. 已在commit-e0bdb7中解决此问题 |
||
|
|
||
| message Suites { | ||
| map<string, Items> data = 1; | ||
| } | ||
|
|
@@ -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; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个变量该怎么用呢?下面的接口里没有体现到。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
另外,接口的定义后续会重构。大体的思路是:
LinuxSuRen/atest-ext-data-swagger#1
#803
重构完成后再调整即可。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExtensionKindAI 变量定义了AI扩展的配置参数:
这些参数通过 GenerateContentRequest.parameters 字段传递给AI服务,用于配置AI模型的行为。在接口中作为 parameters 映射传递给AI扩展服务。