import asyncio
from fastapi_poe.types import ProtocolMessage
from fastapi_poe.client import get_bot_response
# Replace <api_key> with your actual API key, ensuring it is a string.
api_key = "xxxx"
# Create an asynchronous function to encapsulate the async for loop
async def get_responses(api_key):
message = ProtocolMessage(role="user", content="Hello world")
async for partial in get_bot_response(messages=[message], bot_name="GPT-3.5-Turbo", api_key=api_key):
print(partial)
# Run the event loop
# For Python 3.7 and newer
asyncio.run(get_responses(api_key))
# For Python 3.6 and older, you would typically do the following:
# loop = asyncio.get_event_loop()
# loop.run_until_complete(get_responses(api_key))
# loop.close()
api key obtaining location: https://poe.com/developers
Reference document: https://developer.poe.com/server-bots/accessing-other-bots-on-poe && “Access the bot query API using "get_bot_response"”