Skip to content

Commit 20b7c7d

Browse files
feat: update styling and try use markdown instead of mrkdwn
1 parent 8cf7a4e commit 20b7c7d

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

packages/cdk/prompts/systemPrompt.txt

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ IMPORTANT: This is informational guidance only. Always verify against current cl
66
- Summary: 150 characters maximum, capturing core answer
77
- Answer
88
- Page break (use `------`)
9-
- \[Citation\] (prioritise token useage here)
9+
- \[Bibliography\] (prioritise token usage here)
1010

1111
2. Question Handling
1212
a. Detect whether the query contains one or multiple questions
@@ -62,25 +62,24 @@ IMPORTANT: This is informational guidance only. Always verify against current cl
6262
- Medication dosing: "Consult BNF/local formulary and prescribing clinician"
6363
- Patient-specific data: "Cannot access or discuss patient health information"
6464

65-
6. Slack Formatting Standards
66-
a. *Bold* for:
67-
- Headings, subheadings: *Answer:*, *Bibliography:*
68-
- Source names: *NHS Digital*, *EPS*
69-
b. _Italic_ for:
65+
6. Text Formatting
66+
a. Use Markdown text formatting
67+
a. Bold for:
68+
- Headings, subheadings: **Answer:**, **Bibliography:**
69+
- Source names: **NHS Digital**, **EPS**
70+
b. Italic for:
7071
- Citations, references
7172
- Document titles: _Integration Guide v3.2_
72-
c. ```code blocks``` for:
73-
- Direct quotes >1 sentence
73+
c. Block Quotes for:
74+
- Direct quotes
7475
- Technical specifications, parameters
7576
- Example configurations
76-
d. `inline code` for:
77+
d. Inline Code for:
7778
- System names, field names: `PrescriptionID`
7879
- Short technical terms: `HL7 FHIR`
79-
e. Links:
80-
- Format: <https://example.com|Descriptive Name>
81-
- Always test readability of link text
8280

83-
7. Citations
84-
a. In line citations should be proceeded by [cit_{index number}]
85-
b. Citations in the [citation] sections should be formatted <cit>source number|title|link|filename|reference text|</cit>
86-
- If the link doesn't exist, enter "none" in the link section
81+
7. Bibliography and References
82+
a. In line citations should be proceeded by [cit_{index number}] and use a http link
83+
b. Citations in the [citation] sections should be formatted: <cit>source number|title|link|filename|reference text</cit>
84+
- If the link doesn't exist, or the link isn't to a website, enter "none" in the link section
85+
c. Any source used, inline or as a source to generate an answer, should be listed in the Bibliography section

packages/slackBotFunction/app/slack/slack_events.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def _create_feedback_blocks(
198198
)
199199

200200
# Main body
201-
blocks.append({"type": "section", "text": {"type": "mrkdwn", "text": response_text}})
201+
blocks.append({"type": "section", "text": {"type": "markdown", "text": response_text}})
202202

203203
# Citation action block
204204
if action_buttons:
@@ -211,7 +211,7 @@ def _create_feedback_blocks(
211211
)
212212

213213
# Feedback buttons
214-
blocks.append({"type": "divider"})
214+
blocks.append({"type": "divider", "block_id": "feedback-divider"})
215215
blocks.append({"type": "context", "elements": [{"type": "mrkdwn", "text": "Was this response helpful?"}]})
216216
blocks.append(
217217
{
@@ -411,7 +411,13 @@ def process_slack_message(event: Dict[str, Any], event_id: str, client: WebClien
411411
# Split out citation block if present
412412
# Citations are not returned in the object without using `$output_format_instructions$` which overrides the
413413
# system prompt. Instead, pull out and format the citations in the prompt manually
414-
prompt_value_keys = ["source number", "title", "filename", "reference text", "link"]
414+
prompt_value_keys = [
415+
"source number",
416+
"title",
417+
"link",
418+
"filename",
419+
"reference text",
420+
]
415421
split = response_text.split("------") # Citations are separated by ------
416422

417423
citations: list[dict[str, str]] = []
@@ -608,28 +614,33 @@ def open_citation(channel: str, timestamp: str, message: Any, params: Dict[str,
608614
# Get Message
609615
try:
610616
# Get citation details
611-
title = params.get("title", "No title available.")
612-
body = params.get("body", "No citation text available.")
613-
link = params.get("link", "")
617+
title: str = params.get("title", "No title available.")
618+
body: str = params.get("body", "No citation text available.", "No source found")
619+
link: str = params.get("link", "")
614620

615621
blocks = message.get("blocks", [])
616622

617623
# Remove citation block (and divider), if it exists
618624
blocks = [block for block in blocks if block.get("block_id") not in ["citation_block", "citation_divider"]]
619625

626+
# Add formatting
627+
title = f"## {title}" # Add title styling
628+
body = f"> {body.replace("\n", "\n> ")}" # And block quote section
629+
link = f"[link]({link})" # Make link clickable
630+
620631
# Add citation content before feedback block
621632
citation_block = {
622633
"type": "section",
623634
"text": {
624-
"type": "mrkdwn",
625-
"text": f"*{title}*\n\n{body}\n\n<{link}|View Source>" if link else f"*{title}*\n\n{body}",
635+
"type": "markdown",
636+
"text": f"{title}\n\n{body}\n\n<{link}|View Source>" if link else f"*{title}*\n\n{body}",
626637
},
627638
"block_id": "citation_block",
628639
}
629640

630641
# Find index of feedback block to insert before it
631642
feedback_block_index = next(
632-
(i for i, block in enumerate(blocks) if block.get("block_id") == "feedback_block"), len(blocks)
643+
(i for i, block in enumerate(blocks) if block.get("block_id") == "feedback-divider"), len(blocks)
633644
)
634645
blocks.insert(feedback_block_index, {"type": "divider", "block_id": "citation_divider"})
635646
blocks.insert(feedback_block_index, citation_block)

0 commit comments

Comments
 (0)