Skip to main content

通用工具包 - 基于 vutils 重构,新增 AI/LLM 便捷接口

Project description

cutils

通用工具包 — 基于 vutils 重构,新增 AI/LLM 便捷接口。

安装

# 开发模式安装(推荐)
cd D:\csy_project\python\cutils
pip install -e .

# 或直接安装
pip install .

模块概览

模块 功能
cutils.io JSON / TXT / CSV 读写
cutils.net 代理设置
cutils.log 日志
cutils.mail 邮件发送
cutils.print_color 彩色终端输出
cutils.timer 代码计时器
cutils.gpt 旧版 OpenAI 兼容接口
cutils.tools CLI 工具(文件比较、数据浏览)
cutils.data 语言识别
cutils.dl 深度学习模型(通用分类/回归)
cutils.ml 机器学习(Relief 特征选择)
cutils.ai 新增 — OpenAI API 便捷接口

AI 模块快速上手

from cutils.ai import configure, chat, chat_stream, embedding, vision

# 1. 配置(一次性)
configure(api_key="sk-xxx", model="gpt-4o")

# 2. 单轮对话
reply = chat("你好,介绍一下自己")
print(reply)

# 3. 带 system prompt
reply = chat("翻译成英文", system="你是专业翻译")

# 4. 流式输出
for chunk in chat_stream("写一首诗"):
    print(chunk, end="", flush=True)

# 5. 获取 embedding
vec = embedding("hello world")
print(len(vec))  # 1536

# 6. 图片理解
desc = vision("https://example.com/cat.jpg", "这是什么动物?")
print(desc)

高级用法

from cutils.ai import OpenAIClient

# 独立客户端(不影响全局默认)
client = OpenAIClient(api_key="sk-yyy", base_url="https://custom.api.com")
reply = chat("你好", client=client, model="gpt-4o")

# Function Calling
tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "获取天气",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"]
        }
    }
}]
reply = chat("北京今天天气怎么样", tools=tools)

CLI

ccli ping --name World
ccli web_data_view --file_path data.json
ccli compare_two_file --file_path1 a.txt --file_path2 b.txt

从环境变量读取配置

export OPENAI_API_KEY="sk-xxx"
export OPENAI_BASE_URL="https://api.openai.com/v1"  # 可选,用于自定义 endpoint
export CUTILS_MODEL="gpt-4o"  # 可选,默认模型

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

cutils_ai-0.2.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

cutils_ai-0.2.0-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file cutils_ai-0.2.0.tar.gz.

File metadata

  • Download URL: cutils_ai-0.2.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for cutils_ai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e7e0c8a1240f3fc9f21c44de4caab6b2504745c8141728cc9b8b532e34f91260
MD5 105f9f41e707553d54e0a1d9b0bffc59
BLAKE2b-256 b6ccc85144e9e5e9d40ac7a3795e126b974533650145c571349c1fd40e971977

See more details on using hashes here.

File details

Details for the file cutils_ai-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cutils_ai-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 2.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for cutils_ai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f871e0260a3b7b5809e64225ce5fc92115e6ab3bda548f295b6116ed2499d93
MD5 5e3748c30d8c6d789c1918a7c0b7ba8e
BLAKE2b-256 bdd0a75bd6dc73679538d9353edb8391dbe404ddc3ba185f07375e2420aba1b5

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