YONG627 commited on
Commit
003281f
·
1 Parent(s): d6fae8c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+
4
+ headers = {
5
+ "Content-Type": "application/json"
6
+ }
7
+
8
+ data = {'model': 'gpt-3.5-turbo', 'messages': [{'role': 'user', 'content': '你好'}],'stream':True}
9
+
10
+ # 这里以免费通道作为示例,付费通道修改data中的model参数即可使用其它模型
11
+ # 支持的模型请到网站查看
12
+ response = requests.post('https://api.zhtec.xyz/xht/chatWith16k.php', headers=headers, data=json.dumps(data), stream=True)
13
+
14
+ # 支持流式输出!
15
+ for chunk in response.iter_lines():
16
+ if chunk:
17
+ decoded_chunk = chunk.decode('utf-8')
18
+ if decoded_chunk.startswith('data:'):
19
+ # Remove the 'data: ' prefix and parse the JSON object
20
+ try:
21
+ parsed_chunk = json.loads(decoded_chunk[5:])
22
+ print(parsed_chunk['choices'][0]['delta']['content'], end='')
23
+ except:
24
+ pass