feature:新增群百科游戏,用于促进群活跃。加入了新的指令 可用:/start, /tasks, /list, /answer [任务ID] [答案], /addgroup, /rank

This commit is contained in:
liuwei
2025-02-21 16:32:51 +08:00
parent 84f8a88ba4
commit 08e71722e8
5 changed files with 404 additions and 5 deletions

View File

@@ -0,0 +1,67 @@
import requests
import json
# 解析JSON
def extract_content(data_string):
try:
data = json.loads(data_string)
# 提取content字段
content = data["choices"][0]["message"].get("content", "")
return content
except json.JSONDecodeError:
print("Invalid JSON")
return None
def message_task_json(prompt, content):
# 设置Authorization和URL
authorization = "46a5674a-e978-491b-a810-5d54605f2c36" # 请替换为真实的Authorization token
url = 'http://127.0.0.1:8080/v1/chat/completions'
data = {
# "stream": True,
"model": "windsurf/gpt4o",
"messages": [
{
"role": "system",
"content": f"{prompt}"
},
{
"role": "user",
"content": f"{content}"
}
]
}
# 设置请求头
headers = {
"Content-Type": "application/json; charset=utf-8",
"Authorization": authorization
}
# 发送POST请求
response = requests.post(url, headers=headers, data=json.dumps(data), )
response.encoding = 'utf-8'
# 输出响应内容
print(response.status_code)
print(response.text)
return extract_content(response.text)
def game_question_json(question):
prompt = "你是一个益智百科问答大师可以随时提出百科类的问题问题需要有一定的难度回答完毕之后用户能有所收获并且对问题进行打分同时根据问题难度告知答对之后给多少分1-10请只返回JSON格式的内容格式要求如下{\"question\": \"哪个国家最早将玫瑰与爱情联系起来?\", \"score\":\"1\", \"answer\": \"波斯\",\"description\":\"描述问题答案的原因\"}"
return message_task_json(prompt, question)
def game_answer_json(answar):
prompt = "你是一个益智百科问答大师,可以根据用户回答的答案进行判断,并且对问题(question)答案(answer)进行打分,打分时请参考最高分要求(top_score)告知用户能获得多少分请在description中描述打分理由请只返回JSON格式的内容格式要求如下{\"question\": \"哪个国家最早将玫瑰与爱情联系起来?\", \"score\":\"1\", \"answer\": \"波斯\",\"description\":\"描述问题答案的原因\"}"
return message_task_json(prompt, answar)
if __name__ == '__main__':
print(game_question_json('请出题!'))
print(game_answer_json('question:哪个国家的节日与裸体狂欢有关?,answer:古罗马,top_score:3'))