Skip to content

Stuck on Using Bedrock Invoke API to generate response #812

@justmekaren

Description

@justmekaren

Package

langchain-aws

Checked other resources

  • I added a descriptive title to this issue
  • I searched the LangChain documentation with the integrated search
  • I used the GitHub search to find a similar issue and didn't find it
  • I am sure this is a bug and not a question or request for help

Example Code

from langchain_aws import ChatBedrock

# Local Imports
from libs.utility.clients import _get_client
from libs.utility.logging import logging
import os

default_max_tokens = "Value"
llm_model = "ModelId"


bedrock_client = _get_client("bedrock-runtime", region="us-east-1")

def llm_instance(
    modelId=llm_model, streaming=True, temperature=0.3, max_tokens=default_max_tokens
):
    """Returns an instance of the LLM to use
    :param modelId: The ID of the LLM
    :param streaming: Boolean for instance of the LLM to enable streaming or no
    :param temperature: Creativity level for the LLM
    """
    logging.info(f"Max_tokens: {max_tokens}")
    
    return ChatBedrock(
        model_id=modelId,
        client=bedrock_client,
        streaming=streaming,
        model_kwargs=dict(temperature=temperature, max_tokens=int(max_tokens)),
    )


llm_tool = llm_instance(streaming=False, temperature=0.0)

logging.info("Instance created successfully.")

Error Message and Stack Trace (if applicable)

stuck on "Using Bedrock Invoke API to generate response" on llm invoke

libs/aws/langchain_aws/llms/bedrock.py

Description

I am getting inconsistencies when invoking the model. Cloudwatch logs shows this message "Using Bedrock Invoke API to generate response" but it never returned the LLM response back.

boto3 config max retry 3, read timeout = 120s, connect timeout = 10

I've checked the CW metrics and the model invocation actually did return a response. This issue happened 5/10 attempts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions