Anirudh Esthuri commited on
Commit
9abf0b8
·
1 Parent(s): c738f66

Improve error messages for invalid Bedrock model IDs

Browse files
Files changed (1) hide show
  1. llm.py +15 -2
llm.py CHANGED
@@ -141,7 +141,14 @@ def chat(messages, persona):
141
  raise
142
  except Exception as e:
143
  error_msg = str(e)
144
- if "UnrecognizedClientException" in error_msg or "invalid" in error_msg.lower():
 
 
 
 
 
 
 
145
  raise ValueError(
146
  f"AWS Bedrock authentication failed: {error_msg}. "
147
  "Please verify your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY secrets "
@@ -201,7 +208,13 @@ def chat(messages, persona):
201
  raise
202
  except Exception as e:
203
  error_msg = str(e)
204
- if "UnrecognizedClientException" in error_msg or "invalid" in error_msg.lower():
 
 
 
 
 
 
205
  raise ValueError(
206
  f"AWS Bedrock authentication failed: {error_msg}. "
207
  "Please verify your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY secrets "
 
141
  raise
142
  except Exception as e:
143
  error_msg = str(e)
144
+ if "ValidationException" in error_msg and "model identifier is invalid" in error_msg:
145
+ raise ValueError(
146
+ f"Invalid Bedrock model ID: '{MODEL_STRING}'. "
147
+ f"Error: {error_msg}. "
148
+ "Please verify the model ID is correct and the model is available in your AWS region. "
149
+ "Common Claude model IDs: 'anthropic.claude-3-5-sonnet-20241022-v2' or 'anthropic.claude-3-haiku-20240307-v1'"
150
+ ) from e
151
+ elif "UnrecognizedClientException" in error_msg or "invalid" in error_msg.lower():
152
  raise ValueError(
153
  f"AWS Bedrock authentication failed: {error_msg}. "
154
  "Please verify your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY secrets "
 
208
  raise
209
  except Exception as e:
210
  error_msg = str(e)
211
+ if "ValidationException" in error_msg and "model identifier is invalid" in error_msg:
212
+ raise ValueError(
213
+ f"Invalid Bedrock model ID: '{MODEL_STRING}'. "
214
+ f"Error: {error_msg}. "
215
+ "Please verify the model ID is correct and the model is available in your AWS region."
216
+ ) from e
217
+ elif "UnrecognizedClientException" in error_msg or "invalid" in error_msg.lower():
218
  raise ValueError(
219
  f"AWS Bedrock authentication failed: {error_msg}. "
220
  "Please verify your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY secrets "