mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-14 14:31:00 +00:00
feat: 正向代理支持
This commit is contained in:
@@ -7,6 +7,7 @@ from typing import AsyncGenerator
|
|||||||
|
|
||||||
import openai
|
import openai
|
||||||
import openai.types.chat.chat_completion as chat_completion
|
import openai.types.chat.chat_completion as chat_completion
|
||||||
|
import httpx
|
||||||
|
|
||||||
from pkg.provider.entities import Message
|
from pkg.provider.entities import Message
|
||||||
|
|
||||||
@@ -24,6 +25,9 @@ class OpenAIChatCompletion(api.LLMAPIRequester):
|
|||||||
api_key="",
|
api_key="",
|
||||||
base_url=self.ap.provider_cfg.data['openai-config']['base_url'],
|
base_url=self.ap.provider_cfg.data['openai-config']['base_url'],
|
||||||
timeout=self.ap.provider_cfg.data['openai-config']['request-timeout'],
|
timeout=self.ap.provider_cfg.data['openai-config']['request-timeout'],
|
||||||
|
http_client=httpx.AsyncClient(
|
||||||
|
proxies=self.ap.proxy_mgr.get_forward_proxies()
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _req(
|
async def _req(
|
||||||
|
|||||||
+5
-5
@@ -18,14 +18,14 @@ class ProxyManager:
|
|||||||
|
|
||||||
async def initialize(self):
|
async def initialize(self):
|
||||||
self.forward_proxies = {
|
self.forward_proxies = {
|
||||||
"http": os.getenv("HTTP_PROXY") or os.getenv("http_proxy"),
|
"http://": os.getenv("HTTP_PROXY") or os.getenv("http_proxy"),
|
||||||
"https": os.getenv("HTTPS_PROXY") or os.getenv("https_proxy"),
|
"https://": os.getenv("HTTPS_PROXY") or os.getenv("https_proxy"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if 'http' in self.ap.system_cfg.data['network-proxies']:
|
if 'http' in self.ap.system_cfg.data['network-proxies']:
|
||||||
self.forward_proxies['http'] = self.ap.system_cfg.data['network-proxies']['http']
|
self.forward_proxies['http://'] = self.ap.system_cfg.data['network-proxies']['http']
|
||||||
if 'https' in self.ap.system_cfg.data['network-proxies']:
|
if 'https' in self.ap.system_cfg.data['network-proxies']:
|
||||||
self.forward_proxies['https'] = self.ap.system_cfg.data['network-proxies']['https']
|
self.forward_proxies['https://'] = self.ap.system_cfg.data['network-proxies']['https']
|
||||||
|
|
||||||
def get_forward_proxies(self) -> dict:
|
def get_forward_proxies(self) -> dict:
|
||||||
return self.forward_proxies
|
return self.forward_proxies.copy()
|
||||||
|
|||||||
Reference in New Issue
Block a user