-
Notifications
You must be signed in to change notification settings - Fork 702
feat(ai-proxy): add batches & files support #2355
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
Conversation
Signed-off-by: Xijun Dai <[email protected]>
Signed-off-by: Xijun Dai <[email protected]>
…/v1/batches/{batche_id} Signed-off-by: Xijun Dai <[email protected]>
Signed-off-by: Xijun Dai <[email protected]>
feat(ai-proxy): 添加对/v1/files和/v1/batches接口的支持变更文件
时序图Sequence diagram for API routing logic
participant Client
participant Router as AIProxyRouter
participant Provider as OpenAI/QwenProvider
Client->>Router: 发送/v1/files或/v1/batches请求
Router->>Router: 通过getApiName解析路径
Router->>Provider: 调用对应接口处理逻辑
Provider-->>Router: 返回处理结果
Router-->>Client: 响应客户端请求
💡 小贴士与 lingma-agents 交流的方式📜 直接回复评论
📜 在代码行处标记
📜 在讨论中提问
|
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.
🔍 代码评审报告
📋 评审意见详情
💡 单文件建议
✅ 未发现需要特别关注的代码问题。
🚀 跨文件建议
以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍 1. 路径匹配逻辑可能导致API路由错误
在main.go
的getApiName
函数中,新增的/v1/batches
和/v1/files
路径检查使用strings.Contains
代替原来的strings.HasSuffix
。这种模糊匹配可能导致误判,例如路径/v1/batchses/example
会被错误识别为ApiNameBatches
。建议改为精确匹配如strings.HasSuffix
或使用路由框架的精确路径匹配,以避免路由逻辑错误。
📌 关键代码:
+if strings.Contains(path, "/v1/batches") {
+ return provider.ApiNameBatches
+}
+if strings.Contains(path, "/v1/files") {
+ return provider.ApiNameFiles
- 未指定文件
🔍 2. 兼容模式路径映射不完整风险
在qwen.go
的DefaultCapabilities
方法中,新增的qwenCompatibleFilesPath
和qwenCompatibleBatchesPath
路径未在非兼容模式下映射,可能导致非兼容模式下文件/批次API不可用。需检查所有新增功能是否在两种模式下均有对应路径定义。
📌 关键代码:
+string(ApiNameFiles): qwenCompatibleFilesPath,
+string(ApiNameBatches): qwenCompatibleBatchesPath,
🔍 3. API路由逻辑架构不一致
新增的/v1/batches
和/v1/files
端点采用路径包含匹配,而原有/v1/models
等端点使用后缀匹配。建议统一整个项目的API路径匹配策略(如全部使用精确后缀匹配或路由框架),避免混合模式导致的维护复杂度增加。
📌 关键代码:
+if strings.Contains(path, "/v1/batches") {
🔍 4. Qwen兼容模式路径覆盖不完整
在qwen.go
的GetApiName
函数中,新增的兼容路径如qwenCompatibleChatCompletionPath
被正确识别,但未检查原有非兼容路径的覆盖情况。需确保所有新增功能在两种模式下的路径均被路由逻辑覆盖,避免功能缺失。
📌 关键代码:
+strings.Contains(path, qwenCompatibleChatCompletionPath):
+return ApiNameChatCompletion
💡 小贴士
与 lingma-agents 交流的方式
📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:
-
在当前代码中添加详细的注释说明。
-
请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。
📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:
-
@Lingma-Agent 分析这个方法的性能瓶颈并提供优化建议。
-
@Lingma-Agent 对这个方法生成优化代码。
📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:
-
@Lingma-Agent 请总结上述讨论并提出解决方案。
-
@Lingma-Agent 请根据讨论内容生成优化代码。
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2355 +/- ##
===========================================
+ Coverage 35.91% 46.06% +10.15%
===========================================
Files 69 81 +12
Lines 11576 13010 +1434
===========================================
+ Hits 4157 5993 +1836
+ Misses 7104 6671 -433
- Partials 315 346 +31 🚀 New features to boost your workflow:
|
if strings.HasSuffix(path, "/v1/batches") { | ||
return provider.ApiNameBatches | ||
} |
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.
对, 这里是写重复了, 我移除掉
Signed-off-by: Xijun Dai <[email protected]>
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.
LGTM
Ⅰ. Describe what this PR did
添加 openai 、 Qwen 对 /v1/files 与 /v1/batches 接口的支持
Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
以通义千问为例
docker-compose.yaml
envoy.yaml
Upload file
List files
Retrieve File
Create Batch
List Batches
Retrieve Batch
Ⅴ. Special notes for reviews