返回提交历史
Modified
g4f/Provider/Airforce.py
+18
-182
XFEstudio/gpt4free
feat(g4f/Provider/Airforce.py): update model list and improve text processing
d4e0fd7c
代码差异
1 个文件
+18
-182
@@ -1,6 +1,7 @@
1
1
from __future__ import annotations
2
2
import random
3
3
import json
4
import re
4
5
from aiohttp import ClientSession
5
6
from ..typing import AsyncResult, Messages
6
7
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
@@ -24,176 +25,55 @@ class Airforce(AsyncGeneratorProvider, ProviderModelMixin):
24
25
supports_message_history = True
25
26
26
27
text_models = [
27
# anthorpic
28
28
'claude-3-haiku-20240307',
29
29
'claude-3-sonnet-20240229',
30
30
'claude-3-5-sonnet-20240620',
31
31
'claude-3-opus-20240229',
32
33
# openai
34
32
'chatgpt-4o-latest',
35
33
'gpt-4',
36
#'gpt-4-0613',
37
34
'gpt-4-turbo',
38
35
'gpt-4o-mini-2024-07-18',
39
36
'gpt-4o-mini',
40
37
'gpt-3.5-turbo',
41
38
'gpt-3.5-turbo-0125',
42
39
'gpt-3.5-turbo-1106',
43
#'gpt-3.5-turbo-16k', # No response from the API.
44
#'gpt-3.5-turbo-0613', # No response from the API.
45
#'gpt-3.5-turbo-16k-0613', # No response from the API.
46
'gpt-4o',
47
#'o1-mini', # No response from the API.
48
49
# meta-llama
50
40
'llama-3-70b-chat',
51
41
'llama-3-70b-chat-turbo',
52
42
'llama-3-8b-chat',
53
43
'llama-3-8b-chat-turbo',
54
44
'llama-3-70b-chat-lite',
55
45
'llama-3-8b-chat-lite',
56
#'llama-2-70b-chat', # Failed to load response after multiple retries.
57
46
'llama-2-13b-chat',
58
#'llama-2-7b-chat', # Failed to load response after multiple retries.
59
47
'llama-3.1-405b-turbo',
60
48
'llama-3.1-70b-turbo',
61
49
'llama-3.1-8b-turbo',
62
50
'LlamaGuard-2-8b',
63
51
'Llama-Guard-7b',
64
52
'Llama-3.2-90B-Vision-Instruct-Turbo',
65
66
# codellama
67
#'CodeLlama-7b-Python-hf', # Failed to load response after multiple retries.
68
#'CodeLlama-7b-Python',
69
#'CodeLlama-13b-Python-hf', # Failed to load response after multiple retries.
70
#'CodeLlama-34b-Python-hf', # Failed to load response after multiple retries.
71
#'CodeLlama-70b-Python-hf', # Failed to load response after multiple retries.
72
73
# 01-ai
74
#'Yi-34B-Chat', # Failed to load response after multiple retries.
75
#'Yi-34B', # Failed to load response after multiple retries.
76
#'Yi-6B', # Failed to load response after multiple retries.
77
78
# mistral-ai
79
#'Mixtral-8x7B-v0.1',
80
#'Mixtral-8x22B', # Failed to load response after multiple retries.
81
53
'Mixtral-8x7B-Instruct-v0.1',
82
54
'Mixtral-8x22B-Instruct-v0.1',
83
55
'Mistral-7B-Instruct-v0.1',
84
56
'Mistral-7B-Instruct-v0.2',
85
57
'Mistral-7B-Instruct-v0.3',
86
87
# openchat
88
#'openchat-3.5', # Failed to load response after multiple retries.
89
90
# wizardlm
91
#'WizardLM-13B-V1.2', # Failed to load response after multiple retries.
92
#'WizardCoder-Python-34B-V1.0', # Failed to load response after multiple retries.
93
94
# qwen
95
#'Qwen1.5-0.5B-Chat', # Failed to load response after multiple retries.
96
#'Qwen1.5-1.8B-Chat', # Failed to load response after multiple retries.
97
#'Qwen1.5-4B-Chat', # Failed to load response after multiple retries.
98
58
'Qwen1.5-7B-Chat',
99
59
'Qwen1.5-14B-Chat',
100
60
'Qwen1.5-72B-Chat',
101
61
'Qwen1.5-110B-Chat',
102
62
'Qwen2-72B-Instruct',
103
104
# google
105
63
'gemma-2b-it',
106
#'gemma-7b-it', # Failed to load response after multiple retries.
107
#'gemma-2b', # Failed to load response after multiple retries.
108
#'gemma-7b', # Failed to load response after multiple retries.
109
'gemma-2-9b-it', # fix bug
64
'gemma-2-9b-it',
110
65
'gemma-2-27b-it',
111
112
# gemini
113
66
'gemini-1.5-flash',
114
67
'gemini-1.5-pro',
115
116
# databricks
117
'dbrx-instruct',
118
119
# lmsys
120
#'vicuna-7b-v1.5', # Failed to load response after multiple retries.
121
#'vicuna-13b-v1.5', # Failed to load response after multiple retries.
122
123
# cognitivecomputations
124
#'dolphin-2.5-mixtral-8x7b', # Failed to load response after multiple retries.
125
126
# deepseek-ai
127
#'deepseek-coder-33b-instruct', # No response from the API.
128
#'deepseek-coder-67b-instruct', # Failed to load response after multiple retries.
129
68
'deepseek-llm-67b-chat',
130
131
# NousResearch
132
#'Nous-Capybara-7B-V1p9', # Failed to load response after multiple retries.
133
69
'Nous-Hermes-2-Mixtral-8x7B-DPO',
134
#'Nous-Hermes-2-Mixtral-8x7B-SFT', # Failed to load response after multiple retries.
135
#'Nous-Hermes-llama-2-7b', # Failed to load response after multiple retries.
136
#'Nous-Hermes-Llama2-13b', # Failed to load response after multiple retries.
137
70
'Nous-Hermes-2-Yi-34B',
138
139
# Open-Orca
140
#'Mistral-7B-OpenOrca', # Failed to load response after multiple retries.
141
142
# togethercomputer
143
#'alpaca-7b', # Failed to load response after multiple retries.
144
145
# teknium
146
#'OpenHermes-2-Mistral-7B', # Failed to load response after multiple retries.
147
#'OpenHermes-2.5-Mistral-7B', # Failed to load response after multiple retries.
148
149
# microsoft
150
71
'WizardLM-2-8x22B',
151
152
# Nexusflow
153
#'NexusRaven-V2-13B', # Failed to load response after multiple retries.
154
155
# Phind
156
#'Phind-CodeLlama-34B-v2', # Failed to load response after multiple retries.
157
158
# Snoflake
159
#'snowflake-arctic-instruct', # No response from the API.
160
161
# upstage
162
72
'SOLAR-10.7B-Instruct-v1.0',
163
164
# togethercomputer
165
#'StripedHyena-Hessian-7B', # Failed to load response after multiple retries.
166
#'StripedHyena-Nous-7B', # Failed to load response after multiple retries.
167
#'Llama-2-7B-32K-Instruct', # Failed to load response after multiple retries.
168
#'CodeLlama-13b-Instruct', # No response from the API.
169
#'evo-1-131k-base', # Failed to load response after multiple retries.
170
#'OLMo-7B-Instruct', # Failed to load response after multiple retries.
171
172
# garage-bAInd
173
#'Platypus2-70B-instruct', # Failed to load response after multiple retries.
174
175
# snorkelai
176
#'Snorkel-Mistral-PairRM-DPO', # Failed to load response after multiple retries.
177
178
# Undi95
179
#'ReMM-SLERP-L2-13B', # Failed to load response after multiple retries.
180
181
# Gryphe
182
73
'MythoMax-L2-13b',
183
184
# Autism
185
#'chronos-hermes-13b', # Failed to load response after multiple retries.
186
187
# Undi95
188
#'Toppy-M-7B', # Failed to load response after multiple retries.
189
190
# iFlytek
191
#'sparkdesk', # Failed to load response after multiple retries.
192
193
# pawan
194
74
'cosmosrp',
195
196
75
]
76
197
77
image_models = [
198
78
'flux',
199
79
'flux-realism',
@@ -210,72 +90,19 @@ class Airforce(AsyncGeneratorProvider, ProviderModelMixin):
210
90
*text_models,
211
91
*image_models,
212
92
]
93
213
94
model_aliases = {
214
# anthorpic
215
95
"claude-3-haiku": "claude-3-haiku-20240307",
216
96
"claude-3-sonnet": "claude-3-sonnet-20240229",
217
"claude-3-5-sonnet": "claude-3-5-sonnet-20240620",
218
"claude-3-opus": "claude-3-opus-20240229",
219
220
# openai
221
97
"gpt-4o": "chatgpt-4o-latest",
222
"gpt-4o-mini": "gpt-4o-mini-2024-07-18",
223
"gpt-3.5-turbo": "gpt-3.5-turbo-0125",
224
"gpt-3.5-turbo": "gpt-3.5-turbo-1106",
225
226
# meta-llama
227
98
"llama-3-70b": "llama-3-70b-chat",
228
"llama-3-70b": "llama-3-70b-chat-turbo",
229
99
"llama-3-8b": "llama-3-8b-chat",
230
"llama-3-8b": "llama-3-8b-chat-turbo",
231
"llama-3-70b": "llama-3-70b-chat-lite",
232
"llama-3-8b": "llama-3-8b-chat-lite",
233
"llama-2-13b": "llama-2-13b-chat",
234
"llama-3.1-405b": "llama-3.1-405b-turbo",
235
"llama-3.1-70b": "llama-3.1-70b-turbo",
236
"llama-3.1-8b": "llama-3.1-8b-turbo",
237
"llamaguard-2-8b": "LlamaGuard-2-8b",
238
"llamaguard-7b": "Llama-Guard-7b",
239
"llama-3.2-90b": "Llama-3.2-90B-Vision-Instruct-Turbo",
240
241
# mistral-ai
242
100
"mixtral-8x7b": "Mixtral-8x7B-Instruct-v0.1",
243
"mixtral-8x22b": "Mixtral-8x22B-Instruct-v0.1",
244
"mistral-7b": "Mistral-7B-Instruct-v0.1",
245
"mistral-7b": "Mistral-7B-Instruct-v0.2",
246
"mistral-7b": "Mistral-7B-Instruct-v0.3",
247
248
# qwen
249
101
"qwen-1.5-7b": "Qwen1.5-7B-Chat",
250
"qwen-1.5-14b": "Qwen1.5-14B-Chat",
251
"qwen-1.5-72b": "Qwen1.5-72B-Chat",
252
"qwen-1.5-110b": "Qwen1.5-110B-Chat",
253
"qwen-2-72b": "Qwen2-72B-Instruct",
254
255
# google
256
102
"gemma-2b": "gemma-2b-it",
257
"gemma-2-9b": "gemma-2-9b-it",
258
"gemma-2-27b": "gemma-2-27b-it",
259
260
# gemini
261
103
"gemini-flash": "gemini-1.5-flash",
262
"gemini-pro": "gemini-1.5-pro",
263
264
# deepseek-ai
265
"deepseek": "deepseek-llm-67b-chat",
266
267
# NousResearch
268
"mixtral-8x7b-dpo": "Nous-Hermes-2-Mixtral-8x7B-DPO",
269
"yi-34b": "Nous-Hermes-2-Yi-34B",
270
271
# microsoft
272
"wizardlm-2-8x22b": "WizardLM-2-8x22B",
273
274
# upstage
275
"solar-10.7b": "SOLAR-10.7B-Instruct-v1.0",
276
277
# Gryphe
278
104
"mythomax-l2-13b": "MythoMax-L2-13b",
105
"solar-10.7b": "SOLAR-10.7B-Instruct-v1.0",
279
106
}
280
107
281
108
@classmethod
@@ -300,11 +127,9 @@ class Airforce(AsyncGeneratorProvider, ProviderModelMixin):
300
127
) -> AsyncResult:
301
128
model = cls.get_model(model)
302
129
303
# If the model is an image model, use the image API
304
130
if model in cls.image_models:
305
131
async for result in cls._generate_image(model, messages, proxy, seed, size):
306
132
yield result
307
# If the model is a text model, use the text API
308
133
elif model in cls.text_models:
309
134
async for result in cls._generate_text(model, messages, proxy, stream):
310
135
yield result
@@ -330,7 +155,6 @@ class Airforce(AsyncGeneratorProvider, ProviderModelMixin):
330
155
if seed is None:
331
156
seed = random.randint(0, 100000)
332
157
333
# Assume the first message is the prompt for the image
334
158
prompt = messages[0]['content']
335
159
336
160
async with ClientSession(headers=headers) as session:
@@ -404,10 +228,22 @@ class Airforce(AsyncGeneratorProvider, ProviderModelMixin):
404
228
content = json_data['choices'][0]['message']['content']
405
229
part_response = content
406
230
231
# Видаляємо повідомлення про перевищення ліміту символів
232
part_response = re.sub(
233
r"One message exceeds the \d+chars per message limit\..+https:\/\/discord\.com\/invite\/\S+",
234
'',
235
part_response
236
)
237
238
part_response = re.sub(
239
r"Rate limit \(\d+\/minute\) exceeded\. Join our discord for more: .+https:\/\/discord\.com\/invite\/\S+",
240
'',
241
part_response
242
)
243
407
244
full_response += part_response
408
245
yield full_response
409
246
410
247
@classmethod
411
248
def _format_messages(cls, messages: Messages) -> str:
412
"""Formats messages for text generation."""
413
249
return " ".join([msg['content'] for msg in messages])