Skip to content

Commit

Permalink
chat(): use list comprehension to extract messages
Browse files Browse the repository at this point in the history
  • Loading branch information
deedy5 committed Jun 19, 2024
1 parent b7e8cb7 commit cf8c0d1
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions duckduckgo_search/duckduckgo_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 153,11 @@ def chat(self, keywords: str, model: str = "gpt-3.5") -> str:
)
self._chat_vqd = resp.headers.get("x-vqd-4", "")

messages = []
for line in resp.text.replace("data: ", "").replace("[DONE]", "").split("\n\n"):
x = line.strip()
if x:
j = json_loads(x)
message = j.get("message", "")
messages.append(message)
messages = [
json_loads(x).get("message", "")
for line in resp.text.replace("data: ", "").replace("[DONE]", "").split("\n\n")
if (x := line.strip())
]
result = "".join(messages)
self._chat_messages.append({"role": "assistant", "content": result})
return result
Expand Down

0 comments on commit cf8c0d1

Please sign in to comment.