poe-platform / fastapi_poe

A helper library for writing Poe API bots using FastAPI
Apache License 2.0
132 stars 24 forks source link

Access denied and Error communicating with bot chatGPT #3

Closed Areix closed 1 year ago

Areix commented 1 year ago

I deployed the fastapi_poe on server with public access.

It worked well if directly use bot in POE portal, But when i tried to invoke the API, it returns the below error:

Error in Poe API Bot: Bot request to chatGPT failed on try 0 {"allow_retry": true, "text": "Access denied"}
Error in Poe API Bot: Bot request to chatGPT failed on try 1 {"allow_retry": true, "text": "Access denied"}
2023-07-19 06:34:19,553 - ERROR - Error responding to query
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi_poe/client.py", line 321, in stream_request
    async for message in ctx.perform_query_request(request):
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi_poe/client.py", line 225, in perform_query_request
    raise BotError(event.data)
fastapi_poe.client.BotError: {"allow_retry": true, "text": "Access denied"}

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi_poe/base.py", line 169, in handle_query
    async for event in self.get_response(query):
  File "main_copy.py", line 89, in get_response
    async for msg in stream_request(query, "chatGPT", query.api_key):
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi_poe/client.py", line 330, in stream_request
    raise BotError(f"Error communicating with bot {bot_name}") from e
fastapi_poe.client.BotError: Error communicating with bot chatGPT

The data body i post:

message_id = 'm-000000xy92lr5lnu75wqtc90dg2JDT32' 
message_id1 ='m-000000xy92lr5lyif9g6rbylxbbk3543'
conversation_id = 'c-000000xy92lr5lnu75wqtc90dg2wcf62'
user_id = "u-000000xy92lqv94p4iwlomy2k1242pv0"

data = {
    "version": "1.1",
    "type": "query",
    "query": [
        {
            "role": "user",
            "content": "What is the capital of Nepal?",
            "content_type": "text/markdown",
            "timestamp": int(time.time() * 1_000_000),
            "feedback": [],
            "message_id":message_id1
        }
    ],
    "user_id": user_id, 
    "conversation_id": conversation_id, 
    "message_id": message_id           
}

The query that server receive

>>> query:version='1.1' type='query' query=[ProtocolMessage(role='user', content='What is the capital of Nepal?', content_type='text/markdown', timestamp=1689748457587810, message_id='m-000000xy92lr5lyif9g6rbylxbbk3543', feedback=[])] user_id='u-000000xy92lqv94p4iwlomy2k1242pv0' conversation_id='c-000000xy92lr5lnu75wqtc90dg2wcf62' message_id='m-000000xy92lr5lnu75wqtc90dg2JDT32' api_key='<my api key>'

May i know how to address the issue, thanks

JelleZijlstra commented 1 year ago

You are only allowed a limited number of server-to-Poe API calls per message id, because the server-to-Poe API is meant only for supporting existing Poe server bots, not for more general calls. It's documented at https://developer.poe.com/api-bots/api-to-access-bots-on-poe