Explorar el Código

develop-0520-reformat-code

luojunhui hace 1 mes
padre
commit
b59c55d403
Se han modificado 2 ficheros con 22 adiciones y 5 borrados
  1. 14 5
      pqai_agent_server/api_server.py
  2. 8 0
      pqai_agent_server/utils.py

+ 14 - 5
pqai_agent_server/api_server.py

@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 # -*- coding: utf-8 -*-
 # vim:fenc=utf-8
-import time
+
 import logging
 import werkzeug.exceptions
 from flask import Flask, request, jsonify
@@ -12,7 +12,7 @@ from pqai_agent import configs
 from pqai_agent import logging_service, chat_service, prompt_templates
 from pqai_agent.history_dialogue_service import HistoryDialogueService
 from pqai_agent.user_manager import MySQLUserManager, MySQLUserRelationManager
-from pqai_agent_server.utils import wrap_response
+from pqai_agent_server.utils import wrap_response, quit_human_intervention_status
 from pqai_agent_server.utils import (
     run_extractor_prompt,
     run_chat_prompt,
@@ -232,13 +232,22 @@ def get_conversation_list():
     return wrap_response(200, data=response)
 
 
-@app.route("/api/quitHumanConversationStatus", methods=["POST"])
-def quit_human_conversation_status():
+@app.route("/api/quitHumanInterventionStatus", methods=["POST"])
+def quit_human_intervention_status():
     """
     退出人工介入状态
     :return:
     """
-    return wrap_response(200, msg="OK")
+    data = request.get_json()
+    user_id = data["user_id"]
+    staff_id = data["staff_id"]
+    # 测试环境: staff_id 强制等于1688854492669990
+    staff_id = 1688854492669990
+    if not user_id or not staff_id:
+        return wrap_response(404, msg="user_id and staff_id are required")
+    response = quit_human_intervention_status(user_id, staff_id)
+
+    return wrap_response(200, data=response)
 
 
 @app.route("/api/sendMessage", methods=["POST"])

+ 8 - 0
pqai_agent_server/utils.py

@@ -1,5 +1,6 @@
 import json
 
+import requests
 from flask import jsonify
 from datetime import datetime
 
@@ -181,3 +182,10 @@ def run_response_type_prompt(req_data):
         {"role": "user", "content": prompt},
     ]
     return run_openai_chat(messages, model_name, temperature=0.2, max_tokens=128)
+
+
+def quit_human_intervention_status(user_id, staff_id):
+    url = f"http://ai-wechat-hook-internal.piaoquantv.com/manage/insertEvent?sender={user_id}&receiver={staff_id}&type=103&content=SYSTEM"
+    response = requests.get(url)
+    return response.json()
+