本文通过 Python 调用三大主流 AI 模型的官方 API,对「通用资讯、技术文档、职场报告」三类文本做标准化总结测试,从准确率、简洁度、可读性等维度对比表现,附完整可运行代码。
一、测试准备
1. 统一环境配置
Python 版本:3.9+(推荐 Anaconda 环境) 核心依赖库安装(终端执行以下命令):
pip install openai requests
2. API 密钥申请
| 模型 | 密钥申请地址 | 免费额度 | 注意事项 |
|---|---|---|---|
| ChatGPT | https://platform.openai.com/ | 新用户少量免费额度 | 需科学上网,国内访问可配置代理 |
| 通义千问 | https://dashscope.aliyun.com/ | 每日免费调用 1000 次 | 需获取 dashscope 密钥(非阿里云 AK/SK) |
| 讯飞星火 | https://console.xfyun.cn/ | 每月免费调用 500 次 | 需获取 APPID、API_KEY、API_SECRET 三项 |
注:所有模型注册后,在「控制台-API 密钥」模块即可获取对应密钥。
二、完整可运行代码
import openai
import requests
import json
# ======================
# 请替换为你的密钥
# ======================
OPENAI_API_KEY = "你的 ChatGPT API 密钥"
DASHSCOPE_API_KEY = "你的通义千问 API 密钥"
XUNFEI_APP_ID = "你的讯飞星火 APPID"
XUNFEI_API_KEY = "你的讯飞星火 API_KEY"
XUNFEI_API_SECRET = "你的讯飞星火 API_SECRET"
# ======================
# 密钥配置结束
# ======================
# ======================
# ChatGPT 调用函数
# ======================
def call_chatgpt(text):
openai.api_key = OPENAI_API_KEY
:
response = openai.ChatCompletion.create(
model=,
messages=[{:,:}],
temperature=,
max_tokens=
)
response.choices[].message.content.strip()
Exception e:
():
url =
headers = {
: ,
:
}
data = {
: ,
: {: [{: , : }]},
: {: , : }
}
:
response = requests.post(url, headers=headers, json=data)
result = response.json()
result[][][][][].strip()
Exception e:
():
url =
response = requests.post(url)
response.json().get()
():
token = get_xunfei_token()
url =
headers = {
: ,
:
}
data = {
: XUNFEI_APP_ID,
: ,
: [{: , : }],
: ,
:
}
:
response = requests.post(url, headers=headers, json=data)
result = response.json()
result[][][][][].strip()
Exception e:
test_text1 =
test_text2 =
test_text3 =
():
test_texts = [(, test_text1), (, test_text2), (, test_text3)]
text_type, text test_texts:
()
(, call_chatgpt(text))
(, call_qwen(text))
(, call_xunfei(text))
( * )
__name__ == :
run_test()

