Skip to content

Commit

Permalink
fix: anthropic sdk删除proxies导致无法启动 (#962, #960)
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Dec 23, 2024
1 parent 6606c67 commit 535c4a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 1 addition & 3 deletions pkg/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ async def print_web_access_info(self):
self.logger.warning("WebUI 文件缺失,请根据文档获取:https://docs.langbot.app/webui/intro.html")
return

import socket

host_ip = socket.gethostbyname(socket.gethostname())
host_ip = "127.0.0.1"

public_ip = await ip.get_myip()

Expand Down
15 changes: 12 additions & 3 deletions pkg/provider/modelmgr/requesters/anthropicmsgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import traceback

import anthropic
import httpx

from .. import entities, errors, requester

Expand All @@ -21,13 +22,21 @@ class AnthropicMessages(requester.LLMAPIRequester):
client: anthropic.AsyncAnthropic

async def initialize(self):
self.client = anthropic.AsyncAnthropic(
api_key="",

httpx_client = anthropic._base_client.AsyncHttpxClientWrapper(
base_url=self.ap.provider_cfg.data['requester']['anthropic-messages']['base-url'],
timeout=self.ap.provider_cfg.data['requester']['anthropic-messages']['timeout'],
# cast to a valid type because mypy doesn't understand our type narrowing
timeout=typing.cast(httpx.Timeout, self.ap.provider_cfg.data['requester']['anthropic-messages']['timeout']),
limits=anthropic._constants.DEFAULT_CONNECTION_LIMITS,
follow_redirects=True,
proxies=self.ap.proxy_mgr.get_forward_proxies()
)

self.client = anthropic.AsyncAnthropic(
api_key="",
http_client=httpx_client,
)

async def call(
self,
model: entities.LLMModelInfo,
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

async def get_myip() -> str:
try:
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=10)) as session:
async with session.get("https://ip.useragentinfo.com/myip") as response:
return await response.text()
except Exception as e:
Expand Down

0 comments on commit 535c4a8

Please sign in to comment.