Together AI
Together AI 提供开源模型的托管服务,专注于为开发者提供高性能、成本效益的 AI 模型访问。
支持的模型
Meta LLaMA
- meta-llama/Llama-2-70b-chat-hf - LLaMA 2 70B
- meta-llama/Llama-2-13b-chat-hf - LLaMA 2 13B
- meta-llama/Llama-3-70b-instruct-hf - LLaMA 3 70B
- meta-llama/Llama-3-8b-instruct-hf - LLaMA 3 8B
Mistral
- mistralai/Mixtral-8x7B-Instruct-v0.1 - Mixtral MoE
- mistralai/Mistral-7B-Instruct-v0.1 - Mistral 7B
代码模型
- codellama/CodeLlama-34b-Instruct-hf - CodeLlama 34B
- codellama/CodeLlama-13b-Instruct-hf - CodeLlama 13B
- bigcode/starcoder - StarCoder
其他开源模型
- WizardLM/WizardLM-70B-V1.0 - WizardLM
- togethercomputer/RedPajama-INCITE-7B-Instruct - RedPajama
配置
基础配置
在 config.yaml 或 ~/.bytebuddy/config.yaml 中配置:
yaml
models:
- name: "together-llama"
provider: "together"
model: "meta-llama/Llama-2-70b-chat-hf"
apiKey: "${TOGETHER_API_KEY}"
roles: ["chat", "edit"]
defaultCompletionOptions:
temperature: 0.7
maxTokens: 4096代码生成配置
yaml
models:
- name: "together-code"
provider: "together"
model: "codellama/CodeLlama-34b-Instruct-hf"
apiKey: "${TOGETHER_API_KEY}"
roles: ["edit", "apply"]
defaultCompletionOptions:
temperature: 0.2
maxTokens: 2048多模型配置
yaml
models:
- name: "together-llama-70b"
provider: "together"
model: "meta-llama/Llama-2-70b-chat-hf"
apiKey: "${TOGETHER_API_KEY}"
roles: ["chat"]
defaultCompletionOptions:
temperature: 0.7
maxTokens: 4096
- name: "together-mixtral"
provider: "together"
model: "mistralai/Mixtral-8x7B-Instruct-v0.1"
apiKey: "${TOGETHER_API_KEY}"
roles: ["chat", "edit"]
defaultCompletionOptions:
temperature: 0.6
maxTokens: 4096
- name: "together-codellama"
provider: "together"
model: "codellama/CodeLlama-34b-Instruct-hf"
apiKey: "${TOGETHER_API_KEY}"
roles: ["edit", "apply"]
defaultCompletionOptions:
temperature: 0.2
maxTokens: 2048配置字段
必需字段
- name: 模型配置的唯一标识符
- provider: 设置为
"together" - model: 模型标识符(格式:
organization/model-name) - apiKey: Together API 密钥
可选字段
- roles: 模型角色 [
chat,edit,apply,autocomplete] - defaultCompletionOptions:
temperature: 控制随机性 (0-2)maxTokens: 最大令牌数topP: 核采样参数topK: 采样候选数量repetitionPenalty: 重复惩罚stopSequences: 停止序列
环境变量
bash
# ~/.bashrc 或 ~/.zshrc
export TOGETHER_API_KEY="your-together-api-key"获取 API 密钥
- 访问 Together AI
- 注册账户并登录
- 在 API Keys 页面生成新密钥
- 将密钥保存到环境变量
使用场景配置
高性能对话
yaml
models:
- name: "high-quality-chat"
provider: "together"
model: "meta-llama/Llama-3-70b-instruct-hf"
apiKey: "${TOGETHER_API_KEY}"
roles: ["chat"]
defaultCompletionOptions:
temperature: 0.7
maxTokens: 4096成本优化
yaml
models:
- name: "cost-optimized"
provider: "together"
model: "meta-llama/Llama-2-13b-chat-hf"
apiKey: "${TOGETHER_API_KEY}"
roles: ["chat"]
defaultCompletionOptions:
temperature: 0.7
maxTokens: 2048代码助手
yaml
models:
- name: "code-assistant"
provider: "together"
model: "codellama/CodeLlama-34b-Instruct-hf"
apiKey: "${TOGETHER_API_KEY}"
roles: ["edit", "apply"]
defaultCompletionOptions:
temperature: 0.2
maxTokens: 2048性能特性
高吞吐量
- 支持大规模并发请求
- 优化的推理引擎
- 智能负载均衡
低延迟
- 全球分布的推理服务器
- 智能路由选择
- 缓存优化
可扩展性
- 动态资源分配
- 自动扩缩容
- 弹性计算资源
故障排除
常见错误
- 401 Unauthorized: 检查 API 密钥是否正确
- 429 Too Many Requests: 达到速率限制
- Model Not Found: 确认模型标识符格式
- Service Unavailable: 服务临时不可用
调试步骤
- 验证 API 密钥格式和有效性
- 检查模型标识符是否正确
- 确认网络连接正常
- 查看 Together AI 状态页面
- 检查速率限制和配额
最佳实践
1. 模型选择
- 根据任务复杂度选择模型大小
- 优先使用最新模型版本
- 考虑成本效益平衡
- 代码任务使用 CodeLlama
2. 参数优化
- 降低温度值以获得一致性
- 合理设置最大令牌数
- 使用停止序列控制输出
- 调整重复惩罚避免重复
3. 成本控制
- 监控 API 使用量
- 选择合适大小的模型
- 优化提示词长度
- 设置配额警报
4. 性能优化
- 启用流式响应
- 实现请求缓存
- 批量处理相似请求
- 选择最近的服务器区域