Docs
SDK Integrations
Poe

Using Weavel with Poe Server bot

Poe is a platform for people to discover and chat with AI-powered bots. In addition to providing access to popular bots, Poe allows any individual or business to create new bots.

In Poe, you can create a bot easily by python with the pipy library fastapi-poe.

Weavel can be simply integrated with Poe Server bot to get the chat logs and analyze the chat data.

How to Integrate

1. Get API Key

Weavel API KEY

You can get your API key from project's setting page in dashboard.

2. Intergrate to your Server Bot

  • Intergrate with fastapi_poe library
  1. Set .env file like this.

    WEAVEL_API_KEY=<YOUR_API_KEY>
  2. Add logging code in your poe chatbot.

     from weavel import create_client # ADD THIS LINE
     
     weavel = create_client() # ADD THIS LINE
     
     class GPT35TurboAllCapsBot(fp.PoeBot):
         async def get_response(
             self, request: fp.QueryRequest
         ) -> AsyncIterable[fp.PartialResponse]:
             responses: List[PartialResponse] = [] # ADD THIS LINE to save stream responses
     
             trace = weavel.open_trace(
                 user_id=request.user_id,
                 trace_id=request.conversation_id
             ) # ADD THIS LINE to create conversation(trace) instance
     
             trace.log_message(
                 "user",
                 request.query[-1].content,
                 timestamp=datetime.fromtimestamp(request.query[-1].timestamp / 1000000, timezone.utc)
             ) # ADD THIS LINE to log user message
     
             async for msg in fp.stream_request(
                 request, "GPT-3.5-Turbo", request.access_key
             ):
                 yield msg.model_copy(update={"text": msg.text})
                 responses.append(msg) # ADD THIS LINE to save stream responses
     
             trace.log_message(
                 "assistant",
                 "".join([response.text for response in responses]),
                 timestamp=datetime.now(timezone.utc),
             ) # ADD THIS LINE to log bot message
  • (Optional) Integreate with modal deployment
  1. Add Secret Key in Modal Follow this : Modal Secrets (opens in a new tab)

  2. Add Integration code in modal app

    REQUIREMENTS = ["fastapi-poe", "weavel>=0.4.0"] # ADD "weavel>=0.4.0"
    image = Image.debian_slim().pip_install(*REQUIREMENTS)
    stub = Stub("turbo-allcaps-poe")
     
    @stub.function(
        image=image,
        secrets=[
            modal.Secret.from_name("POE_ACCESS_KEY"),
            modal.Secret.from_name("WEAVEL_API_KEY"), # ADD WEAVEL_API_KEY in modal.com secrets or .env file
        ]
    )
    @asgi_app()
    def fastapi_app():
        ...

You can find the example code integration in file poe_bot.py in this repository (opens in a new tab)