返回提交历史
Modified
etc/unittest/test_reasoning_standardization.py
+3
-3
Modified
g4f/client/__init__.py
+2
-2
Modified
g4f/client/stubs.py
+6
-6
XFEstudio/gpt4free
Rename reasoning_content parameter to reasoning for consistent naming
Co-authored-by: hlohaus <983577+hlohaus@users.noreply.github.com>
71f540ad
代码差异
3 个文件
+11
-11
@@ -31,9 +31,9 @@ class TestReasoningFieldStandardization(unittest.TestCase):
31
31
delta = ChatCompletionDelta.model_construct(reasoning)
32
32
33
33
# Check the delta structure
34
self.assertEqual(delta.role, "reasoning")
35
self.assertIsInstance(delta.content, Reasoning)
36
self.assertEqual(delta.reasoning_content, "I need to think about this...")
34
self.assertEqual(delta.role, "assistant")
35
self.assertIsNone(delta.content)
36
self.assertEqual(delta.reasoning, "I need to think about this...")
37
37
38
38
def test_current_api_format_consistency(self):
39
39
"""Test what the API should output for reasoning"""
@@ -145,7 +145,7 @@ def iter_response(
145
145
content, finish_reason, completion_id, int(time.time()), usage=usage,
146
146
**filter_none(tool_calls=[ToolCallModel.model_construct(**tool_call) for tool_call in tool_calls]) if tool_calls is not None else {},
147
147
conversation=None if conversation is None else conversation.get_dict(),
148
reasoning_content=reasoning_content if reasoning_content else None
148
reasoning=reasoning_content if reasoning_content else None
149
149
)
150
150
if provider is not None:
151
151
chat_completion.provider = provider.name
@@ -250,7 +250,7 @@ async def async_iter_response(
250
250
tool_calls=[ToolCallModel.model_construct(**tool_call) for tool_call in tool_calls]
251
251
) if tool_calls is not None else {},
252
252
conversation=conversation,
253
reasoning_content=reasoning_content if reasoning_content else None
253
reasoning=reasoning_content if reasoning_content else None
254
254
)
255
255
if provider is not None:
256
256
chat_completion.provider = provider.name
@@ -150,7 +150,7 @@ class ChatCompletionMessage(BaseModel):
150
150
return super().model_construct(role="assistant", content=[ResponseMessageContent.model_construct(content)])
151
151
152
152
@classmethod
153
def model_construct(cls, content: str, reasoning_content: list[Reasoning] = None, tool_calls: list = None):
153
def model_construct(cls, content: str, reasoning: list[Reasoning] = None, tool_calls: list = None):
154
154
if isinstance(content, AudioResponse) and content.data.startswith("data:"):
155
155
return super().model_construct(
156
156
role="assistant",
@@ -160,9 +160,9 @@ class ChatCompletionMessage(BaseModel):
160
160
),
161
161
content=content
162
162
)
163
if reasoning_content is not None and isinstance(reasoning_content, list):
164
reasoning_content = "".join([str(content) for content in reasoning_content])
165
return super().model_construct(role="assistant", content=content, **filter_none(tool_calls=tool_calls, reasoning=reasoning_content))
163
if reasoning is not None and isinstance(reasoning, list):
164
reasoning = "".join([str(content) for content in reasoning])
165
return super().model_construct(role="assistant", content=content, **filter_none(tool_calls=tool_calls, reasoning=reasoning))
166
166
167
167
@field_serializer('content')
168
168
def serialize_content(self, content: str):
@@ -211,7 +211,7 @@ class ChatCompletion(BaseModel):
211
211
tool_calls: list[ToolCallModel] = None,
212
212
usage: UsageModel = None,
213
213
conversation: dict = None,
214
reasoning_content: list[Reasoning] = None
214
reasoning: list[Reasoning] = None
215
215
):
216
216
return super().model_construct(
217
217
id=f"chatcmpl-{completion_id}" if completion_id else None,
@@ -220,7 +220,7 @@ class ChatCompletion(BaseModel):
220
220
model=None,
221
221
provider=None,
222
222
choices=[ChatCompletionChoice.model_construct(
223
ChatCompletionMessage.model_construct(content, reasoning_content, tool_calls),
223
ChatCompletionMessage.model_construct(content, reasoning, tool_calls),
224
224
finish_reason,
225
225
)],
226
226
**filter_none(usage=usage, conversation=conversation)