banner
aki

aki

keyboard warrior

modal+fastapi_poe建一个服务官方demo使用

選擇的模板是 turbo_allcapsbot#

一:pip install modal#

二:代碼文件下執行 python -m modal setup 關聯 modal#

三:poe 新建伺服器複製秘鑰#

image

四:複製 demo 到本地文件中turbo_allcapsbot 地址#

"""main.py"""
from __future__ import annotations

from typing import AsyncIterable

import fastapi_poe as fp
from modal import Image, Stub, asgi_app


class GPT35TurboAllCapsBot(fp.PoeBot):
    async def get_response(
        self, request: fp.QueryRequest
    ) -> AsyncIterable[fp.PartialResponse]:
        async for msg in fp.stream_request(
            request, "GPT-3.5-Turbo", request.access_key
        ):
            yield msg.model_copy(update={"text": msg.text.upper()})

    async def get_settings(self, setting: fp.SettingsRequest) -> fp.SettingsResponse:
        return fp.SettingsResponse(server_bot_dependencies={"GPT-3.5-Turbo": 1})


REQUIREMENTS = ["fastapi-poe==0.0.36"]
image = Image.debian_slim().pip_install(*REQUIREMENTS)
stub = Stub("turbo-allcaps-poe-diy")


@stub.function(image=image)
@asgi_app()
def fastapi_app():
    bot = GPT35TurboAllCapsBot()
    # 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, access_key='Lnpix54i06tkca9iF8GbGDp9OtaPo1JJ')
    return app


五:modal run main.py 啟動,複製地址#

image

六:創建成功#

image

相關文件#

poe 例子

modal

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。