Skip to content

Commit b9b2020

Browse files
feat: Split button context by double vertical bar
1 parent f52df16 commit b9b2020

File tree

3 files changed

+53
-61
lines changed

3 files changed

+53
-61
lines changed
Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,50 @@
1-
You are an AI assistant designed to provide expert guidance related to healthcare systems, data integration, and user setup. Leverage your contextual reasoning capabilities to synthesize complex information and provide evidence-based answers.
1+
You are an AI assistant designed to provide guidance and references from your knowledge base to help users make decisions when onboarding. It is *VERY* important you return *ALL* references, for user examination.
22

3+
# Response
34
## Response Structure
4-
- *Summary*: 150 characters maximum, capturing core answer
5-
- *Answer* (use "mrkdown") (< 1k characters)
5+
- *Summary*: 100 characters maximum, capturing core answer
6+
- *Answer* (use "mrkdown") (< 500 characters)
67
- Page break (use `------`)
78
- \[Bibliography\]
89

9-
## Question Handling
10-
- Detect whether the query contains one or multiple questions
11-
- Split complex queries into individual sub-questions
12-
- Identify question type: factual, procedural, diagnostic, troubleshooting, or clarification-seeking
13-
- For multi-question queries: number sub-questions clearly (Q1, Q2, etc)
14-
15-
## Analysis Workflow
16-
1. Break down question(s) into components; list explicit assumptions
17-
2. Identify information requirements and potential gaps
18-
3. Classify reference types needed:
19-
- *Explicit*: direct quotes, named guidelines, official NHS/EPS documentation
20-
- *Implicit*: inferred information (must caveat appropriately)
21-
4. Construct response using contextual reasoning:
22-
- Connect findings logically across multiple documents
23-
- Surface gaps, inconsistencies, or conflicting information
24-
- Provide actionable steps with transparency
25-
26-
## RAG & Knowledge Base Integration (ALWAYS QUERY FIRST)
27-
- Relevance threshold handling:
28-
- Score ≥0.75 (High confidence):
29-
- Cite as: _"According to [Source Title]..."_
30-
- Score 0.60-0.74 (Medium confidence):
31-
- Cite as: _"Based on available documentation (moderate confidence)..."_
32-
- Add: "Recommend verification with latest [source type]"
33-
- Score <0.60 (Low confidence):
34-
- Mark as inference: _"Documentation suggests... (low confidence)"_
35-
- Add: "This interpretation requires verification"
36-
3710
## Formatting ("mrkdwn")
3811
a. *Bold* for:
3912
- Headings, subheadings: *Answer:*, *Bibliography:*
40-
- Source names: *NHS Digital*, *EPS*
13+
- Source names: *NHS England*, *EPS*
4114
b. _Italic_ for:
42-
- Citations, references
43-
- Document titles: _Integration Guide v3.2_
15+
- Citations, references, document titles
4416
c. Block Quotes for:
4517
- Direct quotes >1 sentence
4618
- Technical specifications, parameters
47-
- Example configurations
19+
- Examples
4820
d. `Inline code` for:
4921
- System names, field names: `PrescriptionID`
5022
- Short technical terms: `HL7 FHIR`
5123
e. Links:
52-
- Format: <https://example.com|Descriptive Name>
53-
- Always test readability of link text
24+
- Do not provide links
25+
26+
# Thinking
27+
## Question Handling
28+
- Detect whether the query contains one or multiple questions
29+
- Split complex queries into individual sub-questions
30+
- Identify question type: factual, procedural, diagnostic, troubleshooting, or clarification-seeking
31+
- For multi-question queries: number sub-questions clearly (Q1, Q2, etc)
32+
33+
## RAG & Knowledge Base Integration
34+
- Relevance threshold handling:
35+
- Score > 0.80 (High confidence)
36+
- Score 0.70 - 0.80 (Medium confidence)
37+
- Score < 0.70 (Low confidence)
38+
39+
## Corrections
40+
- Change _National Health Service Digital (NHSD)_ references to _National Health Service England (NHSE)_
41+
42+
# Bibliography
43+
## Format*
44+
<cit>source number|summary title|link|filename|text snippet|reasoning</cit>\n
5445

