返回提交历史
Modified
g4f/Provider/DeepInfra.py
+2
-1
Modified
g4f/Provider/HuggingChat.py
+26
-10
Modified
g4f/Provider/Llama.py
+3
-3
Modified
g4f/Provider/Replicate.py
+3
-0
Modified
g4f/cookies.py
+3
-1
Modified
g4f/models.py
+9
-8
XFEstudio/gpt4free
Fix typo in model list
002a4a1d
代码差异
6 个文件
+46
-23
@@ -9,13 +9,14 @@ class DeepInfra(Openai):
9
9
label = "DeepInfra"
10
10
url = "https://deepinfra.com"
11
11
working = True
12
needs_auth = False
12
13
has_auth = True
13
14
supports_stream = True
14
15
supports_message_history = True
15
16
default_model = "meta-llama/Meta-Llama-3-70b-instruct"
16
17
default_vision_model = "llava-hf/llava-1.5-7b-hf"
17
18
model_aliases = {
18
'mixtral-8x22b': 'HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1'
19
'dbrx-instruct': 'databricks/dbrx-instruct',
19
20
}
20
21
21
22
@classmethod
@@ -6,12 +6,14 @@ from aiohttp import ClientSession, BaseConnector
6
6
7
7
from ..typing import AsyncResult, Messages
8
8
from ..requests.raise_for_status import raise_for_status
9
from ..providers.conversation import BaseConversation
9
10
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
10
from .helper import format_prompt, get_connector
11
from .helper import format_prompt, get_connector, get_cookies
11
12
12
13
class HuggingChat(AsyncGeneratorProvider, ProviderModelMixin):
13
14
url = "https://huggingface.co/chat"
14
15
working = True
16
needs_auth = True
15
17
default_model = "mistralai/Mixtral-8x7B-Instruct-v0.1"
16
18
models = [
17
19
"HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1",
@@ -22,9 +24,6 @@ class HuggingChat(AsyncGeneratorProvider, ProviderModelMixin):
22
24
'mistralai/Mistral-7B-Instruct-v0.2',
23
25
'meta-llama/Meta-Llama-3-70B-Instruct'
24
26
]
25
model_aliases = {
26
"openchat/openchat_3.5": "openchat/openchat-3.5-0106",
27
}
28
27
29
28
@classmethod
30
29
def get_models(cls):
@@ -45,9 +44,16 @@ class HuggingChat(AsyncGeneratorProvider, ProviderModelMixin):
45
44
connector: BaseConnector = None,
46
45
web_search: bool = False,
47
46
cookies: dict = None,
47
conversation: Conversation = None,
48
return_conversation: bool = False,
49
delete_conversation: bool = True,
48
50
**kwargs
49
51
) -> AsyncResult:
50
52
options = {"model": cls.get_model(model)}
53
if cookies is None:
54
cookies = get_cookies("huggingface.co", False)
55
if return_conversation:
56
delete_conversation = False
51
57
52
58
system_prompt = "\n".join([message["content"] for message in messages if message["role"] == "system"])
53
59
if system_prompt:
@@ -61,9 +67,14 @@ class HuggingChat(AsyncGeneratorProvider, ProviderModelMixin):
61
67
headers=headers,
62
68
connector=get_connector(connector, proxy)
63
69
) as session:
64
async with session.post(f"{cls.url}/conversation", json=options) as response:
65
await raise_for_status(response)
66
conversation_id = (await response.json())["conversationId"]
70
if conversation is None:
71
async with session.post(f"{cls.url}/conversation", json=options) as response:
72
await raise_for_status(response)
73
conversation_id = (await response.json())["conversationId"]
74
if return_conversation:
75
yield Conversation(conversation_id)
76
else:
77
conversation_id = conversation.conversation_id
67
78
async with session.get(f"{cls.url}/conversation/{conversation_id}/__data.json") as response:
68
79
await raise_for_status(response)
69
80
data: list = (await response.json())["nodes"][1]["data"]
@@ -72,7 +83,7 @@ class HuggingChat(AsyncGeneratorProvider, ProviderModelMixin):
72
83
message_id: str = data[message_keys["id"]]
73
84
options = {
74
85
"id": message_id,
75
"inputs": format_prompt(messages),
86
"inputs": format_prompt(messages) if conversation is None else messages[-1]["content"],
76
87
"is_continue": False,
77
88
"is_retry": False,
78
89
"web_search": web_search
@@ -92,5 +103,10 @@ class HuggingChat(AsyncGeneratorProvider, ProviderModelMixin):
92
103
yield token
93
104
elif line["type"] == "finalAnswer":
94
105
break
95
async with session.delete(f"{cls.url}/conversation/{conversation_id}") as response:
96
await raise_for_status(response)
106
if delete_conversation:
107
async with session.delete(f"{cls.url}/conversation/{conversation_id}") as response:
108
await raise_for_status(response)
109
110
class Conversation(BaseConversation):
111
def __init__(self, conversation_id: str) -> None:
112
self.conversation_id = conversation_id
@@ -11,7 +11,7 @@ class Llama(AsyncGeneratorProvider, ProviderModelMixin):
11
11
url = "https://www.llama2.ai"
12
12
working = True
13
13
supports_message_history = True
14
default_model = "meta/llama-3-70b-chat"
14
default_model = "meta/meta-llama-3-70b-instruct"
15
15
models = [
16
16
"meta/llama-2-7b-chat",
17
17
"meta/llama-2-13b-chat",
@@ -20,8 +20,8 @@ class Llama(AsyncGeneratorProvider, ProviderModelMixin):
20
20
"meta/meta-llama-3-70b-instruct",
21
21
]
22
22
model_aliases = {
23
"meta-llama/Meta-Llama-3-8b-instruct": "meta/meta-llama-3-8b-instruct",
24
"meta-llama/Meta-Llama-3-70b-instruct": "meta/meta-llama-3-70b-instruct",
23
"meta-llama/Meta-Llama-3-8B-Instruct": "meta/meta-llama-3-8b-instruct",
24
"meta-llama/Meta-Llama-3-70B-Instruct": "meta/meta-llama-3-70b-instruct",
25
25
"meta-llama/Llama-2-7b-chat-hf": "meta/llama-2-7b-chat",
26
26
"meta-llama/Llama-2-13b-chat-hf": "meta/llama-2-13b-chat",
27
27
"meta-llama/Llama-2-70b-chat-hf": "meta/llama-2-70b-chat",
@@ -11,6 +11,9 @@ class Replicate(AsyncGeneratorProvider, ProviderModelMixin):
11
11
url = "https://replicate.com"
12
12
working = True
13
13
default_model = "meta/meta-llama-3-70b-instruct"
14
model_aliases = {
15
"meta-llama/Meta-Llama-3-70B-Instruct": default_model
16
}
14
17
15
18
@classmethod
16
19
async def create_async_generator(
@@ -29,7 +29,9 @@ _cookies: Dict[str, Cookies] = {}
29
29
DOMAINS = [
30
30
".bing.com",
31
31
".meta.ai",
32
".google.com"
32
".google.com",
33
"www.whiterabbitneo.com",
34
"huggingface.co"
33
35
]
34
36
35
37
if has_browser_cookie3 and os.environ.get('DBUS_SESSION_BUS_ADDRESS') == "/dev/null":
@@ -25,6 +25,7 @@ from .Provider import (
25
25
Llama,
26
26
OpenaiChat,
27
27
PerplexityLabs,
28
Replicate,
28
29
Pi,
29
30
Vercel,
30
31
You,
@@ -137,19 +138,19 @@ llama2_13b = Model(
137
138
llama2_70b = Model(
138
139
name = "meta-llama/Llama-2-70b-chat-hf",
139
140
base_provider = "meta",
140
best_provider = RetryProvider([Llama, DeepInfra, HuggingChat])
141
best_provider = RetryProvider([Llama, DeepInfra])
141
142
)
142
143
143
144
llama3_8b_instruct = Model(
144
name = "meta-llama/Meta-Llama-3-8b-instruct",
145
name = "meta-llama/Meta-Llama-3-8B-Instruct",
145
146
base_provider = "meta",
146
best_provider = RetryProvider([Llama])
147
best_provider = RetryProvider([Llama, DeepInfra, Replicate])
147
148
)
148
149
149
150
llama3_70b_instruct = Model(
150
name = "meta-llama/Meta-Llama-3-70b-instruct",
151
name = "meta-llama/Meta-Llama-3-70B-Instruct",
151
152
base_provider = "meta",
152
best_provider = RetryProvider([Llama, HuggingChat])
153
best_provider = RetryProvider([Llama, DeepInfra])
153
154
)
154
155
155
156
codellama_34b_instruct = Model(
@@ -168,7 +169,7 @@ codellama_70b_instruct = Model(
168
169
mixtral_8x7b = Model(
169
170
name = "mistralai/Mixtral-8x7B-Instruct-v0.1",
170
171
base_provider = "huggingface",
171
best_provider = RetryProvider([DeepInfra, HuggingChat, HuggingFace, PerplexityLabs])
172
best_provider = RetryProvider([DeepInfra, HuggingFace, PerplexityLabs])
172
173
)
173
174
174
175
mistral_7b = Model(
@@ -186,7 +187,7 @@ mistral_7b_v02 = Model(
186
187
mixtral_8x22b = Model(
187
188
name = "HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1",
188
189
base_provider = "huggingface",
189
best_provider = RetryProvider([HuggingChat, DeepInfra])
190
best_provider = DeepInfra
190
191
)
191
192
192
193
# Misc models
@@ -211,7 +212,7 @@ airoboros_70b = Model(
211
212
openchat_35 = Model(
212
213
name = "openchat/openchat_3.5",
213
214
base_provider = "huggingface",
214
best_provider = RetryProvider([DeepInfra, HuggingChat])
215
best_provider = DeepInfra
215
216
)
216
217
217
218
# Bard