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

XFEstudio/gpt4free

feat(g4f/client/client.py): integrate ModelUtils for model retrieval

b11cf3ab
kqlio67 <kqlio67@users.noreply.github.com>
提交于

代码差异

1 个文件 +9 -8
Modified g4f/client/client.py +9 -8
@@ -184,8 +184,12 @@ class Completions:
184 184 ignore_stream: bool = False,
185 185 **kwargs
186 186 ) -> Union[ChatCompletion, Iterator[ChatCompletionChunk]]:
187 model, provider = get_model_and_provider(
188 model,
187 # We use ModelUtils to obtain the model object.
188 model_instance = ModelUtils.get_model(model)
189
190 # We receive the model and the provider.
191 model_name, provider = get_model_and_provider(
192 model_instance.name, # We use the model name from the object.
189 193 self.provider if provider is None else provider,
190 194 stream,
191 195 ignored,
@@ -196,9 +200,8 @@ class Completions:
196 200 stop = [stop] if isinstance(stop, str) else stop
197 201
198 202 if asyncio.iscoroutinefunction(provider.create_completion):
199 # Run the asynchronous function in an event loop
200 203 response = asyncio.run(provider.create_completion(
201 model,
204 model_name, # We use a model based on the object.
202 205 messages,
203 206 stream=stream,
204 207 **filter_none(
@@ -211,7 +214,7 @@ class Completions:
211 214 ))
212 215 else:
213 216 response = provider.create_completion(
214 model,
217 model_name, # We use a model from the object.
215 218 messages,
216 219 stream=stream,
217 220 **filter_none(
@@ -225,21 +228,19 @@ class Completions:
225 228
226 229 if stream:
227 230 if hasattr(response, '__aiter__'):
228 # It's an async generator, wrap it into a sync iterator
229 231 response = to_sync_iter(response)
230 232
231 # Now 'response' is an iterator
232 233 response = iter_response(response, stream, response_format, max_tokens, stop)
233 234 response = iter_append_model_and_provider(response)
234 235 return response
235 236 else:
236 237 if hasattr(response, '__aiter__'):
237 # If response is an async generator, collect it into a list
238 238 response = list(to_sync_iter(response))
239 239 response = iter_response(response, stream, response_format, max_tokens, stop)
240 240 response = iter_append_model_and_provider(response)
241 241 return next(response)
242 242
243
243 244 async def async_create(
244 245 self,
245 246 messages: Messages,