Skip to content

Commit

Permalink
make sure validation flow works for all model providers in bedrock (l…
Browse files Browse the repository at this point in the history
  • Loading branch information
guchenhe authored and dengpeng committed Jun 16, 2024
1 parent d54c070 commit 093265a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ provider_credential_schema:
label:
en_US: Available Model Name
zh_Hans: 可用模型名称
type: secret-input
type: text-input
placeholder:
en_US: A model you have access to (e.g. amazon.titan-text-lite-v1) for validation.
zh_Hans: 为了进行验证,请输入一个您可用的模型名称 (例如:amazon.titan-text-lite-v1)
30 changes: 15 additions & 15 deletions api/core/model_runtime/model_providers/bedrock/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,25 +402,25 @@ def validate_credentials(self, model: str, credentials: dict) -> None:
:param credentials: model credentials
:return:
"""

if "anthropic.claude-3" in model:
try:
self._invoke_claude(model=model,
credentials=credentials,
prompt_messages=[{"role": "user", "content": "ping"}],
model_parameters={},
stop=None,
stream=False)

except Exception as ex:
raise CredentialsValidateFailedError(str(ex))

required_params = {}
if "anthropic" in model:
required_params = {
"max_tokens": 32,
}
elif "ai21" in model:
# ValidationException: Malformed input request: #/temperature: expected type: Number, found: Null#/maxTokens: expected type: Integer, found: Null#/topP: expected type: Number, found: Null, please reformat your input and try again.
required_params = {
"temperature": 0.7,
"topP": 0.9,
"maxTokens": 32,
}
try:
ping_message = UserPromptMessage(content="ping")
self._generate(model=model,
self._invoke(model=model,
credentials=credentials,
prompt_messages=[ping_message],
model_parameters={},
model_parameters=required_params,
stream=False)

except ClientError as ex:
Expand Down

0 comments on commit 093265a

Please sign in to comment.