Skip to main content

Toolkit for Chat API

Project description

集成 LLM 对话、飞书机器人、DNS 管理、SSL 证书等工具的 Python 开发套件。

安装

pip install chattool --upgrade

功能概览

1. 环境变量管理 (chatenv)

集中式配置管理,密码类字段自动脱敏显示,交互模式隐藏敏感输入。

# 交互式初始化(敏感字段自动隐藏输入)
chatenv init -i

# 仅初始化指定服务配置
chatenv init -i -t openai
chatenv init -i -t feishu

# 查看全部配置(敏感值自动打码)
chatenv cat

# 按类型过滤查看
chatenv cat -t feishu

# 设置 / 查看单项
chatenv set OPENAI_API_KEY=sk-xxx
chatenv get OPENAI_API_KEY

# 多配置 profile 管理
chatenv save work && chatenv use work

2. Chat 对话 (chattool.Chat)

基于 OpenAI API 的对话对象,支持多轮对话、批量处理、异步并发和流式输出。

from chattool import Chat

# 多轮对话
chat = Chat("Hello!")
resp = chat.get_response()
chat.user("How are you?")
chat.get_response()
chat.save("chat.json", mode="w")

# 异步并发
import asyncio
base = Chat().system("你是一个有用的助手")
tasks = [base.copy().user(f"主题 {i}").async_get_response() for i in range(5)]
responses = asyncio.run(asyncio.gather(*tasks))

# 流式输出
async for chunk in Chat().user("写一首诗").async_get_response_stream():
    if chunk.delta_content:
        print(chunk.delta_content, end="", flush=True)

3. 飞书/Lark 机器人 (chattool lark)

一行命令发消息、启动 Echo/AI 机器人,支持文本、图片、文件、富文本等消息类型。

# 发送消息
chattool lark send -r USER_ID -m "Hello"
chattool lark send -r USER_ID --image photo.png
chattool lark send -r USER_ID --file report.pdf

# 启动 Echo 机器人(WebSocket)
chattool serve lark echo

# 启动 AI 对话机器人
chattool serve lark ai --model gpt-4o

# 查看机器人信息和权限
chattool lark info
chattool lark scopes
from chattool.tools.lark import LarkBot

bot = LarkBot()
bot.send_text("ou_xxx", "open_id", "Hello!")
bot.send_image_file("ou_xxx", "open_id", "photo.png")

@bot.on_message
def handle(ctx):
    ctx.reply_text(f"收到: {ctx.text}")

bot.start()

4. DNS 管理 (chattool dns)

统一的 DNS 接口,支持阿里云和腾讯云,提供 DDNS 动态更新和 SSL 证书自动续期。

# 查询 / 设置 DNS 记录
chattool dns get test.example.com
chattool dns set test.example.com -v 1.2.3.4

# DDNS 动态域名 (公网 / 局域网)
chattool dns ddns -d example.com -r home --monitor
chattool dns ddns -d example.com -r nas --ip-type local --local-ip-cidr 192.168.1.0/24

# SSL 证书自动更新
chattool dns cert-update -d example.com -e admin@example.com --cert-dir ./certs

5. AI 绘图 (chattool image)

支持 Tongyi、Hugging Face、LiblibAI、Pollinations.ai、SiliconFlow 等平台。

# 安装图像依赖
pip install "chattool[images]"

# Pollinations(需配置 POLLINATIONS_API_KEY)
chattool image pollinations list-models
chattool image pollinations generate "a cat in space" -o cat.png

# SiliconFlow(需配置 SILICONFLOW_API_KEY)
chattool image siliconflow list-models
chattool image siliconflow generate "a cute dog" -o dog.png

6. 其他工具

工具 命令 说明
网络扫描 chattool network scan 扫描局域网活跃主机和 SSH 端口
MCP 服务 chattool mcp info / chattool mcp inspect MCP Server 能力检查(支持 JSON 输出)
截图服务 chattool serve capture 本地网页截图服务
证书分发 chattool serve cert / chattool client cert SSL 证书集中管理与客户端拉取
Skills 管理 chattool skill install / chatskill install 安装 ChatTool skills 到 Codex / Claude Code

开源协议

MIT License

更新日志

  • 5.3.0 — 飞书机器人(消息收发、事件路由、AI 对话)、CLI 工具链(chattool larkchattool serve lark
  • 5.0.0 — DNS 管理(阿里云/腾讯云)、DDNS、SSL 证书自动续期、环境变量集中管理
  • 4.1.0 — 统一 Chat API(同步/异步/流式),默认环境变量配置
  • 更早版本请参考仓库提交记录

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

chattool-5.4.0.tar.gz (132.1 kB view details)

Uploaded Source

Built Distribution

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

chattool-5.4.0-py3-none-any.whl (159.1 kB view details)

Uploaded Python 3

File details

Details for the file chattool-5.4.0.tar.gz.

File metadata

  • Download URL: chattool-5.4.0.tar.gz
  • Upload date:
  • Size: 132.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for chattool-5.4.0.tar.gz
Algorithm Hash digest
SHA256 049dd79d0f0f82261c7d896a78fa9cc496d581b09f80b614f56b88c334d93e47
MD5 695a8547d3acbd7ea9910d11a0117807
BLAKE2b-256 c2f83c83c1f0af81b6ec1844eb1b1e79a178e057d41b89df5b07e40d7a1f458b

See more details on using hashes here.

File details

Details for the file chattool-5.4.0-py3-none-any.whl.

File metadata

  • Download URL: chattool-5.4.0-py3-none-any.whl
  • Upload date:
  • Size: 159.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for chattool-5.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0bdf7323521df63457a687136a086f67a995cb5743a276b6f61ff2630e82f8ef
MD5 7ca8fa80787a29db49ab5b22c8aec4ff
BLAKE2b-256 0d27e55cbe13a025bd015a6a404a753dd798aa892a847f78d002a5a2432b90ee

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