-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (38 loc) · 1.19 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import streamlit as st
import boto3
import json
# from botocore.exceptions import ClientError
client = boto3.client('bedrock-runtime','us-east-1')
def generate_response(prompt):
native_request = {
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 512,
"temperature": 0.5,
"messages": [
{
"role": "user",
"content": [{"type": "text", "text": prompt}],
}
],
}
model_id = "anthropic.claude-3-sonnet-20240229-v1:0"
request = json.dumps(native_request)
try:
response = client.invoke_model(
modelId=model_id, body=request
)
print("response:::",response)
# result = json.loads(response['body'].read())
manas = json.loads(response.get('body').read())
return manas["content"][0]["text"]
except Exception as e:
print(e)
st.title("Chat Playground using Amazon Bedrock and Streamlit")
# st.write("Type a message and get a response from the model.")
user_input = st.text_input("You: ")
if st.button("Send"):
if user_input:
response = generate_response(user_input)
st.write(f" 💬 : {response}")
else:
st.write("Please enter a message.")