Skip to content

Commit f52df16

Browse files
feat: Increase max tokens
1 parent 00ea6ef commit f52df16

File tree

4 files changed

+32
-37
lines changed

4 files changed

+32
-37
lines changed

packages/slackBotFunction/app/services/bedrock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def query_bedrock(user_query: str, session_id: str = None) -> RetrieveAndGenerat
2525
inference_config = prompt_template.get("inference_config")
2626

2727
if not inference_config:
28-
default_values = {"temperature": 0, "maxTokens": 512, "topP": 1}
28+
default_values = {"temperature": 0, "maxTokens": 1500, "topP": 1}
2929
inference_config = default_values
3030
logger.warning(
3131
"No inference configuration found in prompt template; using default values",

packages/slackBotFunction/app/services/prompt_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def load_prompt(prompt_name: str, prompt_version: str = None) -> dict:
106106
actual_version = response.get("version", "DRAFT")
107107

108108
# Extract inference configuration with defaults
109-
default_inference = {"temperature": 0, "topP": 1, "maxTokens": 512}
109+
default_inference = {"temperature": 0, "topP": 1, "maxTokens": 1500}
110110
raw_inference = response["variants"][0].get("inferenceConfiguration", {})
111111
raw_text_config = raw_inference.get("textInferenceConfiguration", {})
112112
inference_config = {**default_inference, **raw_text_config}

packages/slackBotFunction/app/slack/slack_events.py

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -615,70 +615,65 @@ def store_feedback(
615615

616616

617617
def open_citation(channel: str, timestamp: str, message: Any, params: Dict[str, Any], client: WebClient) -> None:
618-
"""
619-
Open citation - update/ replace message to include citation content
620-
"""
618+
"""Open citation - update/replace message to include citation content"""
621619
logger.info("Opening citation", extra={"channel": channel, "timestamp": timestamp})
622-
# Get Message
623620
try:
624-
# Get citation details
621+
# Citation details
625622
title: str = params.get("title", "No title available.")
626623
body: str = params.get("body", "No citation text available.")
627624
source_number: str = params.get("source_number")
625+
link: str = params.get("link", "")
628626

629-
# Remove any citation block (and divider), if it exists
627+
# Remove any existing citation block/divider
630628
blocks = message.get("blocks", [])
631-
blocks = [block for block in blocks if block.get("block_id") not in ["citation_block", "citation_divider"]]
632-
633-
# Add formatting
634-
title = f"*{title.replace("\n", "")}*"
635-
body = f"> {body.replace("\n", "\n> ")}"
636-
link: str = params.get("link", "")
629+
blocks = [b for b in blocks if b.get("block_id") not in ["citation_block", "citation_divider"]]
637630

638-
# Highlight selected citation by updating the button style
639-
logger.info("Searching for Citation", extra={"cit_n": source_number, "cit_title": title})
631+
# Format text
632+
title = f"*{title.replace('\n', '')}*"
633+
body = f"> {body.replace('\n', '\n> ')}"
640634

641-
active_id = None
642635
current_id = f"cite_{source_number}"
636+
selected = False
637+
638+
# Reset all button styles, then set the clicked one
643639
for block in blocks:
644640
if block.get("type") == "actions":
645641
for element in block.get("elements", []):
646642
if element.get("type") == "button":
647643
action_id = element.get("action_id")
648-
649-
if element.get("style"):
650-
active_id = action_id
651-
652-
if action_id == current_id and active_id != current_id:
653-
logger.info(
654-
"Citation found - set active", extra={"cit_n": source_number, "cit_title": title}
655-
)
656-
element["style"] = "primary"
644+
if action_id == current_id:
645+
# Toggle: if already styled, unselect; else select
646+
if element.get("style") == "primary":
647+
element.pop("style", None)
648+
selected = False
649+
else:
650+
element["style"] = "primary"
651+
selected = True
657652
else:
653+
# Unselect all other buttons
658654
element.pop("style", None)
659655

660-
if active_id:
661-
# Add citation content before feedback block
656+
# If selected, insert citation block before feedback
657+
if selected:
662658
citation_block = {
663659
"type": "section",
664660
"text": {
665661
"type": "mrkdwn",
666662
"text": (
667663
f"{title}\n\n{body}\n\n<{link}|View Source>"
668664
if link and link != "none"
669-
else f"*{title}*\n\n{body}"
665+
else f"{title}\n\n{body}"
670666
),
671667
},
672668
"block_id": "citation_block",
673669
}
674-
675-
# Find index of feedback block to insert before it
676-
feedback_block_index = next(
677-
(i for i, block in enumerate(blocks) if block.get("block_id") == "feedback-divider"), len(blocks)
670+
feedback_index = next(
671+
(i for i, b in enumerate(blocks) if b.get("block_id") == "feedback-divider"),
672+
len(blocks),
678673
)
679-
blocks.insert(feedback_block_index, citation_block)
674+
blocks.insert(feedback_index, citation_block)
680675

681-
# Update message with new blocks
676+
# Update Slack message
682677
logger.info("Updated message body", extra={"blocks": blocks})
683678
client.chat_update(channel=channel, ts=timestamp, blocks=blocks)
684679

packages/slackBotFunction/tests/test_bedrock_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_query_bedrock_check_config(mock_boto_client: Mock, mock_load_prompt: Mo
114114
mock_client.retrieve_and_generate.return_value = {"output": {"text": "response"}}
115115
mock_load_prompt.return_value = {
116116
"prompt_text": "Test prompt template",
117-
"inference_config": {"temperature": "0", "maxTokens": "512", "topP": "1"},
117+
"inference_config": {"temperature": "0", "maxTokens": "1500", "topP": "1"},
118118
}
119119

120120
# delete and import module to test
@@ -132,5 +132,5 @@ def test_query_bedrock_check_config(mock_boto_client: Mock, mock_load_prompt: Mo
132132
]["inferenceConfig"]["textInferenceConfig"]
133133

134134
assert prompt_config["temperature"] == "0"
135-
assert prompt_config["maxTokens"] == "512"
135+
assert prompt_config["maxTokens"] == "1500"
136136
assert prompt_config["topP"] == "1"

0 commit comments

Comments
 (0)