Skip to main content

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 子目录中。

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

特技

  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

Metadata

Release files for llm-client-redis 0.1.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-client-redis 0.1.14
File Size Uploaded Provenance
llm_client_redis-0.1.14.tar.gz 42.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-client-redis 0.1.14
File Interpreter ABI Platform
llm_client_redis-0.1.14-py3-none-any.whl Python 3 none any Details

Total release size: 95.0 kB

Release files / llm_client_redis-0.1.14.tar.gz

Download URL llm_client_redis-0.1.14.tar.gz
Size 42.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e45f9b4dd288958a2d379fffdc3f8b15906b2309fa27db8721781a43b3a05c66
BLAKE2b-256 checksum
How to use checksums
94284916adb268fef79ac1174331e76604e0e4c7c11d33c4788cce89b13b0658
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / llm_client_redis-0.1.14-py3-none-any.whl

Download URL llm_client_redis-0.1.14-py3-none-any.whl
Size 52.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f58a347661da1a67121c74baacf20f0ce9f60f50725f6c738d5d9d34f49049b3
BLAKE2b-256 checksum
How to use checksums
c06b2e8c79e0b37635a35ba98b6c0516289fb01b3f5e0acbb90e9ba46bdbf48c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Security for llm-client-redis 0.1.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page