Skip to content

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

KariHall619
Copy link
Contributor

@KariHall619 KariHall619 commented Aug 11, 2025

Connects #660

  • Added AI extension entry and default port to the README
  • Added AI extension type and configuration parameters to store.ts
  • Added AIExtension service and SQL generation related message definitions to server.proto

- Added AI extension entry and default port to the README
- Added AI extension type and configuration parameters to store.ts
- Added AIExtension service and SQL generation related message definitions to server.proto
@LinuxSuRen LinuxSuRen changed the title #660 feat: Added AI extension support and SQL generation APIs feat: Added AI extension support and SQL generation APIs Aug 11, 2025
@LinuxSuRen LinuxSuRen added the ospp 开源之夏 https://summer-ospp.ac.cn/ label Aug 11, 2025
// 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.

收到,已按要求改动.

{
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扩展服务。

Comment on lines 334 to 343
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来处理此类任务.

- 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+
Comment on lines 338 to 352
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中解决此问题

Copy link
Owner

@LinuxSuRen LinuxSuRen left a comment

Choose a reason for hiding this comment

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

你既然写了 proto 文件了,是需要执行下面的命令把对应的代码生成出来的:

make grpc grpc-gw

- Install and configure protobuf toolchain (protoc, protoc-gen-go, grpc-gateway)
- Successfully execute make grpc grpc-gw equivalent for api-testing project
- Generate Go protobuf files: server.pb.go, server.pb.gw.go, server_grpc.pb.go
- Generate loader and monitor protobuf files for remote testing
- Regenerate Python protobuf code: ai_extension_pb2.py, ai_extension_pb2_grpc.py
- Fix Python import paths: change absolute imports to relative imports
- Verify gRPC server functionality and service registration
- Confirm AI extension services (GenerateSQLFromNaturalLanguage, GenerateContent) are operational

Breaking changes: None
Tested: ✅ gRPC server starts successfully with all services registered
…eContent.

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.
Copy link

@LinuxSuRen
Copy link
Owner

@KariHall619 注意下代码冲突哈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ospp 开源之夏 https://summer-ospp.ac.cn/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants