[Bug]: Missing supports_assistant_prefill on AWS Bedrock Claude 3.x entries in model_prices_and_context_window.json

用户在 LiteLLM SDK(Python 包,版本 v1.89.2)中加载 model_prices_and_context_window.json 模型配置时,发现多个 AWS Bedrock 上的 Claude 3 条目缺少 supports_assistant_prefill 字段。任何依

[Bug]: Missing supports_assistant_prefill on AWS Bedrock Claude 3.x entries in model_prices_and_context_window.json

[Bug]: Missing supports_assistant_prefill on AWS Bedrock Claude 3.x entries in model_prices_and_context_window.json

快速结论:当使用 LiteLLM 调用 AWS Bedrock 上的 Claude 3 系列模型(如 Haiku、Sonnet、3.5 Sonnet 初版)时,supports_assistant_prefill 字段缺失(而非设为 false),导致预填(prefill)功能被静默禁用。优先排查 model_prices_and_context_window.json 中对应条目是否缺少该字段,并根据 Anthropic 官方文档确认这些模型实际支持该功能。

问题场景

用户在 LiteLLM SDK(Python 包,版本 v1.89.2)中加载 model_prices_and_context_window.json 模型配置时,发现多个 AWS Bedrock 上的 Claude 3 条目缺少 supports_assistant_prefill 字段。任何依赖该字段真值来启用预填功能的代码,会因字段缺失(None)而静默禁用该特性。

报错原文

# No error — the field is silently absent; callers that check truthiness treat None as False.

import litellm
info = litellm.get_model_info("anthropic.claude-3-haiku-20240307-v1:0")
print(info.get("supports_assistant_prefill"))  # None (should be True)

原因分析

该问题属于数据不一致(data inconsistency)。model_prices_and_context_window.json 中多个 AWS Bedrock Claude 3 条目遗漏了 supports_assistant_prefill 字段,而这些模型(根据 Anthropic 官方迁移指南)实际支持 trailing-assistant continuation prefill。字段缺失原因可能在于多区域(us、eu、apac)模型配置维护时的疏忽,导致没有从单一源(single source of truth)同步该字段。

环境排查

  • 确认 LiteLLM 版本(建议检查是否为 v1.89.2 或更早版本)
  • 检查 model_prices_and_context_window.json 中相关条目是否完整(如 anthropic.claude-3-haiku-20240307-v1:0 等)
  • 验证 Python 环境中 litellm 包的版本号

解决步骤

  1. 定位 model_prices_and_context_window.json 文件(通常在 LiteLLM 包目录内)。
  2. 搜索受影响的模型条目(如 anthropic.claude-3-haiku-20240307-v1:0us.anthropic.claude-3-haiku-20240307-v1:0eu.anthropic.claude-3-sonnet-20240229-v1:0 等共 12 个)。
  3. 为每个缺失的条目添加 "supports_assistant_prefill": true 字段,格式参考已正确填充的条目(例如 "anthropic.claude-3-5-sonnet-20241022-v2:0": { "supports_assistant_prefill": true, ... })。
  4. 可优先尝试:在代码中添加验证脚本(如使用 Pydantic 进行 schema 校验),确保所有模型配置包含必要字段。
  5. 可优先尝试:考虑在代码中实现后备机制,当字段缺失时默认设为 true(前提是确认模型实际支持)。

验证方法

修改后,运行以下 Python 代码确认字段已正确返回 True
info = litellm.get_model_info("anthropic.claude-3-haiku-20240307-v1:0")
print(info.get("supports_assistant_prefill")) # 应输出 True

同时,测试实际预填功能是否正常启用。

参考来源

BerriAI/litellm #30863

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

celebrityanime
celebrityanime
文章: 9593

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注