Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created December 27, 2024 20:21
Show Gist options
  • Select an option

  • Save KyMidd/325b6022382db3683053c37ce26530e0 to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/325b6022382db3683053c37ce26530e0 to your computer and use it in GitHub Desktop.
# Function to handle ai request input and response
def ai_request(bedrock_client, messages):
# If enable_guardrails is set to True, include guardrailIdentifier and guardrailVersion in the request
if enable_guardrails:
response = bedrock_client.invoke_model(
modelId=model_id,
guardrailIdentifier=guardrailIdentifier,
guardrailVersion=guardrailVersion,
body=json.dumps(
{
"anthropic_version": anthropic_version,
# "betas": ["pdfs-2024-09-25"], # This is not yet supported, https://docs.anthropic.com/en/docs/build-with-claude/pdf-support#supported-platforms-and-models
"max_tokens": 1024,
"messages": messages,
"temperature": temperature,
"system": model_guidance,
}
),
)
# If enable_guardrails is set to False, do not include guardrailIdentifier and guardrailVersion in the request
else:
response = bedrock_client.invoke_model(
modelId=model_id,
body=json.dumps(
{
"anthropic_version": anthropic_version,
# "betas": ["pdfs-2024-09-25"], # This is not yet supported, https://docs.anthropic.com/en/docs/build-with-claude/pdf-support#supported-platforms-and-models
"max_tokens": 1024,
"messages": messages,
"temperature": temperature,
"system": model_guidance,
}
),
)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment