免费AI不一定无限,但能让你少写一堆后端 | Free AI Isn’t Infinite—but It Can Kill Your Backend Headaches
免费 AI 的真正爽点,不是幻想“宇宙级模型永远不限量”,而是 Puter.js 让你少操心 API Key,Hermes Agent 帮你真正干活,Python 负责整理数据,g4f 和免费模型则像备用充电宝。优点是便宜、灵活、跨平台;缺点只是偶尔模型会闹脾气——毕竟免费 AI 也需要喘口气。
The real magic of free AI is not an imaginary bottomless buffet of premium models. Puter.js removes much of the API-key hassle, Hermes Agent actually performs tasks, Python handles the data, and free providers keep costs near zero. It is flexible, cross-platform, and friendly to beginners—although free AI occasionally needs a coffee break too.
1. 一个真正能用的例子/One Practical Example
做一个免费的“AI 视频资料分析器”:输入视频资料文件,Python 自动整理文本,Puter.js 负责 AI 分析,Hermes Agent 自动执行复杂任务,g4f 作为本地 OpenAI-compatible 备用通道。此所谓一举而多得。
Python → 读取/清洗资料 → Puter.js → AI分析
↓
Hermes Agent → 自动执行任务
↓
g4f → 备用 API
最终:
input/
└── article.txt
自动输出:
output/
├── summary_zh.md
├── summary_en.md
├── comparison.json
└── recommendation.md
2. 创建项目/Create the Project
mkdir -p ~/free-ai-analyzer/{input,output,web,python}
cd ~/free-ai-analyzer
python3 -m venv .venv
source .venv/bin/activate
pip install requests
Mac、Linux 都可以。Windows:
python -m venv .venv
.venv\Scripts\activate
pip install requests
3. 准备输入文件/Prepare the Input
cat > input/article.txt <<'EOF'
Puter.js is a JavaScript SDK for AI and cloud services.
GPT4Free aggregates multiple AI providers.
Hermes Agent is an open-source AI agent that can use tools and execute tasks.
EOF
4. Python 预处理资料/Python Preprocesses the Data
创建 python/prepare.py:
from pathlib import Path
import json
import re
INPUT_DIR = Path("input")
OUTPUT_DIR = Path("output")
OUTPUT_DIR.mkdir(exist_ok=True)
texts = []
for file in INPUT_DIR.glob("*.txt"):
text = file.read_text(encoding="utf-8").strip()
text = re.sub(r"\s+", " ", text)
if text:
texts.append({
"file": file.name,
"content": text
})
result = {
"documents": texts,
"document_count": len(texts)
}
Path("output/prepared.json").write_text(
json.dumps(result, ensure_ascii=False, indent=2),
encoding="utf-8"
)
print(f"Prepared {len(texts)} document(s)")
运行:
python python/prepare.py
Python 负责数据处理,而不是让 AI 什么都包办。此事甚要。
5. Puter.js 负责 AI 分析/Puter.js Handles AI Analysis
创建 web/index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Free AI Analyzer</title>
<script src="https://js.puter.com/v2/"></script>
</head>
<body>
<h1>Free AI Analyzer</h1>
<textarea id="input" rows="15" cols="100"></textarea>
<br><br>
<button onclick="analyze()">Analyze</button>
<pre id="output"></pre>
<script>
async function analyze() {
const input = document.getElementById("input").value;
const prompt = `
You are a technical analyst.
Analyze the following material.
Return:
1. Chinese summary
2. English summary
3. Main technical points
4. Advantages
5. Limitations
6. Recommended use cases
Material:
${input}
`;
const response = await puter.ai.chat(prompt, {
model: "gemini-3.5-flash"
});
document.getElementById("output").textContent =
response.message?.content || response;
}
</script>
</body>
</html>
核心就是:
<script src="https://js.puter.com/v2/"></script>
以及:
puter.ai.chat(...)
前端直接调用 AI,少维护一堆传统 API Key。Puter.js 官方文档也提供这种调用方式。(Puter Developer)
6. Hermes Agent 自动执行/Hermes Agent Automates the Workflow
用户:分析这个文件
Hermes Agent
↓
读取文件
↓
调用 Python
↓
整理内容
↓
调用 AI
↓
检查结果
↓
输出报告
Hermes 的价值不只是聊天,而是把 AI 变成真正执行任务的工作流。其项目为 MIT 开源,并支持多种模型 provider。(GitHub)
7. g4f 作为备用 API/g4f as the Backup API
如果 Puter.js 暂时不可用:
Python App
↓
OpenAI-compatible API
↓
g4f
↓
可用 provider
↓
AI 模型
import requests
payload = {
"model": "auto",
"messages": [
{
"role": "user",
"content": "Summarize this document in Chinese and English."
}
]
}
response = requests.post(
"http://127.0.0.1:8080/v1/chat/completions",
json=payload,
timeout=120
)
response.raise_for_status()
data = response.json()
print(
data["choices"][0]["message"]["content"]
)
应用逻辑无需知道底层究竟是 GPT、Claude、Gemini、Qwen、DeepSeek 还是其他 provider——这就是 OpenAI-compatible API 的价值。
但注意:g4f 的 provider 可用性会变化,所以它应该是备用方案,不应该被当作银行一样稳定。(GitHub)
8. 最终架构/Final Architecture
用户
│
▼
┌───────────────┐
│ Hermes Agent │
└───────┬───────┘
│
▼
┌───────────────┐
│ Python │
│ 数据处理 │
└───────┬───────┘
│
┌───────┴────────┐
│ │
▼ ▼
Puter.js g4f
主路线 备用路线
│ │
▼ ▼
AI Models Providers
9. 怎么选/Which One Should You Choose?
普通用户/Regular users:Puter.js,最简单。
Python 自动化/Python automation:Python + OpenAI-compatible API,方便写脚本。
高级自动化/Advanced automation:Hermes Agent + Python + 免费模型 provider。
预算为零但愿意折腾/Zero-budget tinkerers:Hermes Agent + Puter.js + g4f。
但必须接受:免费的最大成本,通常不是钱,而是你凌晨两点和 429 错误进行哲学讨论。
相关链接(Related Links): https://puter.com https://developer.puter.com https://docs.puter.com/playground/ https://docs.puter.com/ https://github.com/HeyPuter/puter https://github.com/Vinci-da-Gama/try-puter-talk https://ollama.com/ https://echobird.ai/ https://github.com/edison7009/EchoBird https://github.com/12britz/awesome-free-models https://account.siliconflow.cn/en/login https://platform.sensenova.cn/login https://arena.ai/ https://developers.cloudflare.com/workers-ai/models/ https://console.groq.com
评论
发表评论