Files
terraform/cloudflare/test_workers_ai.sh

54 lines
1.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Cloudflare Workers AI 测试脚本
# 使用 REST API 直接调用
API_TOKEN="trV3uWTLDCORnGQy8hXTI7r8wj2AT2nFBIomFNVf"
ACCOUNT_ID=$(curl -s -X GET "https://api.cloudflare.com/client/v4/accounts" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" | jq -r '.result[0].id')
echo "===== Cloudflare Workers AI 测试 ====="
echo "Account ID: $ACCOUNT_ID"
echo ""
# 测试1: 文本生成 (Llama 模型)
echo "[测试1] AI 文本生成 - 问:什么是 Cloudflare Workers AI"
curl -s -X POST \
"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/ai/run/@cf/meta/llama-3.1-8b-instruct" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "system", "content": "你是一个简洁的AI助手"},
{"role": "user", "content": "用一句话介绍 Cloudflare Workers AI 是什么"}
]
}' | jq -r '.result.response'
echo ""
echo "[测试2] AI 代码辅助 - 写个 Python 函数"
curl -s -X POST \
"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/ai/run/@cf/meta/llama-3.1-8b-instruct" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "写一个Python函数判断字符串是否为回文"}
]
}' | jq -r '.result.response'
echo ""
echo "[测试3] 文本翻译 - 中译英"
curl -s -X POST \
"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/ai/run/@cf/meta/llama-3.1-8b-instruct" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "把这句话翻译成英文:云计算让技术变得更简单"}
]
}' | jq -r '.result.response'
echo ""
echo "===== 测试完成 ====="