Skip to content

Commit aedbb16

Browse files
authored
Merge pull request #6 from KyMidd/feature/teach-time-and-anthropic-3.7
Teach time and anthropic 3.7
2 parents bee740a + 6cd8bc0 commit aedbb16

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

python/devopsbot.py

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,44 @@
1414
import json
1515
import requests
1616
import re
17+
from datetime import datetime, timezone
1718

1819
# Slack app imports
1920
from slack_bolt import App
2021
from slack_bolt.adapter.socket_mode import SocketModeHandler # Required for socket mode, used in local development
2122
from slack_bolt.adapter.aws_lambda import SlackRequestHandler
2223

2324

25+
###
26+
# Fetch current date and time
27+
###
28+
29+
# Current date and time, fetched at launch
30+
current_utc = datetime.now(timezone.utc)
31+
current_utc_string = current_utc.strftime("%Y-%m-%d %H:%M:%S %Z")
32+
33+
2434
###
2535
# Constants
2636
###
2737

38+
# Bot info
39+
bot_name = "Vera"
40+
41+
# Slack
42+
slack_buffer_token_size = 10 # Number of tokens to buffer before updating Slack
43+
slack_message_size_limit_words = 350 # Slack limit of characters in response is 4k. That's ~420 words. 350 words is a safe undershot of words that'll fit in a slack response. Used in the system prompt for Vera.
44+
2845
# Specify model ID and temperature
29-
model_id = 'anthropic.claude-3-5-sonnet-20241022-v2:0'
46+
model_id = "us.anthropic.claude-3-7-sonnet-20250219-v1:0" # US regional Claude 3.7 Sonnet model
3047
anthropic_version = "bedrock-2023-05-31"
3148
temperature = 0.2
3249
top_k = 25
3350

3451
# Secrets manager secret name. Json payload should contain SLACK_BOT_TOKEN and SLACK_SIGNING_SECRET
3552
bot_secret_name = "DEVOPSBOT_SECRETS_JSON"
3653

37-
# Guardrail information
54+
# Bedrock guardrail information
3855
enable_guardrails = False # Won't use guardrails if False
3956
guardrailIdentifier = "xxxxxxxxxx"
4057
guardrailVersion = "DRAFT"
@@ -53,13 +70,15 @@
5370
rerank_model_id = "amazon.rerank-v1:0"
5471

5572
# Model guidance, shimmed into each conversation as instructions for the model
56-
model_guidance = """Assistant is a large language model trained to provide the best possible experience for developers and operations teams.
57-
Assistant is designed to provide accurate and helpful responses to a wide range of questions.
58-
Assistant answers should be short and to the point, usually less than 100 words and should be relevant to the user's question.
59-
Assistant should follow Slack's best practices for formatting messages.
60-
Assistant should address the user by name.
61-
Assistant should always provide a Confluence citation link when providing information from the knowledge base.
62-
"""
73+
model_guidance = f"""Assistant is a large language model named {bot_name} who is trained to support Veradigm in providing the best possible experience for their developers and operations team.
74+
Assistant must follow Slack's best practices for formatting messages.
75+
Assistant must limit messages to {slack_message_size_limit_words} words, including code blocks. For longer responses Assistant should provide the first part of the response, and then prompt User to ask for the next part of the response.
76+
Assistant should address the user by name, and shouldn't echo user's pronouns.
77+
When Assistant finishes responding entirely, Assistant should suggest questions the User can ask.
78+
Assistant should always provide a Confluence citation link when providing information from the knowledge base.
79+
When providing Splunk query advice, Assistant must recommend queries that use the fewest resources.
80+
The current date and time is {current_utc_string} UTC.
81+
"""
6382

6483

6584
###
@@ -300,7 +319,15 @@ def response_on_slack(client, streaming_response, message_ts, channel_id, thread
300319
buffer += text
301320
token_counter += 1
302321

303-
if token_counter >= 10:
322+
if token_counter >= slack_buffer_token_size:
323+
# Debug
324+
if os.environ.get("VERA_DEBUG", "False") == "True":
325+
# Print response word count
326+
print("🚀 Response word count:", len(response.split()))
327+
328+
# Print response character count
329+
print("🚀 Response character count:", len(response))
330+
304331
client.chat_update(
305332
text=response,
306333
channel=channel_id,
@@ -313,6 +340,14 @@ def response_on_slack(client, streaming_response, message_ts, channel_id, thread
313340
# If buffer contains anything after iterating over any chunks, add it also
314341
# This completes the update
315342
if buffer:
343+
# Debug
344+
if os.environ.get("VERA_DEBUG", "False") == "True":
345+
# Print response word count
346+
print("🚀 Final response word count:", len(response.split()))
347+
348+
# Print response character count
349+
print("🚀 Final response character count:", len(response))
350+
316351
client.chat_update(
317352
text=response,
318353
channel=channel_id,

terraform/lambda/lambda.tf

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,25 @@ resource "aws_iam_role_policy" "DevOpsBotSlack_Bedrock" {
8585
{
8686
"Version" : "2012-10-17",
8787
"Statement" : [
88-
# Grant permission to invoke bedrock models of any type in us-west-2 region
88+
# Grant permission to invoke bedrock models of any type in US regions
8989
{
9090
"Effect" : "Allow",
91-
"Action" : "bedrock:InvokeModel",
92-
"Resource" : "arn:aws:bedrock:us-west-2::foundation-model/*"
91+
"Action" : [
92+
"bedrock:InvokeModel",
93+
"bedrock:InvokeModelStream",
94+
"bedrock:InvokeModelWithResponseStream",
95+
],
96+
# Both no longer specify region, since Bedrock wants cross-region access
97+
"Resource" : [
98+
"arn:aws:bedrock:us-east-1::foundation-model/*",
99+
"arn:aws:bedrock:us-east-2::foundation-model/*",
100+
"arn:aws:bedrock:us-west-1::foundation-model/*",
101+
"arn:aws:bedrock:us-west-2::foundation-model/*",
102+
"arn:aws:bedrock:us-east-1:${data.aws_caller_identity.current.account_id}:inference-profile/*",
103+
"arn:aws:bedrock:us-east-2:${data.aws_caller_identity.current.account_id}:inference-profile/*",
104+
"arn:aws:bedrock:us-west-1:${data.aws_caller_identity.current.account_id}:inference-profile/*",
105+
"arn:aws:bedrock:us-west-2:${data.aws_caller_identity.current.account_id}:inference-profile/*",
106+
]
93107
},
94108
# Grant permission to invoke bedrock guardrails of any type in us-west-2 region
95109
{

0 commit comments

Comments
 (0)