pref(provider):优化provider架构#93
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Member
|
PR body 目前没有抓住重点。reviewer 首先需要知道的是:
请先把这 3 点写清楚,再写收益、测试和风险。否则信息很多,但决策不清晰。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明
本次重构优化provider模块架构,主要解决以下问题:
通过配置集中化、删除冗余实现、修复并发安全,提升代码质量和系统稳定性。
主要改动
1. Provider配置集中管理
新增文件:
internal/config/builtin_providers.go改动内容:
DefaultProviders()函数返回所有内置provider配置影响范围:
internal/provider/builtin/builtin.go:改用config.DefaultProviders()BuiltinConfig()函数2. 删除冗余Provider实现
删除文件:
internal/provider/gemini/gemini.go(31行)internal/provider/gemini/gemini_test.go(31行)internal/provider/openll/openll.go(30行)internal/provider/openll/openll_test.go(43行)删除原因:
3. 修复Runtime并发安全问题
改动文件:
internal/runtime/runtime.go:123改动前:
改动后:
解决问题:
ResolvedSelectedProvider()返回的快照4. 消除重复代码
改动文件:
internal/provider/service.go删除函数:
改用统一实现:
影响函数:
SetCurrentModel(service.go:113)selectModel(service.go:136)5. 其他优化
builtin包简化:
测试更新:
预期收益
代码质量提升
系统稳定性增强
架构设计优化
测试验证
单元测试
测试文件:
internal/provider/registry_test.go- 10个测试函数internal/provider/builtin/builtin_test.go- 1个测试函数internal/provider/openai/openai_test.go- 9个测试函数关键测试场景:
TestServiceSelectProviderAndSetCurrentModelTestServiceSelectProviderRejectsUnsupportedDriverTestServiceListProvidersUsesConfiguredMetadataTestProviderChatConsumesSSEAndMergesToolCallsTestProviderChatHTTPErrorResponses集成测试
主链路验证:
验证项:
回归测试
执行命令:
测试结果:
风险评估
低风险
Fixes #94