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

XFEstudio/gpt4free

Update backend_url in OpenaiChat

58d19785
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

2 个文件 +28 -5
Modified g4f/Provider/needs_auth/OpenaiChat.py +26 -4
@@ -30,7 +30,7 @@ from ...tools.media import merge_media
30 30 from ..helper import format_cookies, format_media_prompt, to_string
31 31 from ..openai.models import default_model, default_image_model, models, image_models, text_models, model_aliases
32 32 from ..openai.har_file import get_request_config
33 from ..openai.har_file import RequestConfig, arkReq, arkose_url, start_url, conversation_url, backend_url, backend_anon_url
33 from ..openai.har_file import RequestConfig, arkReq, arkose_url, start_url, conversation_url, backend_url, prepare_url, backend_anon_url
34 34 from ..openai.proofofwork import generate_proof_token
35 35 from ..openai.new import get_requirements_token, get_config
36 36 from ... import debug
@@ -373,6 +373,27 @@ class OpenaiChat(AsyncAuthedProvider, ProviderModelMixin):
373 373 sources = OpenAISources([])
374 374 references = ContentReferences()
375 375 while conversation.finish_reason is None:
376 conduit_token = None
377 if cls._api_key is not None:
378 data = {
379 "action": "next",
380 "fork_from_shared_post":False,
381 "parent_message_id": conversation.message_id,
382 "model": model,
383 "timezone_offset_min":-120,
384 "timezone":"Europe/Berlin",
385 "conversation_mode":{"kind":"primary_assistant"},
386 "system_hints":[],
387 "supports_buffering":True,
388 "supported_encodings":["v1"]
389 }
390 async with session.post(
391 prepare_url,
392 json=data,
393 headers=cls._headers
394 ) as response:
395 await raise_for_status(response)
396 conduit_token = (await response.json())["conduit_token"]
376 397 async with session.post(
377 398 f"{cls.url}/backend-anon/sentinel/chat-requirements"
378 399 if cls._api_key is None else
@@ -415,7 +436,7 @@ class OpenaiChat(AsyncAuthedProvider, ProviderModelMixin):
415 436 "action": "next",
416 437 "parent_message_id": conversation.message_id,
417 438 "model": model,
418 "timezone_offset_min":-60,
439 "timezone_offset_min":-120,
419 440 "timezone":"Europe/Berlin",
420 441 "conversation_mode":{"kind":"primary_assistant"},
421 442 "enable_message_followups":True,
@@ -446,6 +467,7 @@ class OpenaiChat(AsyncAuthedProvider, ProviderModelMixin):
446 467 "accept": "text/event-stream",
447 468 "content-type": "application/json",
448 469 "openai-sentinel-chat-requirements-token": chat_token,
470 **({} if conduit_token is None else {"x-conduit-token": conduit_token})
449 471 }
450 472 #if cls.request_config.arkose_token:
451 473 # headers["openai-sentinel-arkose-token"] = cls.request_config.arkose_token
@@ -454,9 +476,9 @@ class OpenaiChat(AsyncAuthedProvider, ProviderModelMixin):
454 476 if need_turnstile and getattr(auth_result, "turnstile_token", None) is not None:
455 477 headers['openai-sentinel-turnstile-token'] = auth_result.turnstile_token
456 478 async with session.post(
457 f"{cls.url}/backend-anon/conversation"
479 backend_anon_url
458 480 if cls._api_key is None else
459 f"{cls.url}/backend-api/conversation",
481 backend_url,
460 482 json=data,
461 483 headers=headers
462 484 ) as response:
Modified g4f/Provider/openai/har_file.py +2 -1
@@ -17,7 +17,8 @@ from ...errors import NoValidHarFileError
17 17 from ... import debug
18 18
19 19 arkose_url = "https://tcr9i.chat.openai.com/fc/gt2/public_key/35536E1E-65B4-4D96-9D97-6ADB7EFF8147"
20 backend_url = "https://chatgpt.com/backend-api/conversation"
20 backend_url = "https://chatgpt.com/backend-api/f/conversation"
21 prepare_url = "https://chatgpt.com/backend-api/f/conversation/prepare"
21 22 backend_anon_url = "https://chatgpt.com/backend-anon/conversation"
22 23 start_url = "https://chatgpt.com/"
23 24 conversation_url = "https://chatgpt.com/c/"