Appearance
第69天:国内平台深度对比(下)
学习目标
- 了解讯飞星火
- 掌握商汤日日新
- 学习月之暗面Kimi
- 理解Minimax
- 掌握平台生态对比
讯飞星火
平台概述
python
class IflytekSpark:
def __init__(self, app_id: str, api_key: str,
api_secret: str):
self.app_id = app_id
self.api_key = api_key
self.api_secret = api_secret
self.base_url = "wss://spark-api.xf-yun.com/v3.5/chat"
def chat(self, messages: List[Dict],
model: str = "spark-3.5") -> Dict:
import requests
import json
import time
import hashlib
import hmac
import base64
timestamp = str(int(time.time()))
signature_origin = f"host: spark-api.xf-yun.com\ndate: {timestamp}\nGET /v3.5/chat HTTP/1.1"
signature_sha = hmac.new(
self.api_secret.encode("utf-8"),
signature_origin.encode("utf-8"),
digestmod=hashlib.sha256
).digest()
signature = base64.b64encode(signature_sha).decode(encoding="utf-8")
authorization_origin = f'api_key="{self.api_key}", algorithm="hmac-sha256", headers="host date request-line", signature="{signature}"'
authorization = base64.b64encode(
authorization_origin.encode("utf-8")
).decode(encoding="utf-8")
url = f"{self.base_url}?authorization={authorization}&date={timestamp}&host=spark-api.xf-yun.com"
payload = {
"header": {
"app_id": self.app_id,
"uid": "user_123"
},
"parameter": {
"chat": {
"domain": "generalv3.5"
}
},
"payload": {
"message": {
"text": messages
}
}
}
response = requests.post(url, json=payload)
return response.json()平台特点
python
class IflytekPlatformFeatures:
def __init__(self):
self.features = {
"model_variety": {
"description": "模型多样性",
"models": [
"Spark-3.5",
"Spark-Pro",
"Spark-Lite",
"Spark-Max"
],
"score": 4
},
"performance": {
"description": "性能表现",
"metrics": {
"response_time": "< 1s",
"accuracy": "高",
"context_length": "32K"
},
"score": 4
},
"cost": {
"description": "成本",
"pricing": {
"Spark-3.5": "0.036元/千tokens",
"Spark-Pro": "0.018元/千tokens",
"Spark-Lite": "0.009元/千tokens"
},
"score": 4
},
"ecosystem": {
"description": "生态支持",
"features": [
"SDK支持",
"API文档完善",
"社区活跃",
"企业级支持"
],
"score": 4
},
"compliance": {
"description": "合规性",
"certifications": [
"ISO27001",
"等保三级",
"数据本地化"
],
"score": 5
}
}
def get_feature(self, feature_name: str) -> Dict:
return self.features.get(feature_name, {})
def get_all_features(self) -> Dict:
return self.features
def calculate_overall_score(self) -> float:
scores = [feature["score"] for feature in self.features.values()]
return sum(scores) / len(scores)商汤日日新
平台概述
python
class SenseTimeRixin:
def __init__(self, api_key: str):
self.api_key = api_key
self.base_url = "https://api.sensenova.com/v1/chat/completions"
def chat(self, messages: List[Dict],
model: str = "nova-ptc-xl-v1") -> Dict:
import requests
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json"
}
payload = {
"model": model,
"messages": messages
}
response = requests.post(
self.base_url,
json=payload,
headers=headers
)
return response.json()
def stream_chat(self, messages: List[Dict],
model: str = "nova-ptc-xl-v1"):
import requests
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json"
}
payload = {
"model": model,
"messages": messages,
"stream": True
}
response = requests.post(
self.base_url,
json=payload,
headers=headers,
stream=True
)
for line in response.iter_lines():
if line:
yield line.decode("utf-8")平台特点
python
class SenseTimePlatformFeatures:
def __init__(self):
self.features = {
"model_variety": {
"description": "模型多样性",
"models": [
"Nova-PTC-XL",
"Nova-PTC",
"Nova-Chat",
"Nova-Search"
],
"score": 4
},
"performance": {
"description": "性能表现",
"metrics": {
"response_time": "< 1s",
"accuracy": "高",
"context_length": "32K"
},
"score": 4
},
"cost": {
"description": "成本",
"pricing": {
"Nova-PTC-XL": "0.05元/千tokens",
"Nova-PTC": "0.02元/千tokens",
"Nova-Chat": "0.01元/千tokens"
},
"score": 4
},
"ecosystem": {
"description": "生态支持",
"features": [
"SDK支持",
"API文档完善",
"社区活跃",
"企业级支持"
],
"score": 4
},
"compliance": {
"description": "合规性",
"certifications": [
"ISO27001",
"等保三级",
"数据本地化"
],
"score": 5
}
}
def get_feature(self, feature_name: str) -> Dict:
return self.features.get(feature_name, {})
def get_all_features(self) -> Dict:
return self.features
def calculate_overall_score(self) -> float:
scores = [feature["score"] for feature in self.features.values()]
return sum(scores) / len(scores)月之暗面Kimi
平台概述
python
class MoonshotAIKimi:
def __init__(self, api_key: str):
self.api_key = api_key
self.base_url = "https://api.moonshot.cn/v1/chat/completions"
def chat(self, messages: List[Dict],
model: str = "moonshot-v1-128k") -> Dict:
import requests
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json"
}
payload = {
"model": model,
"messages": messages
}
response = requests.post(
self.base_url,
json=payload,
headers=headers
)
return response.json()
def stream_chat(self, messages: List[Dict],
model: str = "moonshot-v1-128k"):
import requests
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json"
}
payload = {
"model": model,
"messages": messages,
"stream": True
}
response = requests.post(
self.base_url,
json=payload,
headers=headers,
stream=True
)
for line in response.iter_lines():
if line:
yield line.decode("utf-8")平台特点
python
class MoonshotAIPlatformFeatures:
def __init__(self):
self.features = {
"model_variety": {
"description": "模型多样性",
"models": [
"Moonshot-V1-128K",
"Moonshot-V1-32K",
"Moonshot-V1-8K"
],
"score": 3
},
"performance": {
"description": "性能表现",
"metrics": {
"response_time": "< 2s",
"accuracy": "高",
"context_length": "128K"
},
"score": 5
},
"cost": {
"description": "成本",
"pricing": {
"Moonshot-V1-128K": "0.12元/千tokens",
"Moonshot-V1-32K": "0.012元/千tokens",
"Moonshot-V1-8K": "0.012元/千tokens"
},
"score": 4
},
"ecosystem": {
"description": "生态支持",
"features": [
"SDK支持",
"API文档完善",
"社区活跃",
"企业级支持"
],
"score": 3
},
"compliance": {
"description": "合规性",
"certifications": [
"ISO27001",
"等保三级",
"数据本地化"
],
"score": 5
}
}
def get_feature(self, feature_name: str) -> Dict:
return self.features.get(feature_name, {})
def get_all_features(self) -> Dict:
return self.features
def calculate_overall_score(self) -> float:
scores = [feature["score"] for feature in self.features.values()]
return sum(scores) / len(scores)Minimax
平台概述
python
class Minimax:
def __init__(self, api_key: str):
self.api_key = api_key
self.base_url = "https://api.minimax.chat/v1/text/chatcompletion_v2"
def chat(self, messages: List[Dict],
model: str = "abab5.5-chat") -> Dict:
import requests
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json"
}
payload = {
"model": model,
"messages": messages
}
response = requests.post(
self.base_url,
json=payload,
headers=headers
)
return response.json()
def stream_chat(self, messages: List[Dict],
model: str = "abab5.5-chat"):
import requests
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json"
}
payload = {
"model": model,
"messages": messages,
"stream": True
}
response = requests.post(
self.base_url,
json=payload,
headers=headers,
stream=True
)
for line in response.iter_lines():
if line:
yield line.decode("utf-8")平台特点
python
class MinimaxPlatformFeatures:
def __init__(self):
self.features = {
"model_variety": {
"description": "模型多样性",
"models": [
"abab5.5-chat",
"abab5.5s-chat",
"abab6-chat",
"abab6.5s-chat"
],
"score": 4
},
"performance": {
"description": "性能表现",
"metrics": {
"response_time": "< 1s",
"accuracy": "高",
"context_length": "32K"
},
"score": 4
},
"cost": {
"description": "成本",
"pricing": {
"abab5.5-chat": "0.015元/千tokens",
"abab5.5s-chat": "0.005元/千tokens",
"abab6-chat": "0.05元/千tokens"
},
"score": 5
},
"ecosystem": {
"description": "生态支持",
"features": [
"SDK支持",
"API文档完善",
"社区活跃",
"企业级支持"
],
"score": 4
},
"compliance": {
"description": "合规性",
"certifications": [
"ISO27001",
"等保三级",
"数据本地化"
],
"score": 5
}
}
def get_feature(self, feature_name: str) -> Dict:
return self.features.get(feature_name, {})
def get_all_features(self) -> Dict:
return self.features
def calculate_overall_score(self) -> float:
scores = [feature["score"] for feature in self.features.values()]
return sum(scores) / len(scores)平台生态对比
生态系统评估
python
class PlatformEcosystemComparator:
def __init__(self):
self.platforms = {
"baidu": {
"name": "百度文心一言",
"ecosystem": {
"sdk": ["Python", "Java", "Go", "Node.js"],
"integrations": ["微信", "钉钉", "飞书"],
"community": {
"github_stars": "10K+",
"documentation": "完善",
"support": "企业级"
},
"tools": [
"模型训练平台",
"数据标注平台",
"部署平台"
]
}
},
"alibaba": {
"name": "阿里通义千问",
"ecosystem": {
"sdk": ["Python", "Java", "Go", "Node.js"],
"integrations": ["阿里云", "钉钉", "淘宝"],
"community": {
"github_stars": "15K+",
"documentation": "完善",
"support": "企业级"
},
"tools": [
"模型训练平台",
"数据标注平台",
"部署平台"
]
}
},
"tencent": {
"name": "腾讯混元",
"ecosystem": {
"sdk": ["Python", "Java", "Go", "Node.js"],
"integrations": ["微信", "QQ", "腾讯云"],
"community": {
"github_stars": "8K+",
"documentation": "完善",
"support": "企业级"
},
"tools": [
"模型训练平台",
"数据标注平台",
"部署平台"
]
}
},
"zhipu": {
"name": "智谱AI",
"ecosystem": {
"sdk": ["Python", "Java", "Go"],
"integrations": ["飞书", "企业微信"],
"community": {
"github_stars": "20K+",
"documentation": "完善",
"support": "企业级"
},
"tools": [
"模型训练平台",
"数据标注平台",
"部署平台"
]
}
},
"iflytek": {
"name": "讯飞星火",
"ecosystem": {
"sdk": ["Python", "Java", "C++"],
"integrations": ["讯飞开放平台"],
"community": {
"github_stars": "5K+",
"documentation": "完善",
"support": "企业级"
},
"tools": [
"语音识别",
"语音合成",
"模型训练平台"
]
}
},
"sensetime": {
"name": "商汤日日新",
"ecosystem": {
"sdk": ["Python", "Java"],
"integrations": ["商汤开放平台"],
"community": {
"github_stars": "3K+",
"documentation": "完善",
"support": "企业级"
},
"tools": [
"视觉识别",
"模型训练平台",
"部署平台"
]
}
},
"moonshot": {
"name": "月之暗面Kimi",
"ecosystem": {
"sdk": ["Python"],
"integrations": ["Kimi网页版"],
"community": {
"github_stars": "2K+",
"documentation": "基础",
"support": "基础"
},
"tools": [
"长文本处理"
]
}
},
"minimax": {
"name": "Minimax",
"ecosystem": {
"sdk": ["Python", "Java", "Go"],
"integrations": ["Glow", "MiniMax开放平台"],
"community": {
"github_stars": "4K+",
"documentation": "完善",
"support": "企业级"
},
"tools": [
"角色扮演",
"多模态生成"
]
}
}
}
def compare_ecosystem(self) -> Dict:
comparison = {}
for platform_id, platform_info in self.platforms.items():
ecosystem = platform_info["ecosystem"]
sdk_score = len(ecosystem["sdk"])
integration_score = len(ecosystem["integrations"])
community_score = self._calculate_community_score(
ecosystem["community"]
)
tools_score = len(ecosystem["tools"])
overall_score = (
sdk_score * 0.3 +
integration_score * 0.2 +
community_score * 0.3 +
tools_score * 0.2
)
comparison[platform_id] = {
"name": platform_info["name"],
"sdk": ecosystem["sdk"],
"integrations": ecosystem["integrations"],
"community": ecosystem["community"],
"tools": ecosystem["tools"],
"overall_score": overall_score
}
return comparison
def _calculate_community_score(self, community: Dict) -> float:
stars = community["github_stars"]
if "20K+" in stars:
return 5.0
elif "15K+" in stars:
return 4.5
elif "10K+" in stars:
return 4.0
elif "5K+" in stars:
return 3.0
else:
return 2.0
def rank_ecosystem(self) -> List[Dict]:
comparison = self.compare_ecosystem()
ranked = sorted(
comparison.items(),
key=lambda x: x[1]["overall_score"],
reverse=True
)
return [
{
"platform_id": platform_id,
**platform_info
}
for platform_id, platform_info in ranked
]
def generate_ecosystem_report(self) -> str:
comparison = self.compare_ecosystem()
ranked = self.rank_ecosystem()
report = f"""
国内AI平台生态对比报告
生态排名:
"""
for i, platform in enumerate(ranked, 1):
report += f"""
{i}. {platform['name']} - 生态得分: {platform['overall_score']:.2f}
"""
report += """
详细对比:
"""
for platform_id, platform_info in comparison.items():
report += f"""
{platform_info['name']}:
- SDK支持: {', '.join(platform_info['sdk'])}
- 集成支持: {', '.join(platform_info['integrations'])}
- 社区: {platform_info['community']['github_stars']}
- 工具: {', '.join(platform_info['tools'])}
- 生态得分: {platform_info['overall_score']:.2f}
"""
return report实践练习
练习1:调用讯飞星火
python
def call_iflytek_spark(app_id, api_key, api_secret, messages):
client = IflytekSpark(app_id, api_key, api_secret)
response = client.chat(messages, model="spark-3.5")
return response练习2:调用月之暗面Kimi
python
def call_moonshot_kimi(api_key, messages):
client = MoonshotAIKimi(api_key)
response = client.chat(messages, model="moonshot-v1-128k")
return response练习3:对比平台生态
python
def compare_platform_ecosystem():
comparator = PlatformEcosystemComparator()
comparison = comparator.compare_ecosystem()
ranked = comparator.rank_ecosystem()
report = comparator.generate_ecosystem_report()
return comparison, ranked, report总结
本节我们学习了国内平台深度对比(下):
- 讯飞星火平台
- 商汤日日新平台
- 月之暗面Kimi平台
- Minimax平台
- 平台生态对比
国内平台生态各有特色,需要根据具体需求选择。
