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

XFEstudio/gpt4free

added a site and some refratoring

e02094de
t.me/xtekky <98614666+xtekky@users.noreply.github.com>
提交于

代码差异

8 个文件 +88 -42
Modified gpt4free/__init__.py +9 -0
@@ -5,6 +5,7 @@ from gpt4free import forefront
5 5 from gpt4free import quora
6 6 from gpt4free import theb
7 7 from gpt4free import you
8 from gpt4free import usesless
8 9
9 10
10 11 class Provider(Enum):
@@ -15,6 +16,7 @@ class Provider(Enum):
15 16 ForeFront = 'fore_front'
16 17 Theb = 'theb'
17 18 CoCalc = 'cocalc'
19 UseLess = 'useless'
18 20
19 21
20 22 class Completion:
@@ -22,6 +24,7 @@ class Completion:
22 24
23 25 @staticmethod
24 26 def create(provider: Provider, prompt: str, **kwargs) -> str:
27
25 28 """
26 29 Invokes the given provider with given prompt and addition arguments and returns the string response
27 30
@@ -40,8 +43,14 @@ class Completion:
40 43 return Completion.__theb_service(prompt, **kwargs)
41 44 elif provider == Provider.CoCalc:
42 45 return Completion.__cocalc_service(prompt, **kwargs)
46 elif provider == Provider.UseLess:
47 return Completion.__useless_service(prompt, **kwargs)
43 48 else:
44 49 raise Exception('Provider not exist, Please try again')
50
51 @staticmethod
52 def __useless_service(prompt: str, **kwargs) -> str:
53 return usesless.Completion.create(prompt = prompt, **kwargs)
45 54
46 55 @staticmethod
47 56 def __you_service(prompt: str, **kwargs) -> str:
Renamed gpt4free/usesless/README.md +0 -0
此文件没有可显示的逐行差异。
Renamed gpt4free/usesless/__init__.py +4 -0
@@ -23,6 +23,8 @@ class Completion:
23 23 temperature: float = 1,
24 24 model: str = "gpt-3.5-turbo",
25 25 ):
26 print(parentMessageId, prompt)
27
26 28 json_data = {
27 29 "openaiKey": "",
28 30 "prompt": prompt,
@@ -40,12 +42,14 @@ class Completion:
40 42 url = "https://ai.usesless.com/api/chat-process"
41 43 request = requests.post(url, headers=Completion.headers, json=json_data)
42 44 content = request.content
45
43 46 response = Completion.__response_to_json(content)
44 47 return response
45 48
46 49 @classmethod
47 50 def __response_to_json(cls, text) -> dict:
48 51 text = str(text.decode("utf-8"))
52
49 53 split_text = text.rsplit("\n", 1)[1]
50 54 to_json = json.loads(split_text)
51 55 return to_json
Modified gui/streamlit_chat_app.py +0 -1
@@ -11,7 +11,6 @@ import pickle
11 11
12 12 conversations_file = "conversations.pkl"
13 13
14
15 14 def load_conversations():
16 15 try:
17 16 with open(conversations_file, "rb") as f:
Modified requirements.txt +1 -1
@@ -10,4 +10,4 @@ selenium
10 10 fake-useragent
11 11 twocaptcha
12 12 https://github.com/AI-Yash/st-chat/archive/refs/pull/24/head.zip
13 pydantic
13 pydantic
Renamed testing/theb_test.py +0 -0
此文件没有可显示的逐行差异。
Added testing/useless_test.py +27 -0
@@ -0,0 +1,27 @@
1 from gpt4free import usesless
2
3 message_id = ""
4 while True:
5 prompt = input("Question: ")
6 if prompt == "!stop":
7 break
8
9 req = usesless.Completion.create(prompt=prompt, parentMessageId=message_id)
10
11 print(f"Answer: {req['text']}")
12 message_id = req["id"]
13
14
15 import gpt4free
16
17 message_id = ""
18 while True:
19 prompt = input("Question: ")
20 if prompt == "!stop":
21 break
22
23 req = gpt4free.Completion.create(provider = gpt4free.Provider.UseLess,
24 prompt=prompt, parentMessageId=message_id)
25
26 print(f"Answer: {req['text']}")
27 message_id = req["id"]
Modified unfinished/chatpdf/__init__.py +47 -40
@@ -1,59 +1,66 @@
1 1 import requests
2 2 import json
3 3
4 from queue import Queue, Empty
5 from threading import Thread
6 from json import loads
7 from re import findall
8
9
4 10 class Completion:
5 11
6 12 def request(prompt: str):
7 13 '''TODO: some sort of authentication + upload PDF from URL or local file
8 Then you should get the atoken and chat ID
9 '''
10
14 Then you should get the atoken and chat ID
15 '''
16
11 17 token = "your_token_here"
12 18 chat_id = "your_chat_id_here"
13 19
14 20 url = "https://chat-pr4yueoqha-ue.a.run.app/"
15 21
16 22 payload = json.dumps({
17 "v": 2,
18 "chatSession": {
19 "type": "join",
20 "chatId": chat_id
21 },
22 "history": [
23 {
24 "id": "VNsSyJIq_0",
25 "author": "p_if2GPSfyN8hjDoA7unYe",
26 "msg": "<start>",
27 "time": 1682672009270
28 },
29 {
30 "id": "Zk8DRUtx_6",
31 "author": "uplaceholder",
32 "msg": prompt,
33 "time": 1682672181339
34 }
35 ]
36 })
37
23 "v": 2,
24 "chatSession": {
25 "type": "join",
26 "chatId": chat_id
27 },
28 "history": [
29 {
30 "id": "VNsSyJIq_0",
31 "author": "p_if2GPSfyN8hjDoA7unYe",
32 "msg": "<start>",
33 "time": 1682672009270
34 },
35 {
36 "id": "Zk8DRUtx_6",
37 "author": "uplaceholder",
38 "msg": prompt,
39 "time": 1682672181339
40 }
41 ]
42 })
43
38 44 # TODO: fix headers, use random user-agent, streaming response, etc
39 45 headers = {
40 'authority': 'chat-pr4yueoqha-ue.a.run.app',
41 'accept': '*/*',
42 'accept-language': 'en-US,en;q=0.9',
43 'atoken': token,
44 'content-type': 'application/json',
45 'origin': 'https://www.chatpdf.com',
46 'referer': 'https://www.chatpdf.com/',
47 'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
48 'sec-ch-ua-mobile': '?0',
49 'sec-ch-ua-platform': '"Windows"',
50 'sec-fetch-dest': 'empty',
51 'sec-fetch-mode': 'cors',
52 'sec-fetch-site': 'cross-site',
53 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
54 }
46 'authority': 'chat-pr4yueoqha-ue.a.run.app',
47 'accept': '*/*',
48 'accept-language': 'en-US,en;q=0.9',
49 'atoken': token,
50 'content-type': 'application/json',
51 'origin': 'https://www.chatpdf.com',
52 'referer': 'https://www.chatpdf.com/',
53 'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
54 'sec-ch-ua-mobile': '?0',
55 'sec-ch-ua-platform': '"Windows"',
56 'sec-fetch-dest': 'empty',
57 'sec-fetch-mode': 'cors',
58 'sec-fetch-site': 'cross-site',
59 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
60 }
55 61
56 response = requests.request("POST", url, headers=headers, data=payload).text
62 response = requests.request(
63 "POST", url, headers=headers, data=payload).text
57 64 Completion.stream_completed = True
58 65 return {'response': response}
59 66