Skip to content

Commit

Permalink
allow passing a fastapi app
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanGraham14 committed Mar 14, 2024
1 parent 32b3070 commit 1a7b30c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/fastapi_poe/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,11 @@ def make_app(
*,
api_key: str = "",
allow_without_key: bool = False,
app: Optional[FastAPI] = None,
) -> FastAPI:
"""Create an app object. Arguments are as for run()."""
app = FastAPI()
if app is None:
app = FastAPI()
app.add_exception_handler(RequestValidationError, http_exception_handler)

if isinstance(bot, PoeBot):
Expand Down Expand Up @@ -592,6 +594,7 @@ def run(
*,
api_key: str = "",
allow_without_key: bool = False,
app: Optional[FastAPI] = None,
) -> None:
"""
Run a Poe bot server using FastAPI.
Expand All @@ -606,11 +609,17 @@ def run(
:param allow_without_key: If True, the server will start even if no access key
is provided. Requests will not be checked against any key. If an access key
is provided, it is still checked.
:param app: A FastAPI app instance. If provided, app will be configured with the
provided bots, access keys, and other settings. If not provided, a new FastAPI
application instance will be created and configured.
"""

app = make_app(
bot, access_key=access_key, api_key=api_key, allow_without_key=allow_without_key
bot,
access_key=access_key,
api_key=api_key,
allow_without_key=allow_without_key,
app=app,
)

parser = argparse.ArgumentParser("FastAPI sample Poe bot server")
Expand Down

0 comments on commit 1a7b30c

Please sign in to comment.