-
Notifications
You must be signed in to change notification settings - Fork 0
/
try.py
83 lines (63 loc) · 2.08 KB
/
try.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import boto3
import json
import re
import ldclient
from ldclient.config import Config
import os
sdk_key = os.getenv("LAUNCHDARKLY_SDK_KEY")
feature_flag_key = "lengthy-vs-brief"
bedrock_runtime = boto3.client('bedrock-runtime', region_name='us-west-2')
def getResult(prompt):
kwargs = {
"modelId": "anthropic.claude-3-haiku-20240307-v1:0",
"contentType": "application/json",
"accept": "application/json",
"body": json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 1000,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": prompt
}
]
}
]
})
}
response = bedrock_runtime.invoke_model(**kwargs)
body = json.loads(response['body'].read())
edit_body = body['content'][0]['text']
matches = re.findall(r'\*\*(.*?)\*\*', edit_body)
new_match = ""
for match in matches:
new_match = new_match + ", " + match
new_prompt = "Give me the github repo link to all those packages: " + new_match
new_kwargs = {
"modelId": "anthropic.claude-3-haiku-20240307-v1:0",
"contentType": "application/json",
"accept": "application/json",
"body": json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 1000,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": new_prompt
}
]
}
]
})
}
new_response = bedrock_runtime.invoke_model(**new_kwargs)
new_body = json.loads(new_response['body'].read())
new_edit_body = new_body['content'][0]['text']
return new_edit_body
print(getResult("I need an NLP model that detect user sentiments"))