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

XFEstudio/gpt4free

feat(g4f/client/client.py): add system prompt support

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

代码差异

1 个文件 +26 -4
Modified g4f/client/client.py +26 -4
@@ -149,6 +149,7 @@ class Completions:
149 149 self,
150 150 messages: Messages,
151 151 model: str,
152 system: str = None, # Added system parameter
152 153 provider: ProviderType = None,
153 154 stream: bool = False,
154 155 proxy: str = None,
@@ -161,6 +162,12 @@ class Completions:
161 162 ignore_stream: bool = False,
162 163 **kwargs
163 164 ) -> Union[ChatCompletion, Iterator[ChatCompletionChunk]]:
165 # If a system prompt is provided, prepend it to the messages
166 if system:
167 system_message = {"role": "system", "content": system}
168 messages = [system_message] + messages
169
170 # Existing implementation continues...
164 171 model, provider = get_model_and_provider(
165 172 model,
166 173 self.provider if provider is None else provider,
@@ -221,6 +228,7 @@ class Completions:
221 228 self,
222 229 messages: Messages,
223 230 model: str,
231 system: str = None, # Added system parameter
224 232 provider: ProviderType = None,
225 233 stream: bool = False,
226 234 proxy: str = None,
@@ -233,6 +241,12 @@ class Completions:
233 241 ignore_stream: bool = False,
234 242 **kwargs
235 243 ) -> Union[ChatCompletion, AsyncIterator[ChatCompletionChunk]]:
244 # If a system prompt is provided, prepend it to the messages
245 if system:
246 system_message = {"role": "system", "content": system}
247 messages = [system_message] + messages
248
249 # Existing implementation continues...
236 250 model, provider = get_model_and_provider(
237 251 model,
238 252 self.provider if provider is None else provider,
@@ -271,16 +285,18 @@ class Completions:
271 285 **kwargs
272 286 )
273 287
274 # Removed 'await' here since 'async_iter_response' returns an async generator
275 response = async_iter_response(response, stream, response_format, max_tokens, stop)
276 response = async_iter_append_model_and_provider(response)
277
288 # Handle streaming or non-streaming responses
278 289 if stream:
290 response = async_iter_response(response, stream, response_format, max_tokens, stop)
291 response = async_iter_append_model_and_provider(response)
279 292 return response
280 293 else:
294 response = async_iter_response(response, stream, response_format, max_tokens, stop)
295 response = async_iter_append_model_and_provider(response)
281 296 async for result in response:
282 297 return result
283 298
299
284 300 class Chat:
285 301 completions: Completions
286 302
@@ -401,6 +417,12 @@ class Image:
401 417 def __repr__(self):
402 418 return f"Image(url={self.url}, b64_json={'<base64 data>' if self.b64_json else None})"
403 419
420 def to_dict(self):
421 return {
422 "url": self.url,
423 "b64_json": self.b64_json
424 }
425
404 426 class ImagesResponse:
405 427 def __init__(self, data: list[Image]):
406 428 self.data = data