Skip to content

Conversation

@daixijun
Copy link
Contributor

@daixijun daixijun commented Jun 4, 2025

Ⅰ. Describe what this PR did

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews


Ⅰ. Describe what this PR did

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

V. Special notes for reviews

@daixijun daixijun requested review from CH3CHO, cr7258 and rinfx as code owners June 4, 2025 02:30
@github-actions github-actions bot changed the title feat(ai-proxy): 修复 openai 配置 openaiCustomUrl 之后, 对不支持 Api 透传路径错误的问题 feat(ai-proxy): 修复 openai 配置 openaiCustomUrl 之后, 对不支持 Api 透传路径错误的问题 || feat(ai-proxy): Fixed the issue that the API pass-through path error does not support openaiCustomUrl after openai is configured. Jun 4, 2025
@lingma-agents
Copy link

lingma-agents bot commented Jun 4, 2025

修复OpenAI自定义路径导致API路由路径错误的问题

变更文件

文件路径 变更说明
plugins/​wasm-go/​extensions/​ai-proxy/​provider/​openai.go 修改TransformRequestHeaders方法的路径处理逻辑: 1. 新增对isDirectCustomPath和apiName非空的联合判断条件 2. 调整util.OverwriteRequestPathHeaderByCapability的调用时机 3. 简化customPath非空时的条件分支结构 4. 统一customDomain存在时的Host头设置方式

💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @Lingma-Agent 分析这个方法的性能瓶颈并提供优化建议。

  • @Lingma-Agent 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @Lingma-Agent 请总结上述讨论并提出解决方案。

  • @Lingma-Agent 请根据讨论内容生成优化代码。

Copy link

@lingma-agents lingma-agents bot left a comment

Choose a reason for hiding this comment

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

🔍 代码评审报告

📋 评审意见详情

💡 单文件建议

✅ 未发现需要特别关注的代码问题。

🚀 跨文件建议

以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍 1. 条件判断逻辑变更可能导致路径处理不完整

修改后的TransformRequestHeaders函数将条件从m.customPath != ""简化为m.customPath != "" && !m.isDirectCustomPath && apiName != "",可能导致以下情况未被正确处理:

  1. m.isDirectCustomPath为true时,原逻辑会直接设置customPath,但新逻辑会跳过路径处理
  2. apiName为空时,原逻辑会直接设置customPath,但新逻辑会跳过路径处理
    这些场景可能与用户配置的openaiCustomUrl意图不符,导致API请求路径错误。

📌 关键代码:

if m.customPath != "" && !m.isDirectCustomPath && apiName != "" {
    util.OverwriteRequestPathHeaderByCapability(headers, string(apiName), m.config.capabilities)
}

⚠️ 潜在风险: - 配置了直接路径但未指定API名称时,可能导致路径透传失败

  • API名称为空的请求可能使用错误路径格式
  • 需补充测试用例覆盖isDirectCustomPath=trueapiName==""场景
🔍 2. 跨Provider的路径处理逻辑一致性风险

该修改改变了OpenAI provider的路径处理逻辑,但未检查其他AI provider(如Anthropic/Azure)是否采用相同处理模式。若其他provider仍保留原条件结构,可能导致:

  1. 不同服务对customPath配置的响应方式不一致
  2. 配置迁移或统一管理时出现兼容性问题
    需确认所有AI provider的路径处理逻辑是否需要同步调整。

⚠️ 潜在风险: - 多服务配置管理复杂度增加

  • 潜在的配置冲突风险
  • 需进行跨provider架构一致性评审
🔍 3. 技术债务:条件判断可读性降低

将原多分支条件合并为单条件判断,虽然减少了代码量,但隐藏了业务逻辑的关键分支(如对isDirectCustomPath的处理)。这可能导致:

  1. 后续维护者难以理解!m.isDirectCustomPath的业务含义
  2. 配置参数变更时容易引入新问题
    建议:
  • 将复合条件拆分为多个布尔变量
  • 添加注释说明各条件组合的业务含义

📌 关键代码:

if m.customPath != "" && !m.isDirectCustomPath && apiName != "" {

⚠️ 潜在风险: - 技术债务累积导致后续修改成本增加

  • 需要额外文档补充解释条件含义
🔍 4. 测试覆盖策略不完整

当前修改未提供新增测试用例信息,可能存在以下未覆盖场景:

  1. m.isDirectCustomPath = true时的路径处理
  2. apiName == ""时的路径处理
  3. customDomaincustomPath同时配置时的组合情况
    需补充测试用例覆盖这些核心配置组合,尤其是边界条件。

⚠️ 潜在风险: - 未覆盖场景可能导致线上配置错误

  • 需进行全配置组合的集成测试验证

💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @Lingma-Agent 分析这个方法的性能瓶颈并提供优化建议。

  • @Lingma-Agent 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @Lingma-Agent 请总结上述讨论并提出解决方案。

  • @Lingma-Agent 请根据讨论内容生成优化代码。

@codecov-commenter
Copy link

codecov-commenter commented Jun 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.07%. Comparing base (ef31e09) to head (44bd1b7).
Report is 540 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2364       +/-   ##
===========================================
+ Coverage   35.91%   46.07%   +10.16%     
===========================================
  Files          69       81       +12     
  Lines       11576    13010     +1434     
===========================================
+ Hits         4157     5995     +1838     
+ Misses       7104     6670      -434     
- Partials      315      345       +30     

see 78 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@johnlanni johnlanni left a comment

Choose a reason for hiding this comment

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

LGTM

@CH3CHO CH3CHO merged commit 5674d91 into alibaba:main Jun 6, 2025
24 of 28 checks passed
@daixijun daixijun deleted the fix/custom-path branch June 10, 2025 07:46
ink-hz pushed a commit to ink-hz/higress-ai-capability-auth that referenced this pull request Nov 5, 2025
…| feat(ai-proxy): Fixed the issue that the API pass-through path error does not support openaiCustomUrl after openai is configured. (alibaba#2364)

Signed-off-by: Xijun Dai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants