import json
|
|
from app.config.config import settings
|
# from Log import logger
|
from app.service.v2.app_driver.chat_base import ChatBase
|
from app.utils.rsa_crypto import RagflowCrypto
|
|
|
class ChatBaseApply(ChatBase):
|
|
async def chat_get(self, url, params, headers):
|
|
res = await self.http_get(url, params, headers)
|
if res.status_code == 200:
|
return res.json()
|
else:
|
return {}
|
|
async def chat_ping(self, url, params, headers):
|
res = await self.http_get(url, params, headers)
|
return res.status_code
|
|
|
async def chat_post(self, url, data, headers):
|
|
res = await self.http_post(url, data, headers)
|
if res.status_code == 200:
|
return res.json()
|
else:
|
return {}
|
|
async def chat_login(self, url, data, headers):
|
|
res = await self.http_post(url, data, headers)
|
if res.status_code == 200:
|
res_json = res.json()
|
authorization = res.headers.get('Authorization')
|
if authorization:
|
res_json["data"]["access_token"] = authorization
|
return res_json
|
else:
|
return {}
|
|
|
@staticmethod
|
async def password_encrypt(password):
|
password = RagflowCrypto(settings.PUBLIC_KEY, settings.PRIVATE_KEY).encrypt(password)
|
return password
|
|
|
|
|
if __name__ == "__main__":
|
async def aa():
|
chat_id = "bcb56e4b-8f21-41f1-b22a-80335fe58345"
|
token = "app-9sbGzhtFuGIducdepzQgX06v"
|
base_url = "http://192.168.20.116"
|
url = f"{base_url}/v1/parameters"
|
chat = ChatBaseApply()
|
data = {
|
"question": "电网技术总结300字",
|
"stream": True,
|
"session_id": "9969c152cce411ef8a140242ac1b0002"
|
}
|
params = {
|
"user": "1"
|
}
|
headers = {
|
'Content-Type': 'application/json',
|
'Authorization': f"Bearer {token}"
|
}
|
ans = await chat.chat_parameters(url, params, headers)
|
print(ans)
|
|
|
import asyncio
|
|
asyncio.run(aa())
|