From e38e073fe2f5c5d731b1e9bb18c044ee126f9a5e Mon Sep 17 00:00:00 2001 From: makexine <49511175+makexine@users.noreply.github.com> Date: Wed, 25 Oct 2023 17:13:00 +0800 Subject: [PATCH] Add files via upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 多轮对话调用大模型 --- llm_clients.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 llm_clients.py diff --git a/llm_clients.py b/llm_clients.py new file mode 100644 index 0000000..34c3015 --- /dev/null +++ b/llm_clients.py @@ -0,0 +1,29 @@ +import requests +import urllib3 + +######################################## +# 该文件实现了与大模型的简单通信 +######################################## + +# 忽略https的安全性警告 +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + +url = "https://45.125.46.134:25344/v1/chat/completions" +headers = {"Content-Type": "application/json"} + +#在这里输入你的问题 +k=input() +data_memory=[] +n=1 +while k!='end': + question_now=k + user_dict={"role": "user","content":question_now} + data_memory.append(user_dict) + #print(data_memory) + response = requests.post(url, headers=headers, json={"messages":data_memory, "repetition_penalty": 1.0}, verify=False) + answer=response.json()['choices'][n]['message']['content'] + print(answer) + assistant_dict={"role": "assistant","content":answer} + data_memory.append(assistant_dict) + n=n+2 + k=input() \ No newline at end of file