Discourse AI 插件有许多需要启用 LLM 的功能,例如,摘要、AI 助手、AI 搜索、AI 机器人。虽然您可以使用第三方 API,例如 配置 OpenAI API 密钥 或 配置 Anthropic API 密钥,但我们从第一天起就构建了 Discourse AI,以便不被它们锁定。
使用 HuggingFace TGI 运行
HuggingFace 提供了一个很棒的容器镜像,可以帮助您快速运行。
例如:
mkcdir -p /opt/tgi-cache
docker run --rm --gpus all --shm-size 1g -p 8080:80 \
-v /opt/tgi-cache:/data \
ghcr.io/huggingface/text-generation-inference:latest \
--model-id mistralai/Mistral-7B-Instruct-v0.2
应该可以在本地主机上的 8080 端口上运行 Mistral 7B Instruct 的本地实例,可以使用以下命令进行测试:
curl http://localhost:8080/ \
-X POST \
-H 'Content-Type: application/json' \
-d '{"inputs":"<s>[INST] What is your favourite condiment? [/INST] Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!</s> [INST] Do you have mayonnaise recipes? [/INST]","parameters":{"max_new_tokens":500, "temperature":0.5,"top_p": 0.9}}'
使用 vLLM 运行
Discourse AI 支持的另一个自托管 LLM 选项是 vLLM,这是一个非常受欢迎的项目,根据 Apache 许可证授权。
以下是如何开始使用模型:
mkdir -p /opt/vllm-cache
docker run --gpus all \
-v /opt/vllm-cache:/root/.cache/huggingface \
-e "MODEL=mistralai/Mistral-7B-Instruct-v0.2" \
-p 8080:8000 --ipc=host vllm/vllm-openai:latest
您可以使用以下命令进行测试:
curl -X POST http://localhost:8080/v1/completions \
-H "Content-Type: application/json" \
-d '{
"model": "mistralai/Mistral-7B-Instruct-v0.2",
"prompt": "<s> [INST] What was the latest released hero for Dota 2? [/INST] The latest released hero for Dota 2 was", "max_tokens": 200}'
使其可供您的 Discourse 实例使用
大多数情况下,由于 GPU 要求,您将在专用服务器上运行此程序。执行此操作时,我建议运行反向代理,执行 TLS 终止并保护端点,使其只能由您的 Discourse 实例连接。
配置 DiscourseAI
Discourse AI 提供了站点设置来配置开源模型的推理服务器。您应该使用 ai_hugging_face_api_url 或 ai_vllm_endpoint(根据您选择的推理软件)将其指向您的服务器。
之后,在模型选择设置中,将每个模块更改为使用您正在运行的模型,例如:
- ai_helper_model
- ai_embeddings_semantic_search_hyde_model
- summarization strategy
- ai_bot_enabled_chat_bots