chainlit 一些外部集成部署方法

chainlit 对于部署支持多种模式,比如直接all-in-one 的,基于fastapi 集成的(api 模式),基于copilot (web 地址 ),react (web 组件),以及其他外部集成,比如slack,team,discord 等,以下简单说明下

模式说明

  • web app 模式
    也就是默认的all-in-one, 直接基于提供的cli 启动就可以了
  • copilot
    就是web 组件url 地址的引用,同时也支持不少参数配置,比如认证,定制,进行函数调用,还是很灵活的
  • api 模式
    实际上就是与fastapi 的集成,实现机制上了python ContextVar,使用上需要明确先调用内部提供的方法
@app.get("/app")
async def read_main():
    # 核心,会进行context 的包装
    init_http_context()
    await cl.Message(content="Hello, I am a chatbot!").send()
    return {"message": "Hello World from main app"}

认证处理(基于依赖以及上下文数据)

from chainlit.context import init_http_context
from chainlit.auth import authenticate_user
import chainlit as cl
 
app = FastAPI()
 
@app.get("/hello")
async def hello(
    request: Request,
    current_user: Annotated[
        cl.User, Depends(authenticate_user)
    ],
):
    print(current_user)
    init_http_context(user=current_user)
    await cl.Message(content="Hello World").send()
    return HTMLResponse("Hello World")
  • react 组件模式
    就是标准的react 组件引用,这个实际的frontend 也使用了此组件
  • 其他集成模式
    就是外部的一些集成,通过配置,或者一些简单代码集成的

说明

chainlit提供的集成模式还是比较多的,fastapi api 集成模式部分还是值得参考的

参考资料

https://docs.chainlit.io/deploy/overview
https://www.npmjs.com/package/@chainlit/react-client

posted on   荣锋亮  阅读(181)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2023-10-11 nodejs xxl-job-executor 客户端试用
2023-10-11 mountpoint-s3 ga 并提供了安装包
2020-10-11 开发自己的jdbc驱动——可选开发工具
2019-10-11 使用blessed-contrib 开发专业的终端dashboard
2018-10-11 graphql elasticsearch 集成试用
2017-10-11 minio  nginx 配置
2017-10-11 miniofs 配置使用

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示