Skip to content

Instantly share code, notes, and snippets.

@JGalego
Last active September 17, 2024 13:33
Show Gist options
  • Select an option

  • Save JGalego/8d21694f4415763aad3d9bcf24df1fe0 to your computer and use it in GitHub Desktop.

Select an option

Save JGalego/8d21694f4415763aad3d9bcf24df1fe0 to your computer and use it in GitHub Desktop.
Titan Love πŸ”±πŸ’—
"""
Sends love to Amazon Titan for Embeddings πŸ’–
and gets a bunch of numbers in return πŸ”’
"""
import json
import boto3
# Initialize Bedrock Runtime client
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-runtime.html
bedrock = boto3.client("bedrock-runtime")
# Call Amazon Titan for Embeddings model on "love"
# https://docs.aws.amazon.com/bedrock/latest/userguide/titan-embedding-models.html
response = bedrock.invoke_model(
modelId="amazon.titan-embed-text-v1",
body="{\"inputText\": \"love\"}"
)
# Process the model response and print the final result
body = json.loads(response.get('body').read())
print(body['embedding'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment