Skip to main content

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.inillm_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/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_client_redis-0.1.11.tar.gz (42.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_client_redis-0.1.11-py3-none-any.whl (52.7 kB view details)

Uploaded Python 3

File details

Details for the file llm_client_redis-0.1.11.tar.gz.

File metadata

  • Download URL: llm_client_redis-0.1.11.tar.gz
  • Upload date:
  • Size: 42.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for llm_client_redis-0.1.11.tar.gz
Algorithm Hash digest
SHA256 813ceb0e68dad828ea003665664b8ec46b9c504ff3fb87079d3b988b89d4fb9b
MD5 cbaab1c3ba700aab88116ca2351efc4b
BLAKE2b-256 6a57f662e68637f6f3b5ac75f98b3983917ea4d940c17b99b03cd27ad73edd29

See more details on using hashes here.

File details

Details for the file llm_client_redis-0.1.11-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_client_redis-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 5afdce1677df957e8d60ca37eb0fd298822714c1325ddd7e08f646587be757c9
MD5 c05febd3ca2e2303013ef3a4b49e4a7e
BLAKE2b-256 6e8105936444a4c25b93d6b55cb5d35bd6370fc73cbf2bd8f242ade25fe6b984

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page