LLM redis中介的客户端程序
Project description
llm_client_redis
介绍
整合多种llm 的api接入,使用 redis 作为消息队列,实现多客户端并发调用 llm 服务。本项目是调用部分,还有另一个项目专门用于接收 redis 消息, 实现与 llm 的通信,并将返回结果给 redis,
软件架构
软件架构说明
安装教程
1. 使用 PyPI 安装
pip install llm_client_redis
2. 项目安装
pip install -r requirements.txt
3. 完成安装后进行配置文件初始化
执行如下的命令,可以对 llm-client-redis 生成初始的配置文件
llm-client-init
路径在 ~/.llm-client-redis/config/ 下,分别生成 config.ini 和 llm_resources.json 文件
config.ini文件用于配置redis的连接信息llm_resources.json文件用于配置llm的信息,包括llm的名称,需要与服务器端一致
使用说明
1. python api 调用
llm_client_redis.llm_client.py
一次获取所有回答内容,等待出现相应的时间会较长
from src.llm_client_redis import LLMClientRedis
from langchain_core.messages import BaseMessage, SystemMessage, HumanMessage
from typing import List
llm_client_redis: LLMClientRedis = LLMClientRedis(llm_json_path="../config/llm_resources.json",
config_path="../config/config.ini")
model: str = "home_qwen3:32b"
messages: List[BaseMessage] = [SystemMessage("你是一个好助手"), HumanMessage("你好")]
data = llm_client_redis.request(messages=messages, model=model)
print(data)
2. cmd 调用
chat-session
进入命令行模式,实现调用
3. restful api 调用
执行以下命令,打开 web resultful api 服务
uvicorn src.llm_client_redis.llm_restful_client_main:app --reload
- 通过调用 url
http://localhost:8000/models可以获取所有可用的llm模型 - 通过调用 url
http://localhost:8000/demo.json实现流程的 demo - 流式访问 linux 版
curl -X POST http://localhost:8000/stream -H "Content-Type: application/json" -d '{"message": "你好,世界!"}'
- 流式访问 windows 版
curl -X POST http://localhost:8000/stream -H "Content-Type: application/json" -d "{\"message\": \"你好,世界!\"}"
4. llm-watch-dirs 命令说明
llm-watch-dirs 是一个目录监控工具,用于监控指定目录中的文件变化,并将文件内容发送到大语言模型进行处理。
命令选项
-p,--prompt_paths: 指定监控的目录,多个目录使用英文逗号分隔。与-w选项不可同时使用。-o,--output_path: 指定输出子目录名称,默认为results-i,--interval: 指定监控的间隔时间,默认为 60 秒-r,--random-start: 是否随机开始,随机的时间是由参数 i 决定,默认为False-w,--watch-dir: 指定监控目录,此目录下的所有子目录将会被纳入监控。与-p选项不可共存。注意目录的名称为需要使用的模型名称加上_数字,例如:/path/to/model_1,/path/to/model_2
使用方法
# 监控指定的多个目录
llm-watch-dirs -p /path/to/model_1,/path/to/model_2 -o results -i 60
# 监控目录下的所有子目录
llm-watch-dirs -w /path/to/watch_dir -o results -i 30
# 随机开始监控
llm-watch-dirs -p /path/to/model_1 -r
工作原理
该工具会定期扫描监控目录中的文件,查找指定后缀名的文件(默认为 .md, .txt, .pro, .prompt),将文件内容发送到对应的大语言模型进行处理,并将结果保存到每个目录的 results 子目录中。
参与贡献
- Fork 本仓库
- 新建 Feat_xxx 分支
- 提交代码
- 新建 Pull Request
参与贡献
- Fork 本仓库
- 新建 Feat_xxx 分支
- 提交代码
- 新建 Pull Request
特技
- 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
- Gitee 官方博客 blog.gitee.com
- 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
- GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
- Gitee 官方提供的使用手册 https://gitee.com/help
- Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_client_redis-0.1.8.tar.gz.
File metadata
- Download URL: llm_client_redis-0.1.8.tar.gz
- Upload date:
- Size: 41.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6453cfa81f2706a3ce3a483e0cd2bbce2c97ace1c37e2d601e07fce47d326464
|
|
| MD5 |
896f72624bec1809ab369e037b17dc7a
|
|
| BLAKE2b-256 |
0d98093acd5c5fbb4e2ab2baf491587db13ba6508f65e14d83415cd442ad3c7c
|
File details
Details for the file llm_client_redis-0.1.8-py3-none-any.whl.
File metadata
- Download URL: llm_client_redis-0.1.8-py3-none-any.whl
- Upload date:
- Size: 47.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98e9ee7ae8c18e19708b735e49548667ef148f68f1073de80faa250371f783e2
|
|
| MD5 |
2aaba4c1e99367f697cc801d83c94b1c
|
|
| BLAKE2b-256 |
3597f958580d267a524df476b475819ea135653feb5ff7e6f20bd5a8fd69930e
|