# coding=utf-8
import pyperclip
import requests, json, sys
token = "xxxxxxxxxxxxxxx"
third_party_url = "http://localhost:8000/v1/chat/completions"
headers = {
"Authorization": f"Bearer {token }"
}
def get_translation(content_text):
prompt_text = {
"model": "glm4",
"messages": [
{
"role": "user",
"content": "你叫什么?"
}
],
"stream": False
}
response = requests.post(third_party_url, headers=headers, json=prompt_text)
if response.status_code == 200:
response_data = json.loads(response.text)
print(response_data)
else:
print(f"请求失败\n{response.text}")
clipboard_string = pyperclip.paste()
if isinstance(clipboard_string, str):
sys.stdout.reconfigure(encoding='utf-8')
get_translation(clipboard_string)
C:\ProgramData\anaconda3\envs\python311\python.exe C:\Users\Administrator\Personal_scripts\pythonProject\temp.py
{'code': -2001, 'message': '[请求glm失败]: bad request', 'data': None}
进程已结束,退出代码为 0