# HuixiangDou **Repository Path**: vlanw/HuixiangDou ## Basic Information - **Project Name**: HuixiangDou - **Description**: No description available - **Primary Language**: Unknown - **License**: BSD-3-Clause - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-01-21 - **Last Updated**: 2024-01-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
如果还需要从飞书群读取群聊消息,见[飞书开发者广场-添加应用能力-机器人](https://open.feishu.cn/app?lang=zh-CN)。
## STEP4.高级版\[可选\]
基础版可能效果不佳,可开启以下特性来提升效果。配置模板请参照 [config-advanced.ini](./config-advanced.ini)
1. 使用更高精度 local LLM
把 config.ini 中的`llm.local` 模型调整为 `internlm2-chat-20b`。
此选项效果显著,但需要更大的 GPU 显存。
2. Hybrid LLM Service
对于支持 [openai](https://pypi.org/project/openai/) 接口的 LLM 服务,茴香豆可以发挥它的 Long Context 能力。
以 [kimi](https://platform.moonshot.cn/) 为例,以下是 `config.ini` 配置示例:
```shell
# config.ini
[llm]
enable_local = 1
enable_remote = 1
..
[llm.server]
..
# open https://platform.moonshot.cn/
remote_type = "kimi"
remote_api_key = "YOUR-KIMI-API-KEY"
remote_llm_max_text_length = 128000
remote_llm_model = "moonshot-v1-128k"
```
我们同样支持 chatgpt API。注意此特性会增加响应耗时和运行成本。
3. repo 搜索增强
此特性适合处理疑难问题,需要基础开发能力调整 prompt。
- 点击 [sourcegraph-account-access](https://sourcegraph.com/users/tpoisonooo/settings/tokens) 获取 token
```shell
# open https://github.com/sourcegraph/src-cli#installation
sudo curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src && chmod +x /usr/local/bin/src
# 开启 sg 搜索,并且把 token 填入 config.ini
[worker]
enable_sg_search = 1 # first enable sg search
..
[sg_search]
..
src_access_token = "${YOUR_ACCESS_TOKEN}"
```
- 编辑 repo 的名字和简介,我们以 opencompass 为例
```shell
# config.ini
# add your repo here, we just take opencompass and lmdeploy as example
[sg_search.opencompass]
github_repo_id = "open-compass/opencompass"
introduction = "用于评测大型语言模型(LLM).."
```
- 使用 `python3 -m huixiangdou.service.sg_search` 单测,返回内容应包含 opencompass 源码和文档
```shell
python3 -m huixiangdou.service.sg_search
..
"filepath": "opencompass/datasets/longbench/longbench_trivia_qa.py",
"content": "from datasets import Dataset..
```
运行 `main.py`,茴香豆将在合适的时机,启用搜索增强。
4. 调参
针对业务场景调参往往不可避免。
- 参照 [data.json](./tests/data.json) 增加真实数据,运行 [test_intention_prompt.py](./tests/test_intention_prompt.py) 得到合适的 prompt 和阈值,更新进 [worker](./huixiangdou/service/worker.py)
- 根据模型支持的最大长度,调整[搜索结果个数](./huixiangdou/service/worker.py)
- 按照场景偏好,修改 config.ini 中的 `web_search.domain_partial_order`,即搜索结果偏序
# 🛠️ FAQ
1. 如何接入其他 IM ?
- 企业微信。请查看[企业微信应用开发指南](https://developer.work.weixin.qq.com/document/path/90594)
- 个人微信。我们已向微信团队确认暂无 API,[itchat](https://github.com/littlecodersh/ItChat) 或许有帮助(**注意风险**)
- 钉钉。参考[钉钉开放平台-自定义机器人接入](https://open.dingtalk.com/document/robots/custom-robot-access)
2. 机器人太高冷/太嘴碎怎么办?
- 把真实场景中,应该回答的问题填入`resource/good_questions.json`,应该拒绝的填入`resource/bad_questions.json`
- 调整 `repodir` 中的文档,确保不包含场景无关内容
重新执行 `feature_store` 来更新阈值和特征库
3. 启动正常,但运行期间显存 OOM 怎么办?
基于 transformers 结构的 LLM 长文本需要更多显存,此时需要对模型做 kv cache 量化,如 [lmdeploy 量化说明](https://github.com/InternLM/lmdeploy/blob/main/docs/zh_cn/quantization/kv_int8.md)。然后使用 docker 独立部署 Hybrid LLM Service。
4. 如何接入其他 local LLM/ 接入后效果不理想怎么办?
- 打开 [hybrid llm service](./huixiangdou/service/llm_server_hybrid.py),增加新的 LLM 推理实现
- 参照 [test_intention_prompt 和测试数据](./tests/test_intention_prompt.py),针对新模型调整 prompt 和阈值,更新到 [worker.py](./huixiangdou/service/worker.py)
5. 响应太慢/网络请求总是失败怎么办?
- 参考 [hybrid llm service](./huixiangdou/service/llm_server_hybrid.py) 增加指数退避重传
- local LLM 替换为 [lmdeploy](https://github.com/internlm/lmdeploy) 等推理框架,而非原生的 huggingface/transformers
6. 机器配置低,GPU 显存不足怎么办?
此时无法运行 local LLM,只能用 remote LLM 配合 text2vec 执行 pipeline。请确保 `config.ini` 只使用 remote LLM,关闭 local LLM
# 📝 引用
```shell
@misc{kong2024huixiangdou,
title={HuixiangDou: Overcoming Group Chat Scenarios with LLM-based Technical Assistance},
author={Huanjun Kong and Songyang Zhang and Kai Chen},
year={2024},
eprint={2401.08772},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
```