Just a Test for History support
Browse files- webscout.py +3 -6
webscout.py
CHANGED
|
@@ -178,7 +178,6 @@ class WEBS:
|
|
| 178 |
verify=False,
|
| 179 |
)
|
| 180 |
self._exception_event = Event()
|
| 181 |
-
self._chat_messages: List[Dict[str, str]] = []
|
| 182 |
self._chat_vqd: str = ""
|
| 183 |
|
| 184 |
def __enter__(self) -> "WEBS":
|
|
@@ -227,7 +226,7 @@ class WEBS:
|
|
| 227 |
resp_content = self._get_url("POST", "https://duckduckgo.com", data={"q": keywords})
|
| 228 |
return _extract_vqd(resp_content, keywords)
|
| 229 |
|
| 230 |
-
def chat(self, keywords: str, model: str = "gpt-3.5", timeout: int = 20) -> str:
|
| 231 |
"""Initiates a chat session with DuckDuckGo AI.
|
| 232 |
|
| 233 |
Args:
|
|
@@ -251,11 +250,11 @@ class WEBS:
|
|
| 251 |
resp = self.client.get("https://duckduckgo.com/duckchat/v1/status", headers={"x-vqd-accept": "1"})
|
| 252 |
self._chat_vqd = resp.headers.get("x-vqd-4", "")
|
| 253 |
|
| 254 |
-
|
| 255 |
|
| 256 |
json_data = {
|
| 257 |
"model": models[model],
|
| 258 |
-
"messages":
|
| 259 |
}
|
| 260 |
resp = self.client.post(
|
| 261 |
"https://duckduckgo.com/duckchat/v1/chat",
|
|
@@ -267,8 +266,6 @@ class WEBS:
|
|
| 267 |
|
| 268 |
data = ",".join(x for line in resp.text.rstrip("[DONE]\n").split("data:") if (x := line.strip()))
|
| 269 |
result = "".join(x.get("message", "") for x in json_loads("[" + data + "]"))
|
| 270 |
-
|
| 271 |
-
self._chat_messages.append({"role": "assistant", "content": result})
|
| 272 |
return result
|
| 273 |
|
| 274 |
def text(
|
|
|
|
| 178 |
verify=False,
|
| 179 |
)
|
| 180 |
self._exception_event = Event()
|
|
|
|
| 181 |
self._chat_vqd: str = ""
|
| 182 |
|
| 183 |
def __enter__(self) -> "WEBS":
|
|
|
|
| 226 |
resp_content = self._get_url("POST", "https://duckduckgo.com", data={"q": keywords})
|
| 227 |
return _extract_vqd(resp_content, keywords)
|
| 228 |
|
| 229 |
+
def chat(self, keywords: str, model: str = "gpt-3.5", chat_messages: List[Dict[str, str]] = [], timeout: int = 20) -> str:
|
| 230 |
"""Initiates a chat session with DuckDuckGo AI.
|
| 231 |
|
| 232 |
Args:
|
|
|
|
| 250 |
resp = self.client.get("https://duckduckgo.com/duckchat/v1/status", headers={"x-vqd-accept": "1"})
|
| 251 |
self._chat_vqd = resp.headers.get("x-vqd-4", "")
|
| 252 |
|
| 253 |
+
chat_messages.append({"role": "user", "content": keywords})
|
| 254 |
|
| 255 |
json_data = {
|
| 256 |
"model": models[model],
|
| 257 |
+
"messages": chat_messages,
|
| 258 |
}
|
| 259 |
resp = self.client.post(
|
| 260 |
"https://duckduckgo.com/duckchat/v1/chat",
|
|
|
|
| 266 |
|
| 267 |
data = ",".join(x for line in resp.text.rstrip("[DONE]\n").split("data:") if (x := line.strip()))
|
| 268 |
result = "".join(x.get("message", "") for x in json_loads("[" + data + "]"))
|
|
|
|
|
|
|
| 269 |
return result
|
| 270 |
|
| 271 |
def text(
|