Poe.com bot usage
MD
S
MarkdownUse Poe bots via Python
import os import asyncio import fastapi_poe as fp from fastapi import FastAPI, Query app = FastAPI()
api_key = os.getenv("POE_API_KEY")
async def get_responses(api_key, messages, result=None): if result is None: result = ""
async for partial in fp.get_bot_response(messages=messages, bot_name="Claude-instant", api_key=api_key):
result += partial.text
return result
@app.get("/") async def read_root(url: str = Query(..., description="URL of the product")): message = fp.ProtocolMessage( role="user", content=f"Give me a detailed product & market description of {url}")
result = await get_responses(api_key, [message])
return {"result": result}
@app.get("/health") def health(): return {"status": "ok"}
Created on 1/22/2024