XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

moving to finished

bca970eb
9fo <71867245+9fo@users.noreply.github.com>
提交于

代码差异

2 个文件 +0 -44
Deleted unfinished/openaihosted/README.md +0 -3
@@ -1,3 +0,0 @@
1 writegpt.ai
2 to do:
3 - code ref
Deleted unfinished/openaihosted/__init__.py +0 -41
@@ -1,41 +0,0 @@
1 import json
2 import re
3
4 import requests
5
6 headers = {
7 'authority': 'openai.a2hosted.com',
8 'accept': 'text/event-stream',
9 'accept-language': 'en-US,en;q=0.9,id;q=0.8,ja;q=0.7',
10 'cache-control': 'no-cache',
11 'sec-fetch-dest': 'empty',
12 'sec-fetch-mode': 'cors',
13 'sec-fetch-site': 'cross-site',
14 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.0.0',
15 }
16
17
18 def create_query_param(conversation):
19 encoded_conversation = json.dumps(conversation)
20 return encoded_conversation.replace(" ", "%20").replace('"', '%22').replace("'", "%27")
21
22
23 user_input = input("Enter your message: ")
24
25 data = [
26 {"role": "system", "content": "You are a helpful assistant."},
27 {"role": "user", "content": "hi"},
28 {"role": "assistant", "content": "Hello! How can I assist you today?"},
29 {"role": "user", "content": user_input},
30 ]
31
32 query_param = create_query_param(data)
33 url = f'https://openai.a2hosted.com/chat?q={query_param}'
34
35 response = requests.get(url, headers=headers, stream=True)
36
37 for message in response.iter_content(chunk_size=1024):
38 message = message.decode('utf-8')
39 msg_match, num_match = re.search(r'"msg":"(.*?)"', message), re.search(r'\[DONE\] (\d+)', message)
40 if msg_match: print(msg_match.group(1))
41 if num_match: print(num_match.group(1))