Update app.py
Browse files
app.py
CHANGED
@@ -31,23 +31,27 @@ def invoke(prompt):
|
|
31 |
completion = ""
|
32 |
|
33 |
try:
|
34 |
-
body = json.dumps({"prompt": "Human: " + prompt + "Assistant: ",
|
35 |
-
"max_tokens_to_sample": config["max_tokens_to_sample"],
|
36 |
-
"temperature": config["temperature"],
|
37 |
-
"top_k": config["top_k"],
|
38 |
-
"top_p": config["top_p"],
|
39 |
-
"stop_sequences": ["Human: "]})
|
40 |
modelId = config["model"]
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
response = bedrock_runtime.invoke_model(
|
45 |
-
|
46 |
-
accept = accept,
|
47 |
-
contentType = contentType)
|
48 |
|
49 |
response_body = json.loads(response.get("body").read())
|
50 |
-
completion = response_body["
|
51 |
except Exception as e:
|
52 |
completion = e
|
53 |
|
|
|
31 |
completion = ""
|
32 |
|
33 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
modelId = config["model"]
|
35 |
+
model_kwargs = {
|
36 |
+
"max_tokens": 2048, "temperature": 0.1,
|
37 |
+
"top_k": 250, "top_p": 1, "stop_sequences": ["\n\nHuman"],
|
38 |
+
}
|
39 |
+
# Input configuration
|
40 |
+
prompt = "What is a trullo?"
|
41 |
+
body = {
|
42 |
+
"anthropic_version": "bedrock-2023-05-31",
|
43 |
+
"system": "You are a honest and helpful bot.",
|
44 |
+
"messages": [
|
45 |
+
{"role": "user", "content": [{"type": "text", "text": prompt}]},
|
46 |
+
],
|
47 |
+
}
|
48 |
+
body.update(model_kwargs)
|
49 |
|
50 |
+
response = bedrock_runtime.invoke_model(modelId=model_id,
|
51 |
+
body=json.dumps(body))
|
|
|
|
|
52 |
|
53 |
response_body = json.loads(response.get("body").read())
|
54 |
+
completion = response_body.get("content", [])[0].get("text", "")
|
55 |
except Exception as e:
|
56 |
completion = e
|
57 |
|