|
@@ -1,6 +1,7 @@
|
|
|
#! /usr/bin/env python
|
|
|
# -*- coding: utf-8 -*-
|
|
|
# vim:fenc=utf-8
|
|
|
+import json
|
|
|
import time
|
|
|
import logging
|
|
|
import werkzeug.exceptions
|
|
@@ -11,11 +12,12 @@ from pqai_agent import configs
|
|
|
|
|
|
from pqai_agent import logging_service, chat_service, prompt_templates
|
|
|
from pqai_agent.agents.message_reply_agent import MessageReplyAgent
|
|
|
+from pqai_agent.configs import apollo_config
|
|
|
from pqai_agent.history_dialogue_service import HistoryDialogueService
|
|
|
from pqai_agent.user_manager import MySQLUserManager, MySQLUserRelationManager
|
|
|
from pqai_agent.utils.prompt_utils import format_agent_profile, format_user_profile
|
|
|
from pqai_agent_server.const import AgentApiConst
|
|
|
-from pqai_agent_server.models import MySQLSessionManager
|
|
|
+from pqai_agent_server.models import MySQLSessionManager, MySQLStaffManager
|
|
|
from pqai_agent_server.utils import wrap_response, quit_human_intervention_status
|
|
|
from pqai_agent_server.utils import (
|
|
|
run_extractor_prompt,
|
|
@@ -36,13 +38,41 @@ def list_staffs():
|
|
|
@app.route('/api/getStaffProfile', methods=['GET'])
|
|
|
def get_staff_profile():
|
|
|
staff_id = request.args['staff_id']
|
|
|
- profile = app.user_manager.get_staff_profile(staff_id)
|
|
|
+ if not staff_id:
|
|
|
+ return wrap_response(400, msg='staff_id is required')
|
|
|
+ profile = app.staff_manager.get_staff_profile(staff_id)
|
|
|
if not profile:
|
|
|
return wrap_response(404, msg='staff not found')
|
|
|
else:
|
|
|
return wrap_response(200, data=profile)
|
|
|
|
|
|
|
|
|
+@app.route('/api/saveStaffProfile', methods=['POST'])
|
|
|
+def save_staff_profile():
|
|
|
+ staff_id = request.json.get('staff_id')
|
|
|
+ profile = request.json.get('profile')
|
|
|
+ if not staff_id:
|
|
|
+ return wrap_response(400, msg='staff id is required')
|
|
|
+
|
|
|
+ if not profile:
|
|
|
+ return wrap_response(400, msg='profile is required')
|
|
|
+ else:
|
|
|
+ try:
|
|
|
+ profile_json = json.loads(profile)
|
|
|
+ affected_rows = app.staff_manager.save_staff_profile(staff_id, profile_json)
|
|
|
+ if not affected_rows:
|
|
|
+ return wrap_response(500, msg='save staff profile failed')
|
|
|
+ else:
|
|
|
+ return wrap_response(200, msg='save staff profile success')
|
|
|
+ except json.decoder.JSONDecodeError:
|
|
|
+ return wrap_response(400, msg='profile is not a valid json')
|
|
|
+
|
|
|
+
|
|
|
+@app.route('/api/getProfileFields', methods=['GET'])
|
|
|
+def get_profile_fields():
|
|
|
+ return wrap_response(200, data=app.staff_manager.list_profile_fields())
|
|
|
+
|
|
|
+
|
|
|
@app.route('/api/getUserProfile', methods=['GET'])
|
|
|
def get_user_profile():
|
|
|
user_id = request.args['user_id']
|
|
@@ -346,6 +376,16 @@ if __name__ == '__main__':
|
|
|
)
|
|
|
app.session_manager = session_manager
|
|
|
|
|
|
+ # init staff manager
|
|
|
+ staff_manager = MySQLStaffManager(
|
|
|
+ db_config=user_db_config['mysql'],
|
|
|
+ staff_table=staff_db_config['table'],
|
|
|
+ user_table=user_db_config['table'],
|
|
|
+ config=apollo_config
|
|
|
+ )
|
|
|
+ app.staff_manager = staff_manager
|
|
|
+
|
|
|
+ # init wecom manager
|
|
|
wecom_db_config = config['storage']['user_relation']
|
|
|
user_relation_manager = MySQLUserRelationManager(
|
|
|
user_db_config['mysql'], wecom_db_config['mysql'],
|