AIl / app.py
YONG627's picture
Create app.py
003281f
raw
history blame contribute delete
876 Bytes
import requests
import json
headers = {
"Content-Type": "application/json"
}
data = {'model': 'gpt-3.5-turbo', 'messages': [{'role': 'user', 'content': '你好'}],'stream':True}
# 这里以免费通道作为示例,付费通道修改data中的model参数即可使用其它模型
# 支持的模型请到网站查看
response = requests.post('https://api.zhtec.xyz/xht/chatWith16k.php', headers=headers, data=json.dumps(data), stream=True)
# 支持流式输出!
for chunk in response.iter_lines():
if chunk:
decoded_chunk = chunk.decode('utf-8')
if decoded_chunk.startswith('data:'):
# Remove the 'data: ' prefix and parse the JSON object
try:
parsed_chunk = json.loads(decoded_chunk[5:])
print(parsed_chunk['choices'][0]['delta']['content'], end='')
except:
pass