2025-08-12 18:53:06 +08:00
|
|
|
|
import requests
|
2025-10-22 18:24:43 +08:00
|
|
|
|
from Entity.Variables import prologueList, API_KEY
|
2025-09-20 21:57:37 +08:00
|
|
|
|
from Utils.IOSAIStorage import IOSAIStorage
|
2025-09-09 20:45:02 +08:00
|
|
|
|
from Utils.LogManager import LogManager
|
2025-08-12 18:53:06 +08:00
|
|
|
|
|
2025-08-18 19:22:20 +08:00
|
|
|
|
BaseUrl = "https://crawlclient.api.yolozs.com/api/common/"
|
2025-08-12 18:53:06 +08:00
|
|
|
|
|
2025-08-11 22:06:48 +08:00
|
|
|
|
|
|
|
|
|
|
class Requester():
|
2025-08-12 18:53:06 +08:00
|
|
|
|
comment = "comment"
|
|
|
|
|
|
prologue = "prologue"
|
2025-08-14 14:30:36 +08:00
|
|
|
|
|
2025-08-12 18:53:06 +08:00
|
|
|
|
@classmethod
|
2025-08-18 22:20:23 +08:00
|
|
|
|
def requestPrologue(cls, token):
|
2025-09-10 16:54:05 +08:00
|
|
|
|
try:
|
|
|
|
|
|
headers = {
|
|
|
|
|
|
"vvtoken": token,
|
|
|
|
|
|
}
|
|
|
|
|
|
url = BaseUrl + cls.prologue
|
2025-09-16 16:16:50 +08:00
|
|
|
|
result = requests.get(headers=headers, url=url, verify=False)
|
2025-09-10 16:54:05 +08:00
|
|
|
|
json = result.json()
|
|
|
|
|
|
data = json.get("data")
|
|
|
|
|
|
for i in data:
|
|
|
|
|
|
prologueList.append(i)
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
LogManager.method_error(f"获取requestPrologue失败,报错的原因:{e}", "获取requestPrologue异常")
|
2025-08-12 18:53:06 +08:00
|
|
|
|
|
|
|
|
|
|
# 翻译
|
|
|
|
|
|
@classmethod
|
2025-09-08 21:42:09 +08:00
|
|
|
|
def translation(cls, msg, country="英国"):
|
2025-09-09 20:45:02 +08:00
|
|
|
|
try:
|
2025-09-16 16:16:50 +08:00
|
|
|
|
if country == "":
|
|
|
|
|
|
country = "英国"
|
|
|
|
|
|
|
2025-09-12 21:36:47 +08:00
|
|
|
|
param = {
|
2025-09-09 20:45:02 +08:00
|
|
|
|
"msg": msg,
|
|
|
|
|
|
"country": country,
|
|
|
|
|
|
}
|
2025-09-10 16:54:05 +08:00
|
|
|
|
url = "https://ai.yolozs.com/translation"
|
2025-09-16 16:16:50 +08:00
|
|
|
|
result = requests.post(url=url, json=param, verify=False)
|
2025-09-12 21:36:47 +08:00
|
|
|
|
|
2025-09-16 16:16:50 +08:00
|
|
|
|
LogManager.info(f"翻译 请求的参数:{param}", "翻译")
|
|
|
|
|
|
LogManager.info(f"翻译,状态码:{result.status_code},服务器返回的内容:{result.text}", "翻译")
|
2025-09-16 14:03:43 +08:00
|
|
|
|
|
2025-09-12 21:36:47 +08:00
|
|
|
|
if result.status_code != 200:
|
|
|
|
|
|
LogManager.error(f"翻译失败,状态码:{result.status_code},服务器返回的内容:{result.text}")
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
2025-09-09 20:45:02 +08:00
|
|
|
|
json = result.json()
|
|
|
|
|
|
data = json.get("data")
|
|
|
|
|
|
return data
|
|
|
|
|
|
except Exception as e:
|
2025-09-10 16:54:05 +08:00
|
|
|
|
LogManager.method_error(f"翻译失败,报错的原因:{e}", "翻译失败异常")
|
2025-08-11 22:06:48 +08:00
|
|
|
|
|
2025-09-28 20:42:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 翻译
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def translationToChinese(cls, msg):
|
|
|
|
|
|
try:
|
|
|
|
|
|
param = {
|
|
|
|
|
|
"msg": msg,
|
|
|
|
|
|
}
|
|
|
|
|
|
url = "https://ai.yolozs.com/translationToChinese"
|
|
|
|
|
|
result = requests.post(url=url, json=param, verify=False)
|
|
|
|
|
|
|
|
|
|
|
|
LogManager.info(f"翻译 请求的参数:{param}", "翻译")
|
|
|
|
|
|
LogManager.info(f"翻译,状态码:{result.status_code},服务器返回的内容:{result.text}", "翻译")
|
|
|
|
|
|
|
|
|
|
|
|
if result.status_code != 200:
|
|
|
|
|
|
LogManager.error(f"翻译失败,状态码:{result.status_code},服务器返回的内容:{result.text}")
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
json = result.json()
|
|
|
|
|
|
data = json.get("data")
|
|
|
|
|
|
return data
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
LogManager.method_error(f"翻译失败,报错的原因:{e}", "翻译失败异常")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-12 18:53:06 +08:00
|
|
|
|
# ai聊天
|
2025-08-11 22:06:48 +08:00
|
|
|
|
@classmethod
|
2025-08-12 18:53:06 +08:00
|
|
|
|
def chatToAi(cls, param):
|
2025-10-22 18:24:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# aiConfig = JsonUtils.read_json("aiConfig")
|
2025-09-20 21:57:37 +08:00
|
|
|
|
aiConfig = IOSAIStorage.load("aiConfig.json")
|
2025-10-22 18:24:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-11 19:33:21 +08:00
|
|
|
|
agentName = aiConfig.get("agentName")
|
|
|
|
|
|
guildName = aiConfig.get("guildName")
|
|
|
|
|
|
contactTool = aiConfig.get("contactTool", "")
|
|
|
|
|
|
contact = aiConfig.get("contact", "")
|
2025-09-11 20:32:08 +08:00
|
|
|
|
|
2025-10-22 18:24:43 +08:00
|
|
|
|
age = aiConfig.get("age", 20)
|
|
|
|
|
|
sex = aiConfig.get("sex", "女")
|
|
|
|
|
|
height = aiConfig.get("height", 160)
|
|
|
|
|
|
weight = aiConfig.get("weight", 55)
|
|
|
|
|
|
body_features = aiConfig.get("body_features", "")
|
|
|
|
|
|
nationality = aiConfig.get("nationality", "中国")
|
|
|
|
|
|
personality = aiConfig.get("personality", "")
|
|
|
|
|
|
strengths = aiConfig.get("strengths", "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-11 22:39:57 +08:00
|
|
|
|
inputs = {
|
2025-09-16 14:03:43 +08:00
|
|
|
|
"name": agentName,
|
|
|
|
|
|
"Trade_union": guildName,
|
|
|
|
|
|
"contcat_method": contactTool,
|
2025-10-22 18:24:43 +08:00
|
|
|
|
"contcat_info": contact,
|
|
|
|
|
|
"age": age,
|
|
|
|
|
|
"sex": sex,
|
|
|
|
|
|
"height": height,
|
|
|
|
|
|
"weight": weight,
|
|
|
|
|
|
"body_features": body_features,
|
|
|
|
|
|
"nationality": nationality,
|
|
|
|
|
|
"personality": personality,
|
|
|
|
|
|
"strengths": strengths,
|
2025-09-11 22:39:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
param["inputs"] = inputs
|
2025-09-11 20:32:08 +08:00
|
|
|
|
|
2025-09-10 16:54:05 +08:00
|
|
|
|
try:
|
2025-10-22 18:24:43 +08:00
|
|
|
|
|
|
|
|
|
|
# url = "https://ai.yolozs.com/chat"
|
|
|
|
|
|
url = "https://ai.yolozs.com/customchat"
|
|
|
|
|
|
|
|
|
|
|
|
result = requests.post(url=url, json=param, verify=False)
|
2025-09-28 20:42:01 +08:00
|
|
|
|
|
|
|
|
|
|
LogManager.method_info(f"ai聊天的参数:{param}", "ai聊天")
|
2025-10-22 18:24:43 +08:00
|
|
|
|
print(f"ai聊天的参数:{param}")
|
2025-09-28 20:42:01 +08:00
|
|
|
|
|
2025-09-10 16:54:05 +08:00
|
|
|
|
json = result.json()
|
2025-10-22 18:24:43 +08:00
|
|
|
|
data = json.get("answer", "")
|
|
|
|
|
|
session_id = json.get("conversation_id", "")
|
2025-09-28 20:42:01 +08:00
|
|
|
|
LogManager.method_info(f"ai聊天返回的内容:{result.json()}", "ai聊天")
|
2025-09-16 14:03:43 +08:00
|
|
|
|
|
|
|
|
|
|
return data, session_id
|
2025-09-10 16:54:05 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
|
LogManager.method_error(f"ai聊天失败,ai聊天出现异常,报错的原因:{e}", "ai聊天接口异常")
|