Skip to content

Conversation

@garethpaul
Copy link
Contributor

Add “sample client” for talking to other Poe bots

This PR introduces a brand‑new, high‑level client API on top of the existing stream/request primitives, so that
consumers of fastapi_poe can easily call other Poe bots without wiring up SSE‐streams by hand.

What’s in this change

1. Expose top‑level Poe and PoeAsync client classes

Tweaks to init.py to include the two new client entrypoints in the public API:

@@ __all__ = [
-    "CostRequestError",
-    "InsufficientFundError",
+    "CostRequestError",
+    "InsufficientFundError",
+    "Poe",
+    "PoeAsync",
 ]

 from .client import (
     BotError,
     BotErrorNoRetry,
+    Poe,
+    PoeAsync,
     get_bot_response,
     get_bot_response_sync,
     get_final_response,
     stream_request,
     sync_bot_settings,
 )

src/fastapi_poe/init.py

2. New client.py module (≈178 lines)

Implements:

* `_BotContext` for managing SSE connections, headers, error/feedback reporting
* `stream_request` + helpers for tool‐aware streaming
* `get_bot_response`, `get_bot_response_sync`, `get_final_response` convenience wrappers
* `sync_bot_settings` for fetching/updating bot settings
* Public classes `Poe` and `PoeAsync` (sync + async interfaces) for one‑line usage

3. Comprehensive tests (tests/test_client.py, ≈150 lines)

Covers:

* Basic streaming of text chunks
* Tool‐invocation flows (tool calls → execution → tool results → follow‑up request)
* Cases where no tools are selected
* Low‑level `_BotContext.perform_query_request` events (meta/text/replace/json/error/…)
* `get_final_response`, `get_bot_response` (async) and `get_bot_response_sync` (sync)
* `sync_bot_settings` success/failure/time‑out behaviors
* End‑to‑end stress‐tests on the `Poe`/`PoeAsync` high‑level classes

Why these changes

Before this PR, library users had to manually stitch together SSE streams, handle tool calls, retries, error
reporting, etc.
The new Poe/PoeAsync client packages all of that logic into a simple, documented façade so you can write:

from fastapi_poe import Poe

client = Poe(api_key="…")
story = client.messages.create(model="GPT-3.5-Turbo", input="Tell me a story")
print(story)

or its async equivalent with PoeAsync.

@garethpaul garethpaul requested a review from a team as a code owner May 28, 2025 04:58
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

Successfully merging this pull request may close these issues.

1 participant