返回提交历史
Deleted
g4f/Provider/DuckDuckGo.py
+0
-85
Modified
g4f/Provider/__init__.py
+0
-1
Modified
g4f/models.py
+1
-3
XFEstudio/gpt4free
requested removal of DuckDuckGo
b9ced12c
代码差异
3 个文件
+1
-89
@@ -1,85 +0,0 @@
1
from __future__ import annotations
2
3
import json
4
import aiohttp
5
6
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
7
from .helper import get_connector
8
from ..typing import AsyncResult, Messages
9
from ..requests.raise_for_status import raise_for_status
10
from ..providers.conversation import BaseConversation
11
12
class DuckDuckGo(AsyncGeneratorProvider, ProviderModelMixin):
13
url = "https://duckduckgo.com/duckchat"
14
working = True
15
supports_gpt_35_turbo = True
16
supports_message_history = True
17
18
default_model = "gpt-3.5-turbo-0125"
19
models = ["gpt-3.5-turbo-0125", "claude-3-haiku-20240307"]
20
model_aliases = {
21
"gpt-3.5-turbo": "gpt-3.5-turbo-0125",
22
"claude-3-haiku": "claude-3-haiku-20240307"
23
}
24
25
status_url = "https://duckduckgo.com/duckchat/v1/status"
26
chat_url = "https://duckduckgo.com/duckchat/v1/chat"
27
user_agent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0'
28
headers = {
29
'User-Agent': user_agent,
30
'Accept': 'text/event-stream',
31
'Accept-Language': 'de,en-US;q=0.7,en;q=0.3',
32
'Accept-Encoding': 'gzip, deflate, br',
33
'Referer': 'https://duckduckgo.com/',
34
'Content-Type': 'application/json',
35
'Origin': 'https://duckduckgo.com',
36
'Connection': 'keep-alive',
37
'Cookie': 'dcm=1',
38
'Sec-Fetch-Dest': 'empty',
39
'Sec-Fetch-Mode': 'cors',
40
'Sec-Fetch-Site': 'same-origin',
41
'Pragma': 'no-cache',
42
'TE': 'trailers'
43
}
44
45
@classmethod
46
async def create_async_generator(
47
cls,
48
model: str,
49
messages: Messages,
50
proxy: str = None,
51
connector: aiohttp.BaseConnector = None,
52
conversation: Conversation = None,
53
return_conversation: bool = False,
54
**kwargs
55
) -> AsyncResult:
56
async with aiohttp.ClientSession(headers=cls.headers, connector=get_connector(connector, proxy)) as session:
57
if conversation is not None and len(messages) > 1:
58
vqd_4 = conversation.vqd_4
59
messages = [*conversation.messages, messages[-2], messages[-1]]
60
else:
61
async with session.get(cls.status_url, headers={"x-vqd-accept": "1"}) as response:
62
await raise_for_status(response)
63
vqd_4 = response.headers.get("x-vqd-4")
64
messages = [messages[-1]]
65
payload = {
66
'model': cls.get_model(model),
67
'messages': messages
68
}
69
async with session.post(cls.chat_url, json=payload, headers={"x-vqd-4": vqd_4}) as response:
70
await raise_for_status(response)
71
if return_conversation:
72
yield Conversation(response.headers.get("x-vqd-4"), messages)
73
async for line in response.content:
74
if line.startswith(b"data: "):
75
chunk = line[6:]
76
if chunk.startswith(b"[DONE]"):
77
break
78
data = json.loads(chunk)
79
if "message" in data and data["message"]:
80
yield data["message"]
81
82
class Conversation(BaseConversation):
83
def __init__(self, vqd_4: str, messages: Messages) -> None:
84
self.vqd_4 = vqd_4
85
self.messages = messages
@@ -25,7 +25,6 @@ from .Cnote import Cnote
25
25
from .Cohere import Cohere
26
26
from .DeepInfra import DeepInfra
27
27
from .DeepInfraImage import DeepInfraImage
28
from .DuckDuckGo import DuckDuckGo
29
28
from .Feedough import Feedough
30
29
from .FlowGpt import FlowGpt
31
30
from .FreeChatgpt import FreeChatgpt
@@ -11,7 +11,6 @@ from .Provider import (
11
11
ChatgptNext,
12
12
Cnote,
13
13
DeepInfra,
14
DuckDuckGo,
15
14
Feedough,
16
15
FreeGpt,
17
16
Gemini,
@@ -71,7 +70,6 @@ gpt_35_long = Model(
71
70
ChatgptNext,
72
71
OpenaiChat,
73
72
Koala,
74
DuckDuckGo,
75
73
])
76
74
)
77
75
@@ -196,7 +194,7 @@ claude_3_sonnet = Model(
196
194
claude_3_haiku = Model(
197
195
name = 'claude-3-haiku',
198
196
base_provider = 'anthropic',
199
best_provider = DuckDuckGo
197
best_provider = None
200
198
)
201
199
202
200
gpt_35_turbo_16k = Model(