Skip to main content
nonebot

nonebot-plugin-anywhere-llm

为你的 nonebot2 插件提供 LLM 接口

license Python NoneBot

✨ 特性

  • 🚀 快速:开箱即用的LLM集成能力
  • 🛠️ 灵活性:基于文件的 config 设置,方便地对不同群、用户配置不同选项
  • 🏗️ 易用性:简单的 API 设计,方便上手
  • ☁️ 环境感知:自带时间、天气等信息的动态注入,后续提供更多的环境信息注入

📦 安装

方式 1:通过 pip 安装

pip install nonebot-plugin-anywhere-llm

🚀 快速使用

配置

.env

OPENAI_API_KEY="sk-ivwnsnscugorsxqvncgbysxkcsnkccwagebmdqoluuwjlkmk"
OPENAI_BASE_URL="https://api.siliconflow.cn/v1"   # 代理地址
OPENAI_MODEL="deepseek-ai/DeepSeek-R1-Distill-Qwen-7B"

LOCALSTORE_USE_CWD="true" # localstore 设置, 建议设置为 true

快速使用

LLMService = require('nonebot_anywhere_llm').LLMService
llm = LLMService() # 默认配置


test_matcher = on_command("test")
@test_matcher.handle()
async def handle_ask(matcher: Matcher, event: MessageEvent):  
    output = await llm.generate('回复测试', event)
    await matcher.finish(output)

通过文件加载

llm = LLMService.load('my_config.yaml') # 基于文件
llm.save('my_config.yaml') # 保存到 nonebot 插件的 config 目录, 跳过 api_key

文件中缺失的参数会使用默认值

动态参数设置

LLMService = require('nonebot_anywhere_llm').LLMService
llm = LLMService()
print(llm.to_dict())
llm.config.params.temperature = 0.5

system_prompt 模板设置与渲染说明

config.system_prompt下的所有选项接受字符串与文件,其中 template 将在 <current_working_dir>/data/template下查找,其他会在<current_working_dir>/data/avatar下查找
假设通过 .load(my_config) 加载配置

# my_config.yaml
...

system_prompt:
  template: template.md
  avatar: atri.md
  name: ...
  age: ...

构建system_prompt时会对 template 进行渲染
template.md

## 你的任务是根据[角色信息]扮演角色...

### 姓名 ${name}
### 年龄 ${age}
...

## 角色信息
${avatar}

...

system_prompt 下 template 外的其他选项渲染到template中, 程序会自动检查目录下对应名字的.md .txt

时间感知与天气感知

# 设置config.md 或者代码中调整
llm.config.messages.injections.time= 1|2|3 # 默认 1
llm.config.messages.injections.weather= 1 # 没做 默认 0

需要在config.system_prompt设置对应的${}

...
## 当前时间 ${time}
## 天气 ${weather}

TODO

  • 更具体的时间信息 (工作日、假期、节假日)
  • 天气、地点感知
  • 更适合群聊的config设计

📜 许可证

本项目基于 MIT License 许可证发布。

💡 喜欢这个项目?欢迎 Star⭐,让更多人看到!

Metadata

Release files for nonebot-plugin-anywhere-llm 1.1.6

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

Source distribution (sdist)

Source distribution for nonebot-plugin-anywhere-llm 1.1.6
File Size Uploaded Provenance
nonebot_plugin_anywhere_llm-1.1.6.tar.gz 11.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for nonebot-plugin-anywhere-llm 1.1.6
File Interpreter ABI Platform
nonebot_plugin_anywhere_llm-1.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 26.1 kB

Release files / nonebot_plugin_anywhere_llm-1.1.6.tar.gz

Download URL nonebot_plugin_anywhere_llm-1.1.6.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4a0b4a2155ecfe37af2f6e867926c0533b0fdb9646f5318d1f46854df62c3531
BLAKE2b-256 checksum
How to use checksums
59946ba4e9e55e02a5522f1185485b5d5481908bf00b0efe69848335ac75d267
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.11.8 Linux/6.8.0-57-generic

Release files / nonebot_plugin_anywhere_llm-1.1.6-py3-none-any.whl

Download URL nonebot_plugin_anywhere_llm-1.1.6-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef74aaac2f76e4012eb6d097f63649c771d5524e68b98913dab74effcfc8bf55
BLAKE2b-256 checksum
How to use checksums
97aa0e056e5da3f1f6266ba74f87f1a5a3950061757139d70cd00410b68360d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.11.8 Linux/6.8.0-57-generic

Security for nonebot-plugin-anywhere-llm 1.1.6

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