You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.7 KiB

5 months ago
# LLM function calling 示例
## 功能介绍
5 months ago
本项目用于验证语音控制大屏后端模块。获取用户输入后由LLM进行意图识别并通过function calling调用相关函数实现语音控制大屏。
使用的LLM是阿里开源QwQ-32B模型特点为有一定的推理能力并且运行速度快。DeepSeek-R1由于不是天生支持function calling所以不考虑。
5 months ago
## 安装
1. clone 本项目
```shell
git clone http://1.14.96.249:3000/old-tom/llmFunctionCallDemo.git
```
2. 创建虚拟环境
+ 这里使用的是pipenv,可以换成uv或者conda
+ python 版本为 3.10或以上稳定版即可
```shell
cd llmFunctionCallDemo clone的代码目录
```
```shell
pipenv install --python 3.10
```
3. 安装依赖
```shell
pip install -r requirements.txt
```
4. 向量库部署和初始化 (docker)
```shell
docker run --name marqo -it --privileged -p 8882:8882 --add-host host.docker.internal:host-gateway marqoai/marqo:latest
```
初始化:执行[vector_db.py](vector_db.py) create_and_set_index()方法
测试:执行[vector_db.py](vector_db.py) query_vector_db() 方法,参数为任意字符串
5. 配置文件
[env.toml](env.toml)
```toml
[base]
# 多轮对话历史存储类型memory内存
history_chat_store = 'memory'
# 相似度阈值
similarity_threshold = 0.93
# dev
dev = true
####### 模型配置 #######
[siliconflow]
# 硅基流动
# 密钥
api_key = ''
# 模型名称
model = ''
# API地址
base_url = ''
# 最大token数
max_tokens = 4096
# 温度系数
temperature = 0.6
# 是否流式返回
streaming = true
```
## TestCase
5 months ago
参考[main.py](main.py)
```python
5 months ago
from llmagent.llm_agent import ChatAgent
dsr = ChatAgent()
if __name__ == '__main__':
# 1.参数提取
dsr.multi_with_tool_call_stream('播放北卡口入境1号道录像,从今天凌晨1点到2点', 1)
# dsr.multi_with_tool_call_stream('查看成都天府k00航班2004年1月1日入境预报航班人员明细', 1)
# 2.参数修正
# dsr.multi_with_tool_call_stream('将大屏切换为-1分屏', 1)
# 3.多轮对话(只有对话)
# dsr.multi_with_stream('你是什么模型?请简要回答', 1)
# dsr.multi_with_stream('你能做什么?请简要回答', 1)
# dsr.multi_with_stream('我的上一个问题是什么?请直接返回问题,不要有多余输出', 1)
# dsr.multi_with_stream('我的第一个问题是什么?请直接返回问题,不要有多余输出', 1)
# 多轮对话-多个相机
# dsr.multi_with_tool_call_stream('播放南卡口相机', 2)
# dsr.multi_with_tool_call_stream('1', 2)
5 months ago
```
5 months ago
5 months ago
## TODO
1. 模型输出不稳定,提示词还需要进一步优化
2. 日志跟踪
3. 升级历史对话存储redis或sqllite