Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DDG: allow using conversations and improve UX for incorrect usage #2210

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

0dminnimda
Copy link
Contributor

The vqd-4 changes for each continuation of the converation, thus allowing stepping back or branching, but this contradicts the initial authors assumption. The logic is as such: first status update gives us first empty chat id, the successive chat queries send the new conversation id, we just got to read it and return the new one to the user.

Before that I was getting this if I were to use a conversation (DDG does not allow more than one message without it):

Traceback (most recent call last):
    ...
  File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\g4f\client\client.py", line 29, in iter_response
    for idx, chunk in enumerate(response):
  File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\g4f\providers\base_provider.py", line 223, in create_completion
    yield loop.run_until_complete(await_callback(gen.__anext__))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python3.12.4\Lib\asyncio\base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\g4f\providers\base_provider.py", line 52, in await_callback
    return await callback()
           ^^^^^^^^^^^^^^^^
  File "C:\Python\projects\experiments\gpt4free\DDG.py", line 110, in create_async_generator
    await raise_for_status(response)
  File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\g4f\requests\raise_for_status.py", line 28, in raise_for_status_async
    raise ResponseStatusError(f"Response {response.status}: {message}")
g4f.errors.ResponseStatusError: Response 400: {"action":"error","status":400,"type":"ERR_INVALID_VQD"}

Also it's better to make user track messages, rather than half-tracking present in here (does not track llm answer, so user have to add it to conversation messages for some reason ...) and AFAIC if a user wants to do anything useful with llm, they have to manage the messages history.

The vqd-4 changes for each continuation of the converation, thus
allowing stepping back or branching, but this contradicts the initial
authors assumption. The logic is as such: first status update gives us
first empty chat id, the successive chat queries send the new
conversation id, we just got to read it and return the new one to the
user.

vqd_4_new = response.headers.get("x-vqd-4")
if vqd_4_new is not None:
yield Conversation(vqd_4_new, messages)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I raise an exception if we could not get the conversation id, but the user requested it? Currently it's not a silent error, the user can detect an absence of the Converation chunk.

@TheFirstNoob
Copy link

If i correclty remeber ddg site give 50 messages Converation and after need press "Fire" (clear button).
Maybe need add checking for >49 like

Copy link

Bumping this pull request because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

@kqlio67
Copy link
Contributor

kqlio67 commented Sep 12, 2024

Thank you for these valuable improvements and the detailed explanation about vqd-4 behavior. Your changes significantly enhance error handling and conversation management. I appreciate your efforts in improving the DDG provider. These enhancements make the provider more robust and efficient.

@github-actions github-actions bot removed the stale label Sep 13, 2024
@TheFirstNoob
Copy link

DDG: ValueError: More than one message requires using conversation.

This happening after first message sended or if some "bots" use conversation saving well we have error to

@0dminnimda
Copy link
Contributor Author

DDG: ValueError: More than one message requires using conversation.

Yes, otherwise you'll get an error I referenced in the ticket description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants