-
-
Save KyMidd/325b6022382db3683053c37ce26530e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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