Commit 0076a96

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-06-02 08:33:30
fix(gemini): clean source marks before sending request
1 parent bb6dd18
Changed files (2)
src
history
llm
src/history/sync.py
@@ -26,7 +26,6 @@ async def save_history_to_d1(client: Client, message: Message) -> None:
     if not HISTORY.D1_ENABLE:
         return
     info = parse_msg(message, silent=True)
-    await create_d1_table(info["cid"], DB_COLUMNS, HISTORY.D1_DATABASE, silent=True)
     cid = str(info["cid"]).removeprefix("-100")
     chat_title = info["ctitle"] or info["full_name"]
     if info["ctype"] in ["BOT", "PRIVATE"]:  # for private chats, we use peer side name as chat_title
src/llm/gemini.py
@@ -254,8 +254,6 @@ async def gemini_nonstream(
     """
     results = {}
     try:
-        if clean_marks:
-            clean_gemini_sourcemarks(params["contents"])
         api_keys = [x.strip() for x in GEMINI.API_KEY.split(",") if x.strip()]
         if kwargs.get("gemini_api_keys"):
             api_keys = [x.strip() for x in kwargs["gemini_api_keys"].split(",") if x.strip()]
@@ -268,6 +266,8 @@ async def gemini_nonstream(
         # Construct the request params
         if "contents" not in params and "conversations" in params:  # convert conversations to contents
             params["contents"] = await get_conversation_contexts(client, params.pop("conversations"), ctx_format="gemini")
+        if clean_marks:
+            clean_gemini_sourcemarks(params["contents"])
         response = await app.aio.models.generate_content(**params)
         prefix = f"🤖**{model_name}**:{BOT_TIPS}\n"
         res = parse_response(response.model_dump(), append_grounding=append_grounding)