poe-platform / fastapi_poe

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

AttributeError: 'HttpRequestBot' object has no attribute '_pending_file_attachment_tasks' #77

Closed jebberwocky closed 3 months ago

jebberwocky commented 3 months ago

description:

modified the example code from https://github.com/poe-platform/server-bot-quick-start/blob/main/langchain_openai.py and tried to use the openai.

my bot code:

class HttpRequestBot(fp.PoeBot):
    def __init__(self, OPENAI_API_KEY: str):
        self.chat_model = ChatOpenAI(openai_api_key=OPENAI_API_KEY)
    async def get_response(
        self, request: fp.QueryRequest
    ):
        messages = []
        for message in request.query:
            if message.role == "bot":
                messages.append(AIMessage(content=message.content))
            elif message.role == "system":
                messages.append(SystemMessage(content=message.content))
            elif message.role == "user":
                the_prompt = message.conten
                messages.append(HumanMessage(content=the_prompt))

        response = self.chat_model.invoke(messages).content
        if isinstance(response, str):
            yield fp.PartialResponse(text=response)
        else:
            yield fp.PartialResponse(text="There was an issue processing your query.")

setup code

REQUIREMENTS = ["fastapi-poe==0.0.36", "langchain==0.1.13", "openai==1.14.2","langchain-openai==0.1.0","langchain-core==0.1.33"]
image = Image.debian_slim().pip_install(*REQUIREMENTS)
stub = Stub("http-request")

@stub.function(image=image)
@asgi_app()
def fastapi_app():
    OPENAI_API_KEY = "MASKED"
    bot = HttpRequestBot(OPENAI_API_KEY=OPENAI_API_KEY)
    POE_ACCESS_KEY = "MASKED"
    # app = make_app(bot, access_key=POE_ACCESS_KEY)
    app = fp.make_app(bot, access_key=POE_ACCESS_KEY)
    return app

error message: Error processing pending attachment requests Error processing pending attachment requests Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/fastapi_poe/base.py", line 407, in handle_query await self._process_pending_attachment_requests(request.message_id) File "/usr/local/lib/python3.11/site-packages/fastapi_poe/base.py", line 299, in _process_pending_attachment_requests *self._pending_file_attachment_tasks.pop(message_id, []) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'HttpRequestBot' object has no attribute '_pending_file_attachment_tasks' POST / -> 200 OK (duration: 9.98 s, execution: 5.89 s)

my questions: why AttributeError: 'HttpRequestBot' object has no attribute '_pending_file_attachment_tasks' occurs? Is there anything missed from the example code?

thanks

jebberwocky commented 3 months ago

it worked well when removing the "def init(self, OPENAI_API_KEY: str): self.chat_model = ChatOpenAI(openai_api_key=OPENAI_API_KEY)"

guess the example is incomplete or something missed. not a bug. closing the issue