| | |
| | | import httpx |
| | | from typing import Union, Dict, List |
| | | |
| | | from Tools.scripts.objgraph import ignore |
| | | from fastapi import HTTPException |
| | | from starlette import status |
| | | |
| | |
| | | response = await client.post( |
| | | f"{self.base_url}/v1/user/register", |
| | | headers={'Content-Type': 'application/json'}, |
| | | json={"nickname": username, "email": f"{username}@example.com", "password": password} |
| | | json={"nickname": username, "email": f"{username}@example.com", "password": password} |
| | | ) |
| | | if response.status_code != 200: |
| | | raise Exception(f"Ragflow registration failed: {response.text}") |
| | |
| | | ] |
| | | return result |
| | | |
| | | async def get_session_log(self, token: str, conversation_id: str) -> dict: |
| | | url = f"{self.base_url}/v1/conversation/get?conversation_id={conversation_id}" |
| | | headers = {"Authorization": token} |
| | | async with httpx.AsyncClient() as client: |
| | | response = await client.get(url, headers=headers) |
| | | data = self._handle_response(response) |
| | | session_log = { |
| | | "dialog_id": data.get("dialog_id"), |
| | | "id": data.get("id"), |
| | | "message": [ |
| | | { |
| | | "content": message.get("content"), |
| | | "role": message.get("role"), |
| | | } |
| | | for message in data.get("message", []) |
| | | ], |
| | | "name": data.get("name"), |
| | | "reference": data.get("reference"), |
| | | } |
| | | return session_log |
| | | |
| | | async def set_session(self, token: str, dialog_id: str, message: dict, chat_id: str, is_new: bool) -> list: |
| | | url = f"{self.base_url}/v1/conversation/set?dialog_id={dialog_id}" |
| | | headers = {"Authorization": token} |
| | |
| | | url = f"{self.base_url}/v1/tenant/{tenant_id}/user" |
| | | headers = {"Authorization": token} |
| | | data = {"email": email, "user_id": user_id} |
| | | print(url) |
| | | print(data) |
| | | async with httpx.AsyncClient(timeout=60) as client: |
| | | response = await client.post(url, headers=headers, json=data) |
| | | print(response.text) |
| | | if response.status_code != 200: |
| | | raise Exception(f"Ragflow add user to tenant failed: {response.text}") |