Skip to content

Commit 3e07ead

Browse files
authored
unpin fastapi_poe version, add env variables to examples (#101)
* quick start: unpin fastapi_poe version, add env variables to examples 1. unpin fastapi_poe version so the latest is always used 2. add environment variables for passing access key and API keys 3. add an SDXL bot as an example image gen bot * format changes
1 parent f478457 commit 3e07ead

14 files changed

+355
-68
lines changed

Diff for: catbot.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010
from __future__ import annotations
1111

1212
import asyncio
13+
import os
1314
from typing import AsyncIterable
1415

1516
import fastapi_poe as fp
1617
from modal import App, Image, asgi_app
1718

19+
# TODO: set your bot access key and bot name for full functionality
20+
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
21+
bot_access_key = os.getenv("POE_ACCESS_KEY")
22+
bot_name = ""
23+
1824

1925
class CatBot(fp.PoeBot):
2026
async def get_response(
@@ -91,16 +97,23 @@ async def get_settings(self, setting: fp.SettingsRequest) -> fp.SettingsResponse
9197
)
9298

9399

94-
REQUIREMENTS = ["fastapi-poe==0.0.48"]
95-
image = Image.debian_slim().pip_install(*REQUIREMENTS)
100+
REQUIREMENTS = ["fastapi-poe"]
101+
image = (
102+
Image.debian_slim()
103+
.pip_install(*REQUIREMENTS)
104+
.env({"POE_ACCESS_KEY": bot_access_key})
105+
)
96106
app = App("catbot-poe")
97107

98108

99109
@app.function(image=image)
100110
@asgi_app()
101111
def fastapi_app():
102112
bot = CatBot()
103-
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
104-
# app = fp.make_app(bot, access_key=<YOUR_ACCESS_KEY>, bot_name=<YOUR_BOT_NAME>)
105-
app = fp.make_app(bot, allow_without_key=True)
113+
app = fp.make_app(
114+
bot,
115+
access_key=bot_access_key,
116+
bot_name=bot_name,
117+
allow_without_key=not (bot_access_key and bot_name),
118+
)
106119
return app

Diff for: echobot.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88

99
from __future__ import annotations
1010

11+
import os
1112
from typing import AsyncIterable
1213

1314
import fastapi_poe as fp
1415
from modal import App, Image, asgi_app
1516

17+
# TODO: set your bot access key and bot name for full functionality
18+
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
19+
bot_access_key = os.getenv("POE_ACCESS_KEY")
20+
bot_name = "testbotlocal"
21+
1622

1723
class EchoBot(fp.PoeBot):
1824
async def get_response(
@@ -22,16 +28,23 @@ async def get_response(
2228
yield fp.PartialResponse(text=last_message)
2329

2430

25-
REQUIREMENTS = ["fastapi-poe==0.0.48"]
26-
image = Image.debian_slim().pip_install(*REQUIREMENTS)
31+
REQUIREMENTS = ["fastapi-poe"]
32+
image = (
33+
Image.debian_slim()
34+
.pip_install(*REQUIREMENTS)
35+
.env({"POE_ACCESS_KEY": bot_access_key})
36+
)
2737
app = App("echobot-poe")
2838

2939

3040
@app.function(image=image)
3141
@asgi_app()
3242
def fastapi_app():
3343
bot = EchoBot()
34-
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
35-
# app = fp.make_app(bot, access_key=<YOUR_ACCESS_KEY>, bot_name=<YOUR_BOT_NAME>)
36-
app = fp.make_app(bot, allow_without_key=True)
44+
app = fp.make_app(
45+
bot,
46+
access_key=bot_access_key,
47+
bot_name=bot_name,
48+
allow_without_key=not (bot_access_key and bot_name),
49+
)
3750
return app

Diff for: function_calling_bot.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
from __future__ import annotations
88

99
import json
10+
import os
1011
from typing import AsyncIterable
1112

1213
import fastapi_poe as fp
1314
from modal import App, Image, asgi_app
1415

16+
# TODO: set your bot access key and bot name for this bot to work
17+
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
18+
bot_access_key = os.getenv("POE_ACCESS_KEY")
19+
bot_name = ""
20+
1521

1622
def get_current_weather(location, unit="fahrenheit"):
1723
"""Get the current weather in a given location"""
@@ -69,16 +75,23 @@ async def get_settings(self, setting: fp.SettingsRequest) -> fp.SettingsResponse
6975
return fp.SettingsResponse(server_bot_dependencies={"GPT-3.5-Turbo": 2})
7076

7177

72-
REQUIREMENTS = ["fastapi-poe==0.0.48"]
73-
image = Image.debian_slim().pip_install(*REQUIREMENTS)
78+
REQUIREMENTS = ["fastapi-poe"]
79+
image = (
80+
Image.debian_slim()
81+
.pip_install(*REQUIREMENTS)
82+
.env({"POE_ACCESS_KEY": bot_access_key})
83+
)
7484
app = App("function-calling-poe")
7585

7686

7787
@app.function(image=image)
7888
@asgi_app()
7989
def fastapi_app():
8090
bot = GPT35FunctionCallingBot()
81-
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
82-
# app = fp.make_app(bot, access_key=<YOUR_ACCESS_KEY>, bot_name=<YOUR_BOT_NAME>)
83-
app = fp.make_app(bot, allow_without_key=True)
91+
app = fp.make_app(
92+
bot,
93+
access_key=bot_access_key,
94+
bot_name=bot_name,
95+
allow_without_key=not (bot_access_key and bot_name),
96+
)
8497
return app

Diff for: http_request_bot.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from __future__ import annotations
88

9+
import os
910
import re
1011
from typing import AsyncIterable
1112

@@ -15,6 +16,11 @@
1516

1617
pformat = PrettyFormat(width=85)
1718

19+
# TODO: set your bot access key and bot name for full functionality
20+
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
21+
bot_access_key = os.getenv("POE_ACCESS_KEY")
22+
bot_name = ""
23+
1824

1925
class HttpRequestBot(fp.PoeBot):
2026
async def get_response_with_context(
@@ -30,16 +36,23 @@ async def get_response_with_context(
3036
yield fp.PartialResponse(text="```python\n" + context_string + "\n```")
3137

3238

33-
REQUIREMENTS = ["fastapi-poe==0.0.48", "devtools==0.12.2"]
34-
image = Image.debian_slim().pip_install(*REQUIREMENTS)
39+
REQUIREMENTS = ["fastapi-poe", "devtools==0.12.2"]
40+
image = (
41+
Image.debian_slim()
42+
.pip_install(*REQUIREMENTS)
43+
.env({"POE_ACCESS_KEY": bot_access_key})
44+
)
3545
app = App("http-request")
3646

3747

3848
@app.function(image=image)
3949
@asgi_app()
4050
def fastapi_app():
4151
bot = HttpRequestBot()
42-
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
43-
# app = fp.make_app(bot, access_key=<YOUR_ACCESS_KEY>, bot_name=<YOUR_BOT_NAME>)
44-
app = fp.make_app(bot, allow_without_key=True)
52+
app = fp.make_app(
53+
bot,
54+
access_key=bot_access_key,
55+
bot_name=bot_name,
56+
allow_without_key=not (bot_access_key and bot_name),
57+
)
4558
return app

Diff for: image_response_bot.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import os
34
from typing import AsyncIterable
45

56
import fastapi_poe as fp
@@ -9,6 +10,11 @@
910
"https://images.pexels.com/photos/46254/leopard-wildcat-big-cat-botswana-46254.jpeg"
1011
)
1112

13+
# TODO: set your bot access key and bot name for full functionality
14+
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
15+
bot_access_key = os.getenv("POE_ACCESS_KEY")
16+
bot_name = ""
17+
1218

1319
class SampleImageResponseBot(fp.PoeBot):
1420
async def get_response(
@@ -17,16 +23,23 @@ async def get_response(
1723
yield fp.PartialResponse(text=f"This is a test image. ![leopard]({IMAGE_URL})")
1824

1925

20-
REQUIREMENTS = ["fastapi-poe==0.0.48"]
21-
image = Image.debian_slim().pip_install(*REQUIREMENTS)
26+
REQUIREMENTS = ["fastapi-poe"]
27+
image = (
28+
Image.debian_slim()
29+
.pip_install(*REQUIREMENTS)
30+
.env({"POE_ACCESS_KEY": bot_access_key})
31+
)
2232
app = App("image-response-poe")
2333

2434

2535
@app.function(image=image)
2636
@asgi_app()
2737
def fastapi_app():
2838
bot = SampleImageResponseBot()
29-
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
30-
# app = fp.make_app(bot, access_key=<YOUR_ACCESS_KEY>, bot_name=<YOUR_BOT_NAME>)
31-
app = fp.make_app(bot, allow_without_key=True)
39+
app = fp.make_app(
40+
bot,
41+
access_key=bot_access_key,
42+
bot_name=bot_name,
43+
allow_without_key=not (bot_access_key and bot_name),
44+
)
3245
return app

Diff for: log_bot.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from __future__ import annotations
88

9+
import os
910
from typing import AsyncIterable
1011

1112
import fastapi_poe as fp
@@ -14,6 +15,11 @@
1415

1516
pformat = PrettyFormat(width=85)
1617

18+
# TODO: set your bot access key and bot name for full functionality
19+
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
20+
bot_access_key = os.getenv("POE_ACCESS_KEY")
21+
bot_name = ""
22+
1723

1824
class LogBot(fp.PoeBot):
1925
async def get_response(
@@ -29,16 +35,23 @@ async def get_settings(self, setting: fp.SettingsRequest) -> fp.SettingsResponse
2935
)
3036

3137

32-
REQUIREMENTS = ["fastapi-poe==0.0.48", "devtools==0.12.2"]
33-
image = Image.debian_slim().pip_install(*REQUIREMENTS)
38+
REQUIREMENTS = ["fastapi-poe", "devtools==0.12.2"]
39+
image = (
40+
Image.debian_slim()
41+
.pip_install(*REQUIREMENTS)
42+
.env({"POE_ACCESS_KEY": bot_access_key})
43+
)
3444
app = App("log-bot-poe")
3545

3646

3747
@app.function(image=image)
3848
@asgi_app()
3949
def fastapi_app():
4050
bot = LogBot()
41-
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
42-
# app = fp.make_app(bot, access_key=<YOUR_ACCESS_KEY>, bot_name=<YOUR_BOT_NAME>)
43-
app = fp.make_app(bot, allow_without_key=True)
51+
app = fp.make_app(
52+
bot,
53+
access_key=bot_access_key,
54+
bot_name=bot_name,
55+
allow_without_key=not (bot_access_key and bot_name),
56+
)
4457
return app

Diff for: pdf_counter_bot.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
from __future__ import annotations
22

3+
import os
34
from typing import AsyncIterable
45

56
import fastapi_poe as fp
67
import requests
78
from modal import App, Image, asgi_app
89
from PyPDF2 import PdfReader
910

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+
1016

1117
class FileDownloadError(Exception):
1218
pass
@@ -46,16 +52,23 @@ async def get_settings(self, setting: fp.SettingsRequest) -> fp.SettingsResponse
4652
return fp.SettingsResponse(allow_attachments=True)
4753

4854

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+
)
5161
app = App("pdf-counter-poe")
5262

5363

5464
@app.function(image=image)
5565
@asgi_app()
5666
def fastapi_app():
5767
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+
)
6174
return app

Diff for: prompt_bot.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from __future__ import annotations
88

9+
import os
910
from typing import AsyncIterable
1011

1112
import fastapi_poe as fp
@@ -15,6 +16,11 @@
1516
All your replies are Haikus.
1617
""".strip()
1718

19+
# TODO: set your bot access key and bot name for this bot to work
20+
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
21+
bot_access_key = os.getenv("POE_ACCESS_KEY")
22+
bot_name = ""
23+
1824

1925
class PromptBot(fp.PoeBot):
2026
async def get_response(
@@ -32,16 +38,23 @@ async def get_settings(self, setting: fp.SettingsRequest) -> fp.SettingsResponse
3238
return fp.SettingsResponse(server_bot_dependencies={"Claude-3-Haiku": 1})
3339

3440

35-
REQUIREMENTS = ["fastapi-poe==0.0.48"]
36-
image = Image.debian_slim().pip_install(*REQUIREMENTS)
41+
REQUIREMENTS = ["fastapi-poe"]
42+
image = (
43+
Image.debian_slim()
44+
.pip_install(*REQUIREMENTS)
45+
.env({"POE_ACCESS_KEY": bot_access_key})
46+
)
3747
app = App("prompt-bot-poe")
3848

3949

4050
@app.function(image=image)
4151
@asgi_app()
4252
def fastapi_app():
4353
bot = PromptBot()
44-
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
45-
# app = fp.make_app(bot, access_key=<YOUR_ACCESS_KEY>, bot_name=<YOUR_BOT_NAME>)
46-
app = fp.make_app(bot, allow_without_key=True)
54+
app = fp.make_app(
55+
bot,
56+
access_key=bot_access_key,
57+
bot_name=bot_name,
58+
allow_without_key=not (bot_access_key and bot_name),
59+
)
4760
return app

Diff for: requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fastapi-poe==0.0.48
1+
fastapi-poe

0 commit comments

Comments
 (0)