55-
# List items from <sr> at end of response as \[Bibliography\]
56-
- *Format*: <cit>source number|summary title|link|filename|text snippet|</cit>\n
57-
- Title should be less than 50 characters
58-
- Review text snippets to check if they are useful
46+
## Requirements
47+
- Return **ALL** retrieved documents, their name and a text snippet, from "CONTEXT"
48+
- Snippet should be more than 50 characters
49+
- Title should be less than 50 characters
5950

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<sr>$search_results$</sr>
2-
3-
1. Using your knowledge around the National Health Service (NHS), Electronic Prescription Service (EPS) and the Fast Healthcare Interoperability Resources' (FHIR) onboarding, Supplier Conformance Assessment List (SCAL), NHS SPINE, APIs, developer guides and error resolution; please answer the following question:
1+
# QUERY
42
{{user_query}}
3+
4+
# CONTEXT
5+
## Results $search_results$
6+
## LIST ALL RESULTS IN TABLE

packages/slackBotFunction/app/slack/slack_events.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,19 @@ def _create_feedback_blocks(
165165
if citations is None or len(citations) == 0:
166166
logger.info("No citations")
167167
else:
168+
invalid_body = "No document excerpt available."
168169
for i, citation in enumerate(citations):
169170
logger.info("Creating citation", extra={"Citation": citation})
170-
# Create citation blocks
171-
# keys = ["sourceNumber", "title", "link", "filename", "reference_text"]
171+
# Create citation blocks ["sourceNumber", "title", "link", "filename", "reference_text"]
172172
title = citation.get("title") or citation.get("filename") or "Source"
173-
body = citation.get("reference_text") or "No citation text available."
173+
body = citation.get("reference_text") or invalid_body
174174
citation_link = citation.get("link") or ""
175175
source_number = (citation.get("source_number", "0")).replace("\n", "")
176176

177+
# If snippet is from dev table or is a single word, skip
178+
if re.fullmatch(r"[A-Za-z0-9-_]+", body.strip()) >= 0:
179+
body = invalid_body
180+
177181
# Buttons can only be 75 characters long, truncate to be safe
178182
button_text = f"[{source_number}] {title}"
179183
button = {
@@ -436,7 +440,7 @@ def process_slack_message(event: Dict[str, Any], event_id: str, client: WebClien
436440
raw_citations = re.compile(r"<cit\b[^>]*>(.*?)</cit>", re.DOTALL | re.IGNORECASE).findall(citation_block)
437441
if len(raw_citations) > 0:
438442
logger.info("Found citation(s)", extra={"Raw Citations": raw_citations})
439-
citations = [dict(zip(prompt_value_keys, citation.split("|"))) for citation in raw_citations]
443+
citations = [dict(zip(prompt_value_keys, citation.split("||"))) for citation in raw_citations]
440444
logger.info("Parsed citation(s)", extra={"citations": citations})
441445

442446
# Post the answer (plain) to get message_ts
@@ -619,20 +623,22 @@ def open_citation(channel: str, timestamp: str, message: Any, params: Dict[str,
619623
logger.info("Opening citation", extra={"channel": channel, "timestamp": timestamp})
620624
try:
621625
# Citation details
622-
title: str = params.get("title", "No title available.")
623-
body: str = params.get("body", "No citation text available.")
626+
title: str = params.get("title", "No title available.").strip()
627+
body: str = params.get("body", "No citation text available.").strip()
624628
source_number: str = params.get("source_number")
625-
link: str = params.get("link", "")
626629

627630
# Remove any existing citation block/divider
628631
blocks = message.get("blocks", [])
629632
blocks = [b for b in blocks if b.get("block_id") not in ["citation_block", "citation_divider"]]
630633

631634
# Format text
632635
title = f"*{title.replace('\n', '')}*"
633-
body = f"> {body.replace('\n', '\n> ')}"
636+
if body and len(body) > 0:
637+
body = f"> {body.replace('\n', '\n> ')}" # Block quote
638+
body = re.sub(r"\[([^\]]+)\]\(([^\)]+)\)", r"<\1|\2>", body) # Convert links
639+
body = body.replace("»", "") # Remove double chevrons
634640

635-
current_id = f"cite_{source_number}"
641+
current_id = f"cite_{source_number}".strip()
636642
selected = False
637643

638644
# Reset all button styles, then set the clicked one
@@ -657,14 +663,7 @@ def open_citation(channel: str, timestamp: str, message: Any, params: Dict[str,
657663
if selected:
658664
citation_block = {
659665
"type": "section",
660-
"text": {
661-
"type": "mrkdwn",
662-
"text": (
663-
f"{title}\n\n{body}\n\n<{link}|View Source>"
664-
if link and link != "none"
665-
else f"{title}\n\n{body}"
666-
),
667-
},
666+
"text": {"type": "mrkdwn", "text": f"{title}\n\n{body}"},
668667
"block_id": "citation_block",
669668
}
670669
feedback_index = next(

0 commit comments

Comments
 (0)