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

XFEstudio/gpt4free

fix: add random.choice for alias selection and fix stub model_construct

- Introduced `import random` in g4f/Provider/LambdaChat.py and g4f/Provider/hf_space/CohereForAI_C4AI_Command.py - Replaced the direct lookup with `random.choice(alias)` when `alias` is a list in both provider files - Updated debug log messages to include class name (`{cls.__name__}`) instead of hardcoded string - Removed `model_config = {"arbitrary_types_allowed": True}` from g4f/client/stubs.py - Corrected indentation of `@classmethod` decorator in stubs.py to align with method definition - Clarified that `model_construct` in stubs.py calls `super().model_construct` with role="assistant" and filtered arguments

6901c07b
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

3 个文件 +8 -8
Modified g4f/Provider/LambdaChat.py +5 -4
@@ -3,13 +3,14 @@ from __future__ import annotations
3 3 import json
4 4 import re
5 5 import uuid
6 import random
6 7 from aiohttp import ClientSession, FormData
7 8
8 9 from ..typing import AsyncResult, Messages
9 10 from ..requests import raise_for_status
10 11 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
11 from .helper import format_prompt, get_last_user_message
12 from ..providers.response import JsonConversation, TitleGeneration, Reasoning, FinishReason
12 from .helper import get_last_user_message
13 from ..providers.response import TitleGeneration, Reasoning, FinishReason
13 14 from ..errors import ModelNotFoundError
14 15 from .. import debug
15 16
@@ -56,9 +57,9 @@ class LambdaChat(AsyncGeneratorProvider, ProviderModelMixin):
56 57 # If the alias is a list, randomly select one of the options
57 58 if isinstance(alias, list):
58 59 selected_model = random.choice(alias)
59 debug.log(f"PuterJS: Selected model '{selected_model}' from alias '{model}'")
60 debug.log(f"{cls.__name__}: Selected model '{selected_model}' from alias '{model}'")
60 61 return selected_model
61 debug.log(f"PuterJS: Using model '{alias}' for alias '{model}'")
62 debug.log(f"{cls.__name__}: Using model '{alias}' for alias '{model}'")
62 63 return alias
63 64
64 65 raise ModelNotFoundError(f"Model {model} not found")
Modified g4f/Provider/hf_space/CohereForAI_C4AI_Command.py +3 -2
@@ -1,6 +1,7 @@
1 1 from __future__ import annotations
2 2
3 3 import json
4 import random
4 5 from aiohttp import ClientSession, FormData
5 6
6 7 from ...typing import AsyncResult, Messages
@@ -54,9 +55,9 @@ class CohereForAI_C4AI_Command(AsyncGeneratorProvider, ProviderModelMixin):
54 55 # If the alias is a list, randomly select one of the options
55 56 if isinstance(alias, list):
56 57 selected_model = random.choice(alias)
57 debug.log(f"PuterJS: Selected model '{selected_model}' from alias '{model}'")
58 debug.log(f"{cls.__name__}: Selected model '{selected_model}' from alias '{model}'")
58 59 return selected_model
59 debug.log(f"PuterJS: Using model '{alias}' for alias '{model}'")
60 debug.log(f"{cls.__name__}: Using model '{alias}' for alias '{model}'")
60 61 return alias
61 62
62 63 raise ModelNotFoundError(f"Model {model} not found")
Modified g4f/client/stubs.py +0 -2
@@ -136,8 +136,6 @@ class ChatCompletionMessage(BaseModel):
136 136 reasoning_content: Optional[str] = None
137 137 tool_calls: list[ToolCallModel] = None
138 138
139 model_config = {"arbitrary_types_allowed": True}
140
141 139 @classmethod
142 140 def model_construct(cls, content: str, reasoning_content: list[Reasoning] = None, tool_calls: list = None):
143 141 return super().model_construct(role="assistant", content=content, **filter_none(tool_calls=tool_calls, reasoning_content=reasoning_content))