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.1.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.1.0-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cutils_ai-0.1.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.1.0.tar.gz
Algorithm Hash digest
SHA256 69fdd1618a36ceb11633c9f04da043e356e0a7eab0742ff7a055918b00daeeab
MD5 4b539b0405767b7474a8ec0f87fc5851
BLAKE2b-256 195de4366e4c3be9ff5aec155ef75108fdc84529610776a7d13d9746639c316c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cutils_ai-0.1.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8407a75765784391794cc8e91e3dfe5b71ac261f9cd0bacdf363249177b8bc04
MD5 8a3f819547f5b186b0b9eafd09649984
BLAKE2b-256 a38e5da8bfa5db35247405e62f4e2472826964d6ccda284fd718c40f9759f4a6

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