Skip to content

Commit

Permalink
detect and process "Too many requests" from AWS Bedrock API
Browse files Browse the repository at this point in the history
  • Loading branch information
brainlid committed Nov 29, 2024
1 parent 454df98 commit a2f25cf
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/chat_models/chat_anthropic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,11 @@ defmodule LangChain.ChatModels.ChatAnthropic do
LangChainError.exception(type: "invalid_json", message: error_message, original: response)}
end

def do_process_response(%ChatAnthropic{bedrock: %BedrockConfig{}}, %{"message" => "Too many requests" <> _rest = message}) do
# the error isn't wrapped in an error JSON object. tsk, tsk
{:error, LangChainError.exception(type: "too_many_requests", message: message)}
end

def do_process_response(%ChatAnthropic{bedrock: %BedrockConfig{}}, %{"message" => message}) do
{:error, LangChainError.exception(message: "Received error from API: #{message}")}
end
Expand Down

0 comments on commit a2f25cf

Please sign in to comment.