返回提交历史
Modified
unfinished/easyai/main.py
+15
-9
XFEstudio/gpt4free
http://easy-ai.ink/
73618a91
代码差异
1 个文件
+15
-9
@@ -1,4 +1,8 @@
1
import requests
1
from requests import get
2
from os import urandom
3
from json import loads
4
5
sessionId = urandom(10).hex()
2
6
3
7
headers = {
4
8
'Accept': 'text/event-stream',
@@ -12,15 +16,17 @@ headers = {
12
16
}
13
17
14
18
while True:
19
prompt = input('you: ')
20
15
21
params = {
16
'message': 'what is my name',
17
'sessionId': '2eacb8ad826056587598',
22
'message': prompt,
23
'sessionId': sessionId
18
24
}
19
25
20
for chunk in requests.get('http://easy-ai.ink/easyapi/v1/chat/completions', params=params,
21
headers=headers, verify=False, stream=True).iter_lines():
22
23
if b'data:' in chunk:
24
print(chunk)
26
for chunk in get('http://easy-ai.ink/easyapi/v1/chat/completions', params = params,
27
headers = headers, verify = False, stream = True).iter_lines():
25
28
26
print(chunk)
29
if b'content' in chunk:
30
data = loads(chunk.decode('utf-8').split('data:')[1])
31
print(data['content'], end='')
32