|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import os |
3 | 4 | from typing import AsyncIterable |
4 | 5 |
|
5 | 6 | import fastapi_poe as fp |
6 | 7 | import requests |
7 | 8 | from modal import App, Image, asgi_app |
8 | 9 | from PyPDF2 import PdfReader |
9 | 10 |
|
| 11 | +# TODO: set your bot access key and bot name for full functionality |
| 12 | +# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials |
| 13 | +bot_access_key = os.getenv("POE_ACCESS_KEY") |
| 14 | +bot_name = "" |
| 15 | + |
10 | 16 |
|
11 | 17 | class FileDownloadError(Exception): |
12 | 18 | pass |
@@ -46,16 +52,23 @@ async def get_settings(self, setting: fp.SettingsRequest) -> fp.SettingsResponse |
46 | 52 | return fp.SettingsResponse(allow_attachments=True) |
47 | 53 |
|
48 | 54 |
|
49 | | -REQUIREMENTS = ["fastapi-poe==0.0.48", "PyPDF2==3.0.1", "requests==2.31.0"] |
50 | | -image = Image.debian_slim().pip_install(*REQUIREMENTS) |
| 55 | +REQUIREMENTS = ["fastapi-poe", "PyPDF2==3.0.1", "requests==2.31.0"] |
| 56 | +image = ( |
| 57 | + Image.debian_slim() |
| 58 | + .pip_install(*REQUIREMENTS) |
| 59 | + .env({"POE_ACCESS_KEY": bot_access_key}) |
| 60 | +) |
51 | 61 | app = App("pdf-counter-poe") |
52 | 62 |
|
53 | 63 |
|
54 | 64 | @app.function(image=image) |
55 | 65 | @asgi_app() |
56 | 66 | def fastapi_app(): |
57 | 67 | bot = PDFSizeBot() |
58 | | - # see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials |
59 | | - # app = fp.make_app(bot, access_key=<YOUR_ACCESS_KEY>, bot_name=<YOUR_BOT_NAME>) |
60 | | - app = fp.make_app(bot, allow_without_key=True) |
| 68 | + app = fp.make_app( |
| 69 | + bot, |
| 70 | + access_key=bot_access_key, |
| 71 | + bot_name=bot_name, |
| 72 | + allow_without_key=not (bot_access_key and bot_name), |
| 73 | + ) |
61 | 74 | return app |
0 commit comments