parent
df08f308fa
commit
c559e5aa14
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,35 @@
|
||||
import json
|
||||
import logging
|
||||
|
||||
import requests
|
||||
|
||||
# 更详细地控制日志输出
|
||||
logger = logging.getLogger('MathRag')
|
||||
logger.setLevel(logging.INFO)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
||||
logger.addHandler(handler)
|
||||
|
||||
|
||||
def getAnswer(query_text):
|
||||
# 根据问题查询知识库
|
||||
url = "http://10.10.21.20:8100/api/chat"
|
||||
headers = {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
data = {
|
||||
"query": query_text,
|
||||
"topic":"ChuZhongShuXue"
|
||||
}
|
||||
try:
|
||||
response = requests.post(url, headers=headers, data=json.dumps(data))
|
||||
response.raise_for_status()
|
||||
return response.json().get("data").get("reply")
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.error(f"请求发生异常: {str(e)}")
|
||||
return None
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
query_text = '什么是数学的性质命题'
|
||||
print(getAnswer(query_text))
|
Loading…
Reference in new issue