宋伯文 4 달 전
부모
커밋
c8c4cfc2bf
4개의 변경된 파일4개의 추가작업 그리고 4개의 파일을 삭제
  1. BIN
      local.db
  2. 1 1
      main.spec
  3. 2 2
      plugins/agent.py
  4. 1 1
      plugins/custom_agent.py

BIN
local.db


+ 1 - 1
main.spec

@@ -5,7 +5,7 @@ a = Analysis(
     ['main.py'],
     pathex=[],
     binaries=[('config.json','config.json')],
-    datas=[('wcferry', 'wcferry'),('local.db', '.')],
+    datas=[('wcferry', 'wcferry')],
     hiddenimports=['_cffi_backend'],
     hookspath=[],
     hooksconfig={},

+ 2 - 2
plugins/agent.py

@@ -25,7 +25,7 @@ class Agent(Plugin):
         cursor = connection.cursor()
         try:
             history_messages = msg_history_get(cursor, wx_wxid, msg.sender, msg.roomid)
-            if dataset_id is not None:
+            if not dataset_id:
                 # 优化问题
                 expand_system_prompt = f"""# 任务:
 请根据上下文信息,优化用户发送的最后一条消息,补齐消息中可能缺失的主语、谓语、宾语、定语、状语、补语句子成分。
@@ -59,6 +59,7 @@ class Agent(Plugin):
             bot_reply = self._client_reply(self.openAiClient, messages)
             new_history_messages = history_messages + [{"role": "user", "content": msg.content}, {"role": "assistant", "content": bot_reply}]
             msg_history_update(cursor, wx_wxid, new_history_messages, msg.sender, msg.roomid)
+            connection.commit()
             return bot_reply
         except Exception as e:
             # 回滚事务
@@ -66,7 +67,6 @@ class Agent(Plugin):
             print(f"发生错误: {e}")
         finally:
             # 确保资源被正确释放
-            connection.commit()
             cursor.close()
             connection.close()
 

+ 1 - 1
plugins/custom_agent.py

@@ -12,7 +12,7 @@ class CustomAgent(Plugin):
         super().__init__()
         self.customAiClient = OpenAI(api_key=self.config.get("custom_agent_key"), base_url=self.config.get("custom_agent_base"))
 
-    def answer(self, msg: WxMsg, wx_wxid: Optional[str] = None):
+    def answer(self, msg: WxMsg, wx_wxid: Optional[str] = None) -> str:
         rsp = ""
         try:
             messages = [