Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions astrbot/core/provider/sources/anthropic_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def _init_api_key(self, provider_config: dict) -> None:
api_key=self.chosen_api_key,
timeout=self.timeout,
base_url=self.base_url,
default_headers=self.custom_headers,
http_client=self._create_http_client(provider_config),
)

Expand All @@ -111,9 +112,7 @@ def _create_http_client(self, provider_config: dict) -> httpx.AsyncClient | None
proxy = provider_config.get("proxy", "")
if proxy:
logger.info(f"[Anthropic] 使用代理: {proxy}")
return httpx.AsyncClient(proxy=proxy, headers=self.custom_headers)
if self.custom_headers:
return httpx.AsyncClient(headers=self.custom_headers)
return httpx.AsyncClient(proxy=proxy)
return None

def _apply_thinking_config(self, payloads: dict) -> None:
Expand Down Expand Up @@ -573,7 +572,7 @@ async def text_chat(

# Anthropic has a different way of handling system prompts
if system_prompt:
payloads["system"] = system_prompt
payloads["system"] = [{"type": "text", "text": system_prompt}] if isinstance(system_prompt, str) else system_prompt

llm_response = None
try:
Expand Down Expand Up @@ -636,7 +635,7 @@ async def text_chat_stream(

# Anthropic has a different way of handling system prompts
if system_prompt:
payloads["system"] = system_prompt
payloads["system"] = [{"type": "text", "text": system_prompt}] if isinstance(system_prompt, str) else system_prompt

async for llm_response in self._query_stream(payloads, func_tool):
yield llm_response
Expand Down