Error while using lambda to use bedrock model

0

from langchain.prompts import PromptTemplate from langchain.llms import Bedrock from langchain.chains import LLMChain

def lambda_handler(event, context): # Removed commented-out line (case_study) as it was not being used claude = Bedrock( model_id="meta.llama2-13b-chat-v1" ) claude.model_kwargs = {'max_gen_len': 512, 'temperature': 0.3}

template = """
<s>[INST] <<SYS>>
Be my teacher

<</SYS>>
Instruction: provide a detailed answer for, {question}
Solution:
[/INST]
"""

prompt_template = PromptTemplate(
    input_variables=["question"],  # Include the question variable
    template=template
)

llm_chain = LLMChain(
    llm=claude, verbose=True, prompt=prompt_template
)

try:  # Wrap the execution in a try-except block for graceful error handling
    results = llm_chain({"question": "your question here"})  # Provide a valid question
    print(results["text"])
except Exception as e:  # Catch any exceptions
    print(f"An error occurred: {e}")

return {
    'statusCode': 200,
    'case_results': results["text"] if results else "No response generated"  # Handle potential errors
}

if name == "main": lambda_handler({}, {})

While running this code getting error: Response { "errorMessage": "2024-02-27T04:22:37.625Z 26510848-6bdd-4ee3-a7a4-ee82c357ca80 Task timed out after 3.09 seconds" }

how can i resolve this?

1 Answer
0

The default timeout for Lambda functions is 3 seconds ("The default value for this setting is 3 seconds, but you can adjust this in increments of 1 second up to a maximum value of 15 minutes." from https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-common.html). You can adjust that time window to a larger value to be able to receive the response from the model. I would start with setting it to five Minutes and check then if you still run into a timeout. Let me know if that helps.

profile pictureAWS
EXPERT
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions