XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

Update Claude provider to use new base URL and enhance cookie handling

97f99539
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

2 个文件 +10 -2
Modified g4f/Provider/needs_auth/Claude.py +9 -1
@@ -4,16 +4,18 @@ import os
4 4
5 5 from ...typing import Messages, AsyncResult
6 6 from ...errors import MissingAuthError
7 from ...cookies import get_cookies
7 8 from ..template import OpenaiTemplate
8 9
9 10 class Claude(OpenaiTemplate):
10 11 label = "Claude 💥"
11 12 url = "https://claude.ai"
12 base_url = "https://g4f.space/api/claude"
13 base_url = "https://claude.gpt4free.workers.dev"
13 14 working = True
14 15 active_by_default = False
15 16 login_url = "https://discord.gg/qXA4Wf4Fsm"
16 17 organization_id = None
18 cookie_domain = "claude.ai"
17 19
18 20 @classmethod
19 21 async def create_async_generator(
@@ -21,14 +23,20 @@ class Claude(OpenaiTemplate):
21 23 model: str,
22 24 messages: Messages,
23 25 api_key: str = None,
26 cookies: list = None,
24 27 base_url: str = base_url,
25 28 **kwargs
26 29 ) -> AsyncResult:
27 30 api_key = os.environ.get("CLAUDE_COOKIE", api_key)
31 cookies = cookies or get_cookies(cls.cookie_domain)
32 if not api_key:
33 api_key = "; ".join([f"{key}={value}" for key, value in cookies.items()])
28 34 if not api_key:
29 35 raise MissingAuthError("Claude cookie not found. Please set the 'CLAUDE_COOKIE' environment variable.")
30 36 if not cls.organization_id:
31 37 cls.organization_id = os.environ.get("CLAUDE_ORGANIZATION_ID")
38 if not cls.organization_id:
39 cls.organization_id = cookies.get("lastActiveOrg")
32 40 if not cls.organization_id:
33 41 raise MissingAuthError("Claude organization ID not found. Please set the 'CLAUDE_ORGANIZATION_ID' environment variable.")
34 42 async for chunk in super().create_async_generator(
Modified g4f/gui/server/backend_api.py +1 -1
@@ -182,7 +182,7 @@ class Backend_Api(Api):
182 182 response = self.client.chat.completions.create(
183 183 messages=messages,
184 184 model=model,
185 provider=provider_cls,
185 provider=provider_cls(),
186 186 stream=True,
187 187 )
188 188 for chunk in response: