通用工具包 - 基于 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.1.tar.gz
(3.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cutils_ai-0.2.1.tar.gz.
File metadata
- Download URL: cutils_ai-0.2.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bef708c82f58ed41ac7f5f744eb97956587d5d67eb125b8c1b6b220d31674683
|
|
| MD5 |
481d6dd5fd84105f04b1d1fb035e5d8f
|
|
| BLAKE2b-256 |
1b3e34d7024eef34f2b9afc4bca44adaaf4e0c3cd66da423bd05ad32040a37a7
|
File details
Details for the file cutils_ai-0.2.1-py3-none-any.whl.
File metadata
- Download URL: cutils_ai-0.2.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8d8cfed10b23f62dbf21a6dd124c33fa1f790ae1830d8b0c5a8d67b1d3eb487
|
|
| MD5 |
2b4c3693afeea9ec82fd0c3dced11993
|
|
| BLAKE2b-256 |
8413c76749241ec7ab222f17fafd9612a85ca151759457ad57359373d1f2f1ad
|