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

XFEstudio/gpt4free

small fixes & new pypi version

d53fc931
abc <98614666+xtekky@users.noreply.github.com>
提交于

代码差异

5 个文件 +115 -5
Modified .gitignore +1 -0
@@ -35,6 +35,7 @@ dist/
35 35 *.egg-info
36 36 build
37 37 test.py
38 update.py
38 39
39 40 # Emacs crap
40 41 *~
Modified g4f/Provider/Providers/Vercel.py +110 -0
@@ -42,6 +42,116 @@ vercel_models = {'anthropic:claude-instant-v1': {'id': 'anthropic:claude-instant
42 42 'id': 'huggingface:bigcode/santacoder', 'provider': 'huggingface', 'providerHumanName': 'HuggingFace', 'makerHumanName': 'BigCode', 'instructions': 'The model was trained on GitHub code. As such it is not an instruction model and commands like "Write a function that computes the square root." do not work well. You should phrase commands like they occur in source code such as comments (e.g. # the following function computes the sqrt) or write a function signature and docstring and let the model complete the function body.', 'parameters': {'temperature': {'value': 0.5, 'range': [0.1, 1]}, 'maximumLength': {'value': 200, 'range': [50, 1024]}, 'topP': {'value': 0.95, 'range': [0.01, 0.99]}, 'topK': {'value': 4, 'range': [1, 500]}, 'repetitionPenalty': {'value': 1.03, 'range': [0.1, 2]}}, 'name': 'santacoder'}, 'cohere:command-medium-nightly': {'id': 'cohere:command-medium-nightly', 'provider': 'cohere', 'providerHumanName': 'Cohere', 'makerHumanName': 'Cohere', 'name': 'command-medium-nightly', 'parameters': {'temperature': {'value': 0.9, 'range': [0, 2]}, 'maximumLength': {'value': 200, 'range': [50, 1024]}, 'topP': {'value': 1, 'range': [0, 1]}, 'topK': {'value': 0, 'range': [0, 500]}, 'presencePenalty': {'value': 0, 'range': [0, 1]}, 'frequencyPenalty': {'value': 0, 'range': [0, 1]}, 'stopSequences': {'value': [], 'range': []}}}, 'cohere:command-xlarge-nightly': {'id': 'cohere:command-xlarge-nightly', 'provider': 'cohere', 'providerHumanName': 'Cohere', 'makerHumanName': 'Cohere', 'name': 'command-xlarge-nightly', 'parameters': {'temperature': {'value': 0.9, 'range': [0, 2]}, 'maximumLength': {'value': 200, 'range': [50, 1024]}, 'topP': {'value': 1, 'range': [0, 1]}, 'topK': {'value': 0, 'range': [0, 500]}, 'presencePenalty': {'value': 0, 'range': [0, 1]}, 'frequencyPenalty': {'value': 0, 'range': [0, 1]}, 'stopSequences': {'value': [], 'range': []}}}, 'openai:gpt-4': {'id': 'openai:gpt-4', 'provider': 'openai', 'providerHumanName': 'OpenAI', 'makerHumanName': 'OpenAI', 'name': 'gpt-4', 'minBillingTier': 'pro', 'parameters': {'temperature': {'value': 0.7, 'range': [0.1, 1]}, 'maximumLength': {'value': 200, 'range': [50, 1024]}, 'topP': {'value': 1, 'range': [0.1, 1]}, 'presencePenalty': {'value': 0, 'range': [0, 1]}, 'frequencyPenalty': {'value': 0, 'range': [0, 1]}, 'stopSequences': {'value': [], 'range': []}}}, 'openai:code-cushman-001': {'id': 'openai:code-cushman-001', 'provider': 'openai', 'providerHumanName': 'OpenAI', 'makerHumanName': 'OpenAI', 'parameters': {'temperature': {'value': 0.5, 'range': [0.1, 1]}, 'maximumLength': {'value': 200, 'range': [50, 1024]}, 'topP': {'value': 1, 'range': [0.1, 1]}, 'presencePenalty': {'value': 0, 'range': [0, 1]}, 'frequencyPenalty': {'value': 0, 'range': [0, 1]}, 'stopSequences': {'value': [], 'range': []}}, 'name': 'code-cushman-001'}, 'openai:code-davinci-002': {'id': 'openai:code-davinci-002', 'provider': 'openai', 'providerHumanName': 'OpenAI', 'makerHumanName': 'OpenAI', 'parameters': {'temperature': {'value': 0.5, 'range': [0.1, 1]}, 'maximumLength': {'value': 200, 'range': [50, 1024]}, 'topP': {'value': 1, 'range': [0.1, 1]}, 'presencePenalty': {'value': 0, 'range': [0, 1]}, 'frequencyPenalty': {'value': 0, 'range': [0, 1]}, 'stopSequences': {'value': [], 'range': []}}, 'name': 'code-davinci-002'}, 'openai:gpt-3.5-turbo': {'id': 'openai:gpt-3.5-turbo', 'provider': 'openai', 'providerHumanName': 'OpenAI', 'makerHumanName': 'OpenAI', 'parameters': {'temperature': {'value': 0.7, 'range': [0, 1]}, 'maximumLength': {'value': 200, 'range': [50, 1024]}, 'topP': {'value': 1, 'range': [0.1, 1]}, 'topK': {'value': 1, 'range': [1, 500]}, 'presencePenalty': {'value': 1, 'range': [0, 1]}, 'frequencyPenalty': {'value': 1, 'range': [0, 1]}, 'stopSequences': {'value': [], 'range': []}}, 'name': 'gpt-3.5-turbo'}, 'openai:text-ada-001': {'id': 'openai:text-ada-001', 'provider': 'openai', 'providerHumanName': 'OpenAI', 'makerHumanName': 'OpenAI', 'name': 'text-ada-001', 'parameters': {'temperature': {'value': 0.5, 'range': [0.1, 1]}, 'maximumLength': {'value': 200, 'range': [50, 1024]}, 'topP': {'value': 1, 'range': [0.1, 1]}, 'presencePenalty': {'value': 0, 'range': [0, 1]}, 'frequencyPenalty': {'value': 0, 'range': [0, 1]}, 'stopSequences': {'value': [], 'range': []}}}, 'openai:text-babbage-001': {'id': 'openai:text-babbage-001', 'provider': 'openai', 'providerHumanName': 'OpenAI', 'makerHumanName': 'OpenAI', 'name': 'text-babbage-001', 'parameters': {'temperature': {'value': 0.5, 'range': [0.1, 1]}, 'maximumLength': {'value': 200, 'range': [50, 1024]}, 'topP': {'value': 1, 'range': [0.1, 1]}, 'presencePenalty': {'value': 0, 'range': [0, 1]}, 'frequencyPenalty': {'value': 0, 'range': [0, 1]}, 'stopSequences': {'value': [], 'range': []}}}, 'openai:text-curie-001': {'id': 'openai:text-curie-001', 'provider': 'openai', 'providerHumanName': 'OpenAI', 'makerHumanName': 'OpenAI', 'name': 'text-curie-001', 'parameters': {'temperature': {'value': 0.5, 'range': [0.1, 1]}, 'maximumLength': {'value': 200, 'range': [50, 1024]}, 'topP': {'value': 1, 'range': [0.1, 1]}, 'presencePenalty': {'value': 0, 'range': [0, 1]}, 'frequencyPenalty': {'value': 0, 'range': [0, 1]}, 'stopSequences': {'value': [], 'range': []}}}, 'openai:text-davinci-002': {'id': 'openai:text-davinci-002', 'provider': 'openai', 'providerHumanName': 'OpenAI', 'makerHumanName': 'OpenAI', 'name': 'text-davinci-002', 'parameters': {'temperature': {'value': 0.5, 'range': [0.1, 1]}, 'maximumLength': {'value': 200, 'range': [50, 1024]}, 'topP': {'value': 1, 'range': [0.1, 1]}, 'presencePenalty': {'value': 0, 'range': [0, 1]}, 'frequencyPenalty': {'value': 0, 'range': [0, 1]}, 'stopSequences': {'value': [], 'range': []}}}, 'openai:text-davinci-003': {'id': 'openai:text-davinci-003', 'provider': 'openai', 'providerHumanName': 'OpenAI', 'makerHumanName': 'OpenAI', 'name': 'text-davinci-003', 'parameters': {'temperature': {'value': 0.5, 'range': [0.1, 1]}, 'maximumLength': {'value': 200, 'range': [50, 1024]}, 'topP': {'value': 1, 'range': [0.1, 1]}, 'presencePenalty': {'value': 0, 'range': [0, 1]}, 'frequencyPenalty': {'value': 0, 'range': [0, 1]}, 'stopSequences': {'value': [], 'range': []}}}}
43 43
44 44
45 # import requests
46 # import execjs
47 # import ubox
48 # import json
49 # import re
50
51
52 # html = requests.get('https://sdk.vercel.ai/').text
53 # paths_regex = r'static\/chunks.+?\.js'
54 # separator_regex = r'"\]\)<\/script><script>self\.__next_f\.push\(\[.,"'
55
56 # paths = re.findall(paths_regex, html)
57 # for i in range(len(paths)):
58 # paths[i] = re.sub(separator_regex, "", paths[i])
59 # paths = list(set(paths))
60 # print(paths)
61
62 # scripts = []
63 # threads = []
64
65 # print(f"Downloading and parsing scripts...")
66 # def download_thread(path):
67 # script_url = f"{self.base_url}/_next/{path}"
68 # script = self.session.get(script_url).text
69 # scripts.append(script)
70
71 # for path in paths:
72 # thread = threading.Thread(target=download_thread, args=(path,), daemon=True)
73 # thread.start()
74 # threads.append(thread)
75
76 # for thread in threads:
77 # thread.join()
78
79 # for script in scripts:
80 # models_regex = r'let .="\\n\\nHuman:\",r=(.+?),.='
81 # matches = re.findall(models_regex, script)
82
83 # if matches:
84 # models_str = matches[0]
85 # stop_sequences_regex = r'(?<=stopSequences:{value:\[)\D(?<!\])'
86 # models_str = re.sub(stop_sequences_regex, re.escape('"\\n\\nHuman:"'), models_str)
87
88 # context = quickjs.Context()
89 # json_str = context.eval(f"({models_str})").json()
90 # #return json.loads(json_str)
91
92 # quit()
93 # headers = {
94 # 'authority': 'sdk.vercel.ai',
95 # 'accept': '*/*',
96 # 'accept-language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
97 # 'content-type': 'application/json',
98 # 'origin': 'https://sdk.vercel.ai',
99 # 'referer': 'https://sdk.vercel.ai/',
100 # 'sec-ch-ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
101 # 'sec-ch-ua-mobile': '?0',
102 # 'sec-ch-ua-platform': '"macOS"',
103 # 'sec-fetch-dest': 'empty',
104 # 'sec-fetch-mode': 'cors',
105 # 'sec-fetch-site': 'same-origin',
106 # 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
107 # }
108
109 # response = requests.get('https://sdk.vercel.ai/openai.jpeg', headers=headers)
110
111 # data = (json.loads(ubox.b64dec(response.text)))
112
113 # script = 'globalThis={data: "sentinel"};a=()=>{return (%s)(%s)}' % (data['c'], data['a'])
114
115 # token_data = execjs.compile(script).call('a')
116 # print(token_data)
117
118 # token = {
119 # 'r': token_data,
120 # 't': data["t"]
121 # }
122
123 # botToken = ubox.b64enc(json.dumps(token, separators=(',', ':')))
124 # print(botToken)
125
126 # import requests
127
128 # headers['custom-encoding'] = botToken
129
130 # json_data = {
131 # 'messages': [
132 # {
133 # 'role': 'user',
134 # 'content': 'hello',
135 # },
136 # ],
137 # 'playgroundId': ubox.uuid4(),
138 # 'chatIndex': 0,
139 # 'model': 'openai:gpt-3.5-turbo',
140 # 'temperature': 0.7,
141 # 'maxTokens': 500,
142 # 'topK': 1,
143 # 'topP': 1,
144 # 'frequencyPenalty': 1,
145 # 'presencePenalty': 1,
146 # 'stopSequences': []
147 # }
148
149 # response = requests.post('https://sdk.vercel.ai/api/generate',
150 # headers=headers, json=json_data, stream=True)
151
152 # for token in response.iter_content(chunk_size=2046):
153 # print(token)
154
45 155 def _create_completion(model: str, messages: list, stream: bool, **kwargs):
46 156 return
47 157 # conversation = 'This is a conversation between a human and a language model, respond to the last message accordingly, referring to the past history of messages if needed.\n'
Modified g4f/__init__.py +1 -1
@@ -6,7 +6,7 @@ logging = False
6 6
7 7 class ChatCompletion:
8 8 @staticmethod
9 def create(model: models.Model | str, messages: list, provider: Provider.Provider = None, stream: bool = False, auth: str = False, **kwargs):
9 def create(model: models.Model or str, messages: list, provider: Provider.Provider = None, stream: bool = False, auth: str = False, **kwargs):
10 10 kwargs['auth'] = auth
11 11 if provider and provider.working == False:
12 12 return f'{provider.__name__} is not working'
Modified g4f/models.py +2 -3
@@ -7,13 +7,12 @@ from dataclasses import dataclass
7 7 class Model:
8 8 name: str
9 9 base_provider: str
10 best_provider: ModuleType | None
11
10 best_provider: ModuleType or None
12 11
13 12 gpt_35_turbo = Model(
14 13 name="gpt-3.5-turbo",
15 14 base_provider="openai",
16 best_provider=Provider.Forefront,
15 best_provider=Provider.GetGpt,
17 16 )
18 17
19 18 gpt_4 = Model(
Modified setup.py +1 -1
@@ -10,7 +10,7 @@ with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
10 10 with open('requirements.txt') as f:
11 11 required = f.read().splitlines()
12 12
13 VERSION = '0.0.1.4'
13 VERSION = '0.0.1.9'
14 14 DESCRIPTION = 'The official gpt4free repository | various collection of powerful language models'
15 15
16 16 # Setting up