From c2f724890e6d44aec48e2a8b4f8b1e98a5736d21 Mon Sep 17 00:00:00 2001 From: monosans Date: Wed, 11 Sep 2024 14:55:48 +0300 Subject: feat(GeminiPro): add support for system prompt --- g4f/Provider/GeminiPro.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/g4f/Provider/GeminiPro.py b/g4f/Provider/GeminiPro.py index b225c26c..06bf69ee 100644 --- a/g4f/Provider/GeminiPro.py +++ b/g4f/Provider/GeminiPro.py @@ -54,6 +54,7 @@ class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin): "parts": [{"text": message["content"]}] } for message in messages + if message["role"] != "system" ] if image is not None: image = to_bytes(image) @@ -73,6 +74,13 @@ class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin): "topK": kwargs.get("top_k"), } } + system_prompt = "\n".join( + message["content"] + for message in messages + if message["role"] == "system" + ) + if system_prompt: + data["system_instruction"] = {"parts": {"text": system_prompt}} async with session.post(url, params=params, json=data) as response: if not response.ok: data = await response.json() -- cgit v1.2.3