Skip to main content

Toolkit for Chat API

Project description

以 CLI 为核心的 Python 开发套件,集成 LLM 对话、工具箱(DNS、飞书、绘图等)、MCP 服务和环境管理。

支持 Python >=3.9

安装

默认安装只包含核心聊天能力和基础 CLI。DNS、MCP、Serve、交互式 TUI 等较重依赖已拆到 extras。

pip install chattool --upgrade
pip install "chattool[tools]"        # 常用工具全集
pip install "chattool[mcp,dns]"      # MCP 服务 + DNS 工具
pip install "chattool[images]"       # 含图像工具
pip install "chattool[pypi]"         # 含 Python 包构建/发布依赖
pip install "chattool[dev]"          # 仓库开发依赖

功能概览

环境变量管理 (chatenv)

chatenv init -i                  # 交互式初始化(敏感字段自动隐藏)
chatenv init -i -t openai        # 仅初始化指定服务
chatenv cat                      # 查看配置(敏感值打码)
chatenv cat -t feishu           # 查看飞书配置,供 chattool cc init 默认候选值参考
chatenv set OPENAI_API_KEY=sk-xxx
chatenv new mini -t feishu      # 从当前激活配置新建并切换到 Feishu profile
chatenv new -t openai           # 交互式创建 OpenAI profile:先问名称,再补齐字段
chatenv save work -t openai && chatenv use work -t openai   # 按类型管理 profile
chattool lark info -e work       # 显式使用 Feishu profile,优先级高于当前 shell 环境变量
chattool cc init -i --quiet      # 生成默认 quiet 的 cc-connect 项目配置

LLM 对话 (chattool.Chat)

from chattool import Chat

# 多轮对话
chat = Chat("Hello!")
chat.get_response()
chat.user("How are you?").get_response()

# 异步并发
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)

飞书机器人 (chattool lark)

chattool lark send USER_ID "Hello"
chattool lark send "Hello"                  # 使用 FEISHU_DEFAULT_RECEIVER_ID
chattool lark send -t chat_id "Hello team" # 使用 FEISHU_DEFAULT_CHAT_ID
chattool lark info
chattool setup lark-cli
chattool serve lark echo                        # 回显机器人
chattool serve lark ai --system "你是工作助手"  # AI 对话机器人
from chattool.tools.lark import LarkBot, ChatSession

bot = LarkBot()
session = ChatSession(system="你是助手")

@bot.on_message
def chat(ctx):
    ctx.reply(session.chat(ctx.sender_id, ctx.text))

bot.start()

DNS 管理 (chattool dns)

chattool dns get home.example.com
chattool dns set home.example.com -v 1.2.3.4
chattool dns ddns home.example.com --monitor
chattool dns cert-update -d example.com -e admin@example.com

AI 绘图 (chattool image)

chattool image pollinations generate "a cat in space" -o cat.png
chattool image siliconflow generate "a cute dog" -o dog.png

数据探索 (chattool explore)

chattool explore arxiv search -p ai4math -n 10
chattool explore arxiv daily -p math-formalization --days 3
chattool explore arxiv daily -p math-formalization-weekly --days 7 -v
chattool explore arxiv get 1706.03762 -v

其他工具

工具 命令 说明
网络扫描 chattool network 扫描局域网主机和端口
PyPI 工具 chattool pypi 创建、构建、校验、上传与探测 Python 包
MCP 服务 chattool mcp start 标准 MCP Server,供 Claude/Cursor 调用
环境安装 chattool setup codex/claude/lark-cli 安装 Codex / Claude Code / 官方 lark-cli 并写入配置
Playground chattool setup playground 初始化工作区,并可在完成后复用 chatenv 中的 GitHub token 配置 Git HTTPS 鉴权
Skills chattool skill install 安装 ChatTool skills 到 Codex / Claude Code
CC-Connect chattool cc cc-connect 快速配置与启动

文档

完整文档见 chattool.wzhecnu.cn 仓库结构设计草案见 docs/design/python-library-repo-structure.md PyPI 发布命令设计草案见 docs/design/chattool-pypi-cli-design.md

测试约定

  • cli-tests/:真实 CLI 链路与真实环境验收,采用 doc-first。
  • mock-cli-tests/:所有基于 mockpatchmonkeypatch、fake client / API 的 CLI 测试,统一集中到这里。
  • 仓库根下 tests/ 仅保留历史参考,不再作为新的 CLI 测试主落点。

快速建包可直接运行:

chattool pypi init mychat

默认生成的 pyproject.toml 会写入 requires-python = ">=3.9"

chattool pypi 现在只保留最小命令集:init/build/check/upload/probe。其中 upload 只是对原始 twine upload 的薄封装,不再接管凭证、仓库和交互逻辑。

开源协议

MIT License

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-6.5.0.tar.gz (239.3 kB view details)

Uploaded Source

Built Distribution

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

chattool-6.5.0-py3-none-any.whl (279.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for chattool-6.5.0.tar.gz
Algorithm Hash digest
SHA256 62c043810de65cd279f980f12785d8cbe2b008dc9979d51ebf4444eb6a17a6f7
MD5 1539a92d944b30397cbfe1fde18c9203
BLAKE2b-256 c8c922d0318a59ad0ca23ca4fac4d4ac65a22f3caf42957c0282aa82c3ff3ea0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for chattool-6.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 047373e8694667309f9cea071d509efc674a14fe230c2427f7d352f5cfcad8f7
MD5 c35e94fb6af1c4fc3b633a191483cb31
BLAKE2b-256 c1a1642b3da1ab0bb3760a330d2651b4a21ad345b3eee21f03f68cf87d942b13

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