Skip to content

Add proxy configuration support in .env.example and base_client#57

Closed
daytime001 wants to merge 3 commits intoErlichLiu:mainfrom
daytime001:fix_debug_issue47
Closed

Add proxy configuration support in .env.example and base_client#57
daytime001 wants to merge 3 commits intoErlichLiu:mainfrom
daytime001:fix_debug_issue47

Conversation

@daytime001
Copy link
Copy Markdown

本地部署完成后,调用api请求deepgemini模型报以下错误:

经排查后发现问题出在代理上,在调用gemini时对网络有要求,因此设置了两个代理相关的环境变量USE_PROXYPROXY_URL,并在base_client文件中进行了相应修改。

修改完成后可供用户自主选择是否使用代理,如Gemini等模型则必须使用,其它选择直连即可

@GowayLee GowayLee self-requested a review February 27, 2025 05:32
Comment thread .env.example
# 代理配置
USE_PROXY=false # 是否使用代理,默认不使用.如使用请改为true,并修改PROXY_URL为对应代理地址
PROXY_URL=http://127.0.0.1:7890 # 代理服务器地址,如不填写则不使用代理.此处默认为Clash,如果使用其他代理,需改为对应的代理地址

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

可以将这两个环境变量合并为一个, 例如:

  • 设置PROXY_URL=false, 在读取环境变量时添加一个判断逻辑, 直接完成proxy是否为None的设置.


# 根据环境变量决定是否使用代理
proxy = self.proxy_url if self.use_proxy else None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

proxy声明为成员变量, base_client实例化时即可确定proxy的值. 未来发送请求时只需要传入self.proxy, 可优化该if判断.

@GowayLee GowayLee self-assigned this Feb 27, 2025
@GowayLee GowayLee added enhancement New feature or request good first issue Good for newcomers labels Feb 27, 2025
@GowayLee GowayLee linked an issue Feb 27, 2025 that may be closed by this pull request
@GowayLee
Copy link
Copy Markdown
Collaborator

感谢您的贡献, 支持Proxy是一个很关键的功能.

但是在实际使用场景中, 如果存在多个Provider配置, 能够将Provider区分配置Proxy将会是更好的体验.

目前 #52 实现了相对更加灵活的配置方案, 但是依然缺少Proxy配置. 在 #52 基础上应该可以实现Provider独立配置Proxy. 前往dev分支即可查看最新的配置实现方案.

@GowayLee
Copy link
Copy Markdown
Collaborator

GowayLee commented Mar 5, 2025

已在v1.0.0中支持

@GowayLee GowayLee closed this Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

支持系统代理调用

2 participants