-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_basic_rag.py
53 lines (39 loc) · 1.18 KB
/
01_basic_rag.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
50
51
52
53
import boto3
import json
import os
from datetime import date
def load_context(file_name):
script_path = os.path.abspath(__file__)
file_path = os.path.join(os.path.dirname(script_path), file_name)
with open(file_path, 'r') as file:
return json.load(file)
client = boto3.client("bedrock-runtime", region_name="us-east-1")
system_prompt = [{
"text": f"""
Today's date is {date.today()}. You are a travel assistant.
You will be given JSON data embedded in <context> tags about travel destinations and activities.
With that information, answer the user's question, embedded in <question> tags.
"""
}]
context_data = load_context('files/travel_info.json')
context = json.dumps(context_data)
prompt = "Would it be a good time to visit Las Vegas this month?"
augmented_prompt = f"""
<context>
{context}
</context>
<question>
{prompt}
</question>
"""
messages = [{
"role": "user",
"content": [{"text": augmented_prompt}]
}]
response = client.converse(
modelId="anthropic.claude-3-haiku-20240307-v1:0",
system=system_prompt,
messages=messages
)
response_text = response["output"]["message"]["content"][0]["text"]
print(response_text)