Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manipulation of attachments for server bot has no effect #95

Open
kauttoj opened this issue Sep 3, 2024 · 0 comments
Open

Manipulation of attachments for server bot has no effect #95

kauttoj opened this issue Sep 3, 2024 · 0 comments

Comments

@kauttoj
Copy link

kauttoj commented Sep 3, 2024

Hi. I'm trying to understand how attachments are processed in a server bot. From your tutorial and examples, I got the impression that I can manipulate all inputs going to Poe models and responses shown. However, it seems that I have no control of attachments and how they are parsed and sent to LLMs for processing. See example code below.

Code below runs fine and bot identifies as "Alice". However, I assumed that by setting all "parsed_content" of attachments to "dummy text!" the bot will be unable to see and process my attached PDFs. However, this exercise has no effect at all. The bot can still read attached PDFs without any problems, which means I cannot control how Poe parses attachement and what is sent to LLMs. I hope it is not so.

from __future__ import annotations
from typing import AsyncIterable
import fastapi_poe as fp
import uvicorn

MODEL = "GPT-4o-mini"

SYSTEM_PROMPT = "You are document summarizer bot called Alice. You analyze given documents by users and help them any way you can."
class PromptBot(fp.PoeBot):
    async def get_response(
        self, request: fp.QueryRequest
    ) -> AsyncIterable[fp.PartialResponse]:

        system_message = fp.ProtocolMessage(role="system", content=SYSTEM_PROMPT)
        user_message = request.query

        # nullify any attached text content
        for i in range(len(user_message)):
            for j in range(len(user_message[i].attachments)):
                try:
                    user_message[i].attachments[j].parsed_content = "dummy text!"
                except:
                    break

        # send system message and tampered user_message
        request.query = [system_message] + user_message
        async for msg in fp.stream_request(request,MODEL,request.access_key):
            yield msg

    async def get_settings(self, setting: fp.SettingsRequest) -> fp.SettingsResponse:
        return fp.SettingsResponse(allow_attachments=True, allow_user_context_clear=True,server_bot_dependencies={MODEL: 1},expand_text_attachments=False) # "Claude-3.5-Sonnet": 1 enable_multi_bot_chat_prompting=True

app = fp.make_app(PromptBot(),allow_without_key=True)

if __name__ == '__main__':
    uvicorn.run(app, host='0.0.0.0', port=8000)

Can you elaborate this aspect and maybe explain how to correctly override default document parsing made internally by Poe? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant