mrgick / duck_chat

Reverse engineered DuckDuckGo AI chat API client.
https://pypi.org/project/duck-chat/
MIT License
38 stars 9 forks source link

ERR_CONVERSATION_LIMIT #17

Open h9052300 opened 3 months ago

h9052300 commented 3 months ago

I'll always be in trouble. {“action”: “error”, “status”:429, “type”: “ERR_CONVERSATION_LIMIT”}

k-aito commented 3 months ago

I think it could be a proper error display, but I don't think it can be bypassed. You can reset the chat, and sometimes it helps, but it also stops working after a time. I think it's a limit on the DDG side.

Troptrap commented 3 months ago

Proxies and maybe changing the user agent randomly in duck_chat could help. Somehow DDG identifies the device sending too many requests and throttles it. For me it happens only when I abuse it too much.

Fake user agent is there, I just noticed it. So, only proxies.

mrgick commented 3 months ago

@h9052300 Try to open https://duck.ai in browser - if there is error too, so you need some proxy

k-aito commented 3 months ago

I think it's related that when you use it too much, they just force you to reset the chat. It would not really help to use a proxy or something else, in my opinion.

Troptrap commented 3 months ago

I think it's related that when you use it too much, they just force you to reset the chat. It would not really help to use a proxy or something else, in my opinion.

I'm using it programmatically, changing the model on each completion and I'm still getting throttled. I assume this is what you mean by reset

k-aito commented 3 months ago

Yes, when I use it for long conversation after something like 10 messages, it forces making another conversation. But it's done too much, it just blocks you for some time.

I don't know if it was also like that on the browser, but I could no more use the application for a bit of time.

lunaticsm commented 3 months ago

I guess that's because DDC issue, You can make each question are one session.

Troptrap commented 3 months ago

I guess that's because DDC issue, You can make each question are one session.

async def DDG(self,model: str, prompt: str) -> str:
    ddg_chat = DuckChat(model)
    resp = await ddg_chat.ask_question(prompt)
    await ddg_chat._session.close()
    print(resp)
    return resp

This is how I'm using it and still get limited. This function's argument 'model' comes from another function that randomizes the models, so it also resets history from DDG. So, there is some other pattern that DDG uses to identify same user.

Troptrap commented 3 months ago

@mrgick it's possible that history sent from previous model to trigger some red flag when switching models? I don't know, but I assume they have some bot detection in place

mrgick commented 3 months ago

Hello, sorry for long answer


import asyncio
from duck_chat import DuckChat

async def DDG(model, prompt)
    async with DuckChat(model=model) as chat:
          resp = await ddg_chat.ask_question(prompt)
          print(resp)
    return resp

async def test():
  await DDG("gpt-4o-mini","2+2?")
  await DDG("gpt-4o-mini","Tell answer")

asyncio.run(test())

About bot detection, I think duck.ai start to detect aiohttp connection (maybe bad cookies/tcp timings) or maybe they see that we don't send country.json and status requests.


I think library need to migrate from aiohttp to curl_cffi with more simulating request (maybe this will help)


Also needed more research and for now I don't have much time to migrate library =(

k-aito commented 3 months ago

I think I only got 1 time an issue. Even now, I didn't get the ERR_CONVERSATION_LIMIT yet, but it's true I only use it for a few questions, and then I close the session.

That's why I guess it's not really the library, but just the limitation that DDG choose to apply.

Troptrap commented 2 months ago

I have abused a little bit Duckduckgo's servers lately. I am getting a different error, not the CONVERSATION LIMIT, but ERR_UPSTREAM. I am quite confident it's an IP issue, because as soon as I switch network, it's working again. It could be also fingerprints, but I think bot fingerprinting would persist after IP changing. I will be trying with proxies ASAP and will report here.

Dalveral commented 1 month ago
await ddg_chat._session.close()

Thank you. Its work!

Dalveral commented 1 month ago

Hello. I am getting a 429 error again. However, "await ddg_chat._session.close()" is not working now.

Dalveral commented 1 month ago

I used the method text.replace('\n', '') before sending requests; there were probably too many line breaks in my text. Now there are no errors. I didn't think to check this earlier because I was receiving a 429 error and thought the problem was that the service had restricted access from my device.

Thank you for your work!