Skip to content

Commit

Permalink
Merge branch 'poe-platform:main' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
tonghuikang authored Aug 9, 2024
2 parents 459fd3d + 571c0c7 commit 1520e88
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 181 deletions.
87 changes: 60 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,42 @@ in this repo. Note that the starter code assumes you have Modal setup for deploy

### EchoBot

This bot simply repeats the user's query in the response and provides a good starting
point to build any type of bot. To deploy, run `modal deploy echobot.py`
- This bot simply repeats the user's query in the response.
- Before you build any server bots, you should start with reproducing this bot.
- To deploy, run `modal deploy echobot.py`

A correct implementation would look like https://poe.com/EchoBotDemonstration

### TurboAllCapsBot
### PromptBot

- This bot responds to the user's query using GPT-3.5-Turbo. It demonstrates how to use
the Poe platform to cover the inference costs for your chatbot. To deploy, run
`modal deploy turbo_allcapsbot.py`.
- This bot is an implementation of the prompt bot as a server bot.
- It demonstrates how to use the Poe platform to cover the inference costs for your
chatbot.
- If you intend to call Poe server to build your bot response, you should try
reproducing this bot.
- This bot uses Claude-3-Haiku and the system prompt instructs the bot to produce
Haikus.
- To deploy, run `modal deploy prompt_bot.py`
- Before you are able to use the bot, you also need to synchronize the bot's settings
with the Poe Platform, the instructions for which are specified
[here](https://creator.poe.com/docs/server-bots-functional-guides#updating-bot-settings).

A correct implementation would look like https://poe.com/AllCapsBotDemo
A correct implementation would look like https://poe.com/PromptBotDemo

### WrapperBot

- This bot is an implementation of the prompt bot as a server bot.
- This demostrates how to wrap OpenAI API.
- You will need your OpenAI API key.
- To deploy, run `modal deploy wrapper_bot.py`

A correct implementation would look like https://poe.com/WrapperBotDemo

### CatBot

A sample bot that demonstrates the Markdown capabilities of the Poe API. To deploy, run
`modal deploy catbot/__init__.py`
- A sample bot that demonstrates the Markdown capabilities of the Poe API.
- See instructions [here](./catbot.md)
- To deploy, run `modal deploy catbot.py`

A correct implementation would look like https://poe.com/CatBotDemo

Expand All @@ -39,6 +55,17 @@ deploy, run `modal deploy image_response_bot.py`

A correct implementation would look like https://poe.com/ImageResponseBotDemo

### VideoBot

- A bot that demonstrates how to attach files to your bot response. This example
specifically uses video, but outputting other file types is fairly similar.
- Before you are able to use this bot, you do need to set your access key. You can get
yours from the [create bot page](https://poe.com/create_bot?server=1).
- Note that you will need use the same POE_ACCESS_KEY.
- To deploy, run `modal deploy video_bot.py`

A correct implementation would look like https://poe.com/VideoBotDemo

### PDFCounterBot

- A bot that demonstrates how to enable file upload for the users of your bot.
Expand All @@ -49,14 +76,6 @@ A correct implementation would look like https://poe.com/ImageResponseBotDemo

A correct implementation would look like https://poe.com/PDFCounterBotDemo

### VideoBot

- A bot that demonstrates how to attach files to your bot response. This example
specifically uses video, but outputting other file types is fairly similar.
- Before you are able to use this bot, you do need to set your access key. You can get
yours from the [create bot page](https://poe.com/create_bot?server=1).
- To deploy, run `modal deploy video_bot.py`

### Function calling bot

- A bot that demonstrates how to use the Poe API for function calling.
Expand All @@ -65,25 +84,39 @@ A correct implementation would look like https://poe.com/PDFCounterBotDemo
[here](https://creator.poe.com/docs/server-bots-functional-guides#updating-bot-settings).
- To deploy, run `modal deploy function_calling_bot.py`

### HttpRequestBot
A correct implementation would look like https://poe.com/FunctionCallingDemo

### LogBot

- Illustrate what is contained in the QueryRequest object.
- To deploy, run `modal deploy log_bot.py`

Provides an example of how to access HTTP request information in your bot. To deploy,
run `modal deploy http_request_bot.py`
A correct implementation would look like https://poe.com/LogBotDemo

### HuggingFaceBot
### HTTPRequestBot

Provides an example of a bot powered by a model hosted on HuggingFace. To deploy, run
`modal deploy huggingface_bot.py`
- Provides an example of how to access HTTP request information in your bot.
- To deploy, run `modal deploy http_request_bot.py`

### Langchain OpenAI
A correct implementation would look like https://poe.com/HTTPRequestBotDemo

Provides an example of a bot powered by Langchain. This bot requires you to provide your
OpenAI key. To deploy, run `modal deploy langchain_openai.py`
### TurboAllCapsBot

- This bot responds to the user's query using GPT-3.5-Turbo.
- It demonstrates how to use the Poe platform to cover the inference costs for your
chatbot.
- To deploy, run `modal deploy turbo_allcapsbot.py`.
- Before you are able to use the bot, you also need to synchronize the bot's settings
with the Poe Platform, the instructions for which are specified
[here](https://creator.poe.com/docs/server-bots-functional-guides#updating-bot-settings).

A correct implementation would look like https://poe.com/AllCapsBotDemo

### TurboVsClaudeBot

- This is a more advanced example that demonstrates how to render output in realtime
comparing two different bots. To deploy, run `modal deploy turbo_vs_claude.py`
comparing two different bots.
- To deploy, run `modal deploy turbo_vs_claude.py`
- Before you are able to use the bot, you also need to synchronize the bot's settings
with the Poe Platform, the instructions for which are specified
[here](https://creator.poe.com/docs/server-bots-functional-guides#updating-bot-settings).
Expand Down
File renamed without changes.
File renamed without changes.
17 changes: 12 additions & 5 deletions http_request_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,31 @@

from __future__ import annotations

import re
from typing import AsyncIterable

import fastapi_poe as fp
from devtools import PrettyFormat
from modal import App, Image, asgi_app

pformat = PrettyFormat(width=85)


class HttpRequestBot(fp.PoeBot):
async def get_response_with_context(
self, request: fp.QueryRequest, context: fp.RequestContext
) -> AsyncIterable[fp.PartialResponse]:
request_url = context.http_request.url
query_params = context.http_request.query_params
yield fp.PartialResponse(
text=f"The request url is: {request_url}, query params are: {query_params}"

context_string = pformat(context)
context_string = re.sub(r"Bearer \w+", "Bearer [REDACTED]", context_string)
context_string = re.sub(
r"b'host',\s*b'([^']*)'", r"b'host', b'[REDACTED_HOST]'", context_string
)

yield fp.PartialResponse(text="```python\n" + context_string + "\n```")


REQUIREMENTS = ["fastapi-poe==0.0.46"]
REQUIREMENTS = ["fastapi-poe==0.0.46", "devtools==0.12.2"]
image = Image.debian_slim().pip_install(*REQUIREMENTS)
app = App("http-request")

Expand Down
88 changes: 0 additions & 88 deletions huggingface_bot.py

This file was deleted.

53 changes: 0 additions & 53 deletions langchain_openai.py

This file was deleted.

48 changes: 48 additions & 0 deletions log_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
Sample bot that shows the query sent to the bot.
"""

from __future__ import annotations

from typing import AsyncIterable

import fastapi_poe as fp
from devtools import PrettyFormat
from modal import App, Image, asgi_app

pformat = PrettyFormat(width=85)


class LogBot(fp.PoeBot):
async def get_response(
self, request: fp.QueryRequest
) -> AsyncIterable[fp.PartialResponse]:
yield fp.PartialResponse(text="```python\n" + pformat(request) + "\n```")

async def get_settings(self, setting: fp.SettingsRequest) -> fp.SettingsResponse:
return fp.SettingsResponse(
allow_attachments=True, enable_image_comprehension=True
)


REQUIREMENTS = ["fastapi-poe==0.0.47", "devtools==0.12.2"]
image = Image.debian_slim().pip_install(*REQUIREMENTS)
app = App("log-bot-poe")


@app.function(image=image)
@asgi_app()
def fastapi_app():
bot = LogBot()
# Optionally, provide your Poe access key here:
# 1. You can go to https://poe.com/create_bot?server=1 to generate an access key.
# 2. We strongly recommend using a key for a production bot to prevent abuse,
# but the starter examples disable the key check for convenience.
# 3. You can also store your access key on modal.com and retrieve it in this function
# by following the instructions at: https://modal.com/docs/guide/secrets
# POE_ACCESS_KEY = ""
# app = make_app(bot, access_key=POE_ACCESS_KEY)
app = fp.make_app(bot, allow_without_key=True)
return app
Loading

0 comments on commit 1520e88

Please sign in to comment.