主流模型对比与选型
综合对比
| 模型 | 参数量 | 上下文 | 中文 | 推理 | 代码 | 工具调用 | 开源 | 价格 |
|---|---|---|---|---|---|---|---|---|
| GPT-4o | ~200B | 128K | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ✅ | ❌ | 高 |
| Claude 3.5 Sonnet | - | 200K | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ✅ | ❌ | 高 |
| 千问 Max | - | 32K | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ✅ | ❌ | 中 |
| DeepSeek-V3 | 671B | 128K | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ✅ | 部分 | 低 |
| ChatGLM-4 | - | 128K | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ✅ | ❌ | 低 |
| Llama 3.1 70B | 70B | 128K | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ✅ | ✅ | 自托管 |
金融场景选型建议
python
# 场景化选型决策树
def select_model(scenario: str, budget: str, privacy: str) -> str:
"""
scenario: 'qa'(问答) | 'analysis'(分析) | 'code'(代码) | 'agent'(智能体)
budget: 'low' | 'medium' | 'high'
privacy: 'public' | 'private'(私有化部署)
"""
if privacy == "private":
if scenario == "code":
return "DeepSeek-Coder-V2 本地部署"
return "ChatGLM3-6B 量化版 或 Llama3-8B"
if scenario == "agent" and budget != "low":
return "qwen-max 或 GPT-4o(工具调用最稳定)"
if scenario == "analysis":
return "qwen-plus 或 DeepSeek-V3(长文本分析)"
if budget == "low":
return "glm-4-flash(免费)或 qwen-turbo"
return "qwen-plus(综合性价比最高)"
# 金融场景示例
print(select_model("agent", "medium", "public")) # qwen-max
print(select_model("qa", "low", "public")) # glm-4-flash
print(select_model("analysis", "high", "private")) # ChatGLM3-6BAPI 接口统一封装
python
from abc import ABC, abstractmethod
from openai import OpenAI
from zhipuai import ZhipuAI
from typing import List, Dict
class LLMClient(ABC):
@abstractmethod
def chat(self, messages: List[Dict], **kwargs) -> str:
pass
class QwenClient(LLMClient):
def __init__(self, api_key: str, model: str = "qwen-turbo"):
self.client = OpenAI(
api_key=api_key,
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
)
self.model = model
def chat(self, messages, **kwargs) -> str:
resp = self.client.chat.completions.create(
model=self.model, messages=messages, **kwargs
)
return resp.choices[0].message.content
class ChatGLMClient(LLMClient):
def __init__(self, api_key: str, model: str = "glm-4-flash"):
self.client = ZhipuAI(api_key=api_key)
self.model = model
def chat(self, messages, **kwargs) -> str:
resp = self.client.chat.completions.create(
model=self.model, messages=messages, **kwargs
)
return resp.choices[0].message.content
# 工厂函数
def create_llm(provider: str, **kwargs) -> LLMClient:
clients = {
"qwen": QwenClient,
"chatglm": ChatGLMClient,
}
return clients[provider](**kwargs)
# 使用
llm = create_llm("qwen", api_key="sk-xxx", model="qwen-plus")
result = llm.chat([{"role": "user", "content": "你好"}])