You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS Bedrock调用Titan Text G1-Express遇格式验证错误求助

解决AWS Bedrock Titan Text G1-Express调用问题

1. 区域不匹配问题(已完成切换,但需确认配置)

  • 报错原因:Titan Text G1-Express仅在us-east-1等特定区域部署,us-east-2无该模型,导致模型ID无效。
  • 确认配置:确保AWS区域设置为us-east-1,可在初始化Bedrock时显式指定:
    llm = Bedrock(
        credentials_profile_name="default",
        model_id="amazon.titan-text-express-v1",
        region_name="us-east-1"
    )
    

2. 输入格式不匹配问题(核心报错)

错误提示Malformed input request: string [Observation] does not match pattern ^(\|+|User:)$,是因为CrewAI默认的Agent prompt模板包含Observation标识,不符合Titan Text的格式要求——Titan要求输入必须以User:开头,或使用竖线分隔格式。

解决方法:

  • 自定义适配Titan的prompt模板,替换CrewAI默认模板:
    from crewai import Agent
    from langchain_community.llms import Bedrock
    from langchain_core.prompts import PromptTemplate
    
    llm = Bedrock(
        credentials_profile_name="default",
        model_id="amazon.titan-text-express-v1",
        region_name="us-east-1"
    )
    
    # 定义符合Titan格式的模板
    titan_compatible_prompt = PromptTemplate(
        input_variables=["role", "goal", "backstory", "task"],
        template="""User: You are {role}. Your core goal is {goal}. Your background: {backstory}. Please complete this task: {task}"""
    )
    
    my_agent = Agent(
        role="my role",
        goal="my goal",
        verbose=True,
        llm=llm,
        backstory="""my backstory""",
        prompt_template=titan_compatible_prompt  # 应用自定义模板
    )
    
  • 如果涉及多轮对话或工具调用,需确保所有交互内容都以User:开头,避免出现Observation等不符合规则的标识,可调整任务提示语或禁用不必要的默认格式。

内容的提问来源于stack exchange,提问作者Sameer Mahajan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 18:17:24