Skip to content

LumosNexus/ChatBots

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

ChatBots

Bedrock Runtime Python Client This repository contains a Python client for interacting with Bedrock, a platform for building and deploying AI models. With this client, you can easily send requests to Bedrock models and receive responses.

Installation To use this client, you need to have the following Python packages installed:

boto3: A Python SDK for AWS (Amazon Web Services). awscli: The AWS Command Line Interface. botocore: The low-level, core functionality of boto3. You can install these dependencies using pip by running the following command:

bash Copy code %pip install "boto3>=1.28.57" "awscli>=1.29.57" "botocore>=1.31.57" Getting Started To get started with this client, you will need to import the necessary libraries and create a connection to the Bedrock service.

python Copy code import boto3 import json

Create a connection to the Bedrock service

bedrock = boto3.client(service_name='bedrock-runtime') Next, you can prepare a request to send to a Bedrock model. In this example, we are sending a prompt to an AI model and receiving a response.

python Copy code

Prepare the request body

body = json.dumps({ "prompt": "\n\nHuman:explain black holes to 8th graders\n\nAssistant:", "max_tokens_to_sample": 300, "temperature": 0.1, "top_p": 0.9, })

Specify the model to use

modelId = 'anthropic.claude-v2'

Set the content type for the request and response

accept = 'application/json' contentType = 'application/json'

Send the request to the Bedrock model

response = bedrock.invoke_model(body=body, modelId=modelId, accept=accept, contentType=contentType)

Parse the response

response_body = json.loads(response.get('body').read())

Print the generated text

print(response_body.get('completion')) Make sure to customize the body, modelId, and other parameters according to your specific use case.

License This Python client for Bedrock is provided under the MIT License. Feel free to use and modify it as needed for your projects.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published