zhaoqingang
2024-11-22 600d2205367bf914dceaf97e6f082383aa54348c
app/service/bisheng.py
@@ -1,3 +1,4 @@
import json
from datetime import datetime
import httpx
@@ -70,9 +71,34 @@
                    "updated_time": int(datetime.strptime(item["update_time"], "%Y-%m-%dT%H:%M:%S").timestamp() * 1000)
                }
                for item in data
                if
                "latest_message" in item and "message" in item["latest_message"] and item["latest_message"]["message"]
                if "latest_message" in item and "message" in item["latest_message"] and item["latest_message"]["message"]
            ]
            def process_name(item):
                message = item.get("latest_message", {}).get("message", "")
                name = message
                try:
                    message_json = json.loads(message)
                    if 'question' in message_json:
                        name = message_json['question']
                    elif 'query' in message_json:
                        name = message_json['query']
                    elif 'report_name' in message_json:
                        name = message_json['report_name']
                except json.JSONDecodeError:
                    pass
                return name
            result = [
                {
                    "id": item["chat_id"],
                    "name": process_name(item),
                    "updated_time": int(datetime.strptime(item["update_time"], "%Y-%m-%dT%H:%M:%S").timestamp() * 1000)
                }
                for item in data
                if "latest_message" in item and "message" in item["latest_message"] and item["latest_message"]["message"]
            ]
            return result
    async def get_session_log(self, token: str, agent_id: str, conversation_id: str):
@@ -130,3 +156,17 @@
            response = await client.get(url, headers=headers)
            data = self._check_response(response)
            return data
    async def change_password_public(self, token: str, username: str, password: str, new_password:str) -> dict:
        url = f"{self.base_url}/api/v1/user/change_password_public"
        headers = {'cookie': f"access_token_cookie={token};"}
        public_key = await self.get_public_key_api()
        password = BishengCrypto(public_key, settings.PRIVATE_KEY).encrypt(password)
        new_password = BishengCrypto(public_key, settings.PRIVATE_KEY).encrypt(new_password)
        json = {"username": username, "password": password, "new_password": new_password}
        async with httpx.AsyncClient() as client:
            response = await client.post(url, headers=headers, json=json)
            data = self._check_response(response)
            return data