From 2782c8cebee898c45b978da01468212ea0c59ac5 Mon Sep 17 00:00:00 2001 From: SkyFutu <119418823+SkyFutu@users.noreply.github.com> Date: Tue, 15 Apr 2025 22:00:02 +0800 Subject: [PATCH] Fix/windows compatibility (#1303) * Update anthropicmsgs.py * Update anthropicmsgs.py * Update anthropicmsgs.py * Update anthropicmsgs.py * Update anthropicmsgs.py --- pkg/provider/modelmgr/requesters/anthropicmsgs.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/provider/modelmgr/requesters/anthropicmsgs.py b/pkg/provider/modelmgr/requesters/anthropicmsgs.py index 6bbe4bf1..b6052633 100644 --- a/pkg/provider/modelmgr/requesters/anthropicmsgs.py +++ b/pkg/provider/modelmgr/requesters/anthropicmsgs.py @@ -4,6 +4,8 @@ import typing import json import traceback import base64 +import platform +import socket import anthropic import httpx @@ -23,6 +25,12 @@ class AnthropicMessages(requester.LLMAPIRequester): client: anthropic.AsyncAnthropic async def initialize(self): + # 兼容 Windows 缺失 TCP_KEEPINTVL 和 TCP_KEEPCNT 的问题 + if platform.system() == "Windows": + if not hasattr(socket, "TCP_KEEPINTVL"): + socket.TCP_KEEPINTVL = 0 + if not hasattr(socket, "TCP_KEEPCNT"): + socket.TCP_KEEPCNT = 0 httpx_client = anthropic._base_client.AsyncHttpxClientWrapper( base_url=self.ap.provider_cfg.data['requester']['anthropic-messages']['base-url'].replace(' ', ''),