From fbaa40f8626c31a4828eca9b475b2bfb47dea306 Mon Sep 17 00:00:00 2001 From: yym68686 Date: Thu, 12 Dec 2024 22:58:58 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Bug:=20Fix=20the=20bug=20in=20th?= =?UTF-8?q?e=20Gemini=20API=20where=20an=20empty=20message=20was=20not=20a?= =?UTF-8?q?utomatically=20added=20when=20no=20role=20message=20was=20passe?= =?UTF-8?q?d=20in.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 2 ++ request.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 4c6c192..9687885 100644 --- a/main.py +++ b/main.py @@ -490,6 +490,8 @@ async def dispatch(self, request: Request, call_next): if parsed_body: try: request_model = UnifiedRequest.model_validate(parsed_body).data + if is_debug: + logger.info("request_model: %s", json.dumps(request_model.model_dump(exclude_unset=True), indent=2, ensure_ascii=False)) model = request_model.model current_info["model"] = model diff --git a/request.py b/request.py index 0d07a8a..beadb1c 100644 --- a/request.py +++ b/request.py @@ -212,7 +212,7 @@ async def get_gemini_payload(request, engine, provider): payload = { - "contents": messages, + "contents": messages or [{"role": "user", "parts": [{"text": "No messages"}]}], "safetySettings": [ { "category": "HARM_CATEGORY_HARASSMENT",