mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-25 03:15:06 +08:00
feat: 以新的方式设置正向代理
This commit is contained in:
9
main.py
9
main.py
@@ -191,13 +191,16 @@ def start(first_time_init=False):
|
||||
|
||||
# 配置OpenAI proxy
|
||||
import openai
|
||||
openai.proxy = None # 先重置,因为重载后可能需要清除proxy
|
||||
openai.proxies = None # 先重置,因为重载后可能需要清除proxy
|
||||
if "http_proxy" in config.openai_config and config.openai_config["http_proxy"] is not None:
|
||||
openai.proxy = config.openai_config["http_proxy"]
|
||||
openai.proxies = {
|
||||
"http": config.openai_config["http_proxy"],
|
||||
"https": config.openai_config["http_proxy"]
|
||||
}
|
||||
|
||||
# 配置openai api_base
|
||||
if "reverse_proxy" in config.openai_config and config.openai_config["reverse_proxy"] is not None:
|
||||
openai.api_base = config.openai_config["reverse_proxy"]
|
||||
openai.base_url = config.openai_config["reverse_proxy"]
|
||||
|
||||
# 主启动流程
|
||||
database = pkg.database.manager.DatabaseManager()
|
||||
|
||||
24
tests/proxy_test/forward_proxy_test.py
Normal file
24
tests/proxy_test/forward_proxy_test.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
|
||||
import openai
|
||||
|
||||
client = openai.Client(
|
||||
api_key=os.environ["OPENAI_API_KEY"],
|
||||
)
|
||||
|
||||
openai.proxies = {
|
||||
'http': 'http://127.0.0.1:7890',
|
||||
'https': 'http://127.0.0.1:7890',
|
||||
}
|
||||
|
||||
resp = client.chat.completions.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello, how are you?",
|
||||
}
|
||||
]
|
||||
)
|
||||
|
||||
print(resp)
|
||||
Reference in New Issue
Block a user