@@ -168,32 +168,38 @@ def _create_feedback_blocks(
168168 for i , citation in enumerate (citations ):
169169 logger .info ("Creating citation" , extra = {"Citation" : citation })
170170 # Create citation blocks
171- # keys = ["source number ", "title", "link", "filename", "reference text "]
171+ # keys = ["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 "No citation text available."
174174 citation_link = citation .get ("link" ) or ""
175- citation_number = citation .get ("source number " , 0 )
175+ source_number = citation .get ("source_number " , 0 )
176176
177177 # Buttons can only be 75 characters long, truncate to be safe
178- button_text = f"[{ citation_number } ] { title } "
178+ button_text = f"[{ source_number } ] { title } "
179179 button = {
180180 "type" : "button" ,
181181 "text" : {
182182 "type" : "plain_text" ,
183183 "text" : button_text if len (button_text ) < 75 else f"{ button_text [:70 ]} ..." ,
184184 },
185- "action_id" : f"cite_{ citation_number } " ,
185+ "action_id" : f"cite_{ source_number } " ,
186186 "value" : json .dumps (
187- {** feedback_data , "title" : title , "body" : body , "link" : citation_link },
187+ {
188+ ** feedback_data ,
189+ "source number" : source_number ,
190+ "title" : title ,
191+ "body" : body ,
192+ "link" : citation_link ,
193+ },
188194 separators = ("," , ":" ),
189195 ),
190196 }
191197 action_buttons .append (button )
192198
193199 # Update inline citations
194200 response_text = response_text .replace (
195- f"[cit_{ citation_number } ]" ,
196- f"<{ citation_link } |[{ citation_number } ]>" if citation_link else f"[{ citation_number } ]" ,
201+ f"[cit_{ source_number } ]" ,
202+ f"<{ citation_link } |[{ source_number } ]>" if citation_link else f"[{ source_number } ]" ,
197203 )
198204
199205 # Remove any citations that have not been returned
@@ -414,11 +420,11 @@ def process_slack_message(event: Dict[str, Any], event_id: str, client: WebClien
414420 # Citations are not returned in the object without using `$output_format_instructions$` which overrides the
415421 # system prompt. Instead, pull out and format the citations in the prompt manually
416422 prompt_value_keys = [
417- "source number " ,
423+ "source_number " ,
418424 "title" ,
419425 "link" ,
420426 "filename" ,
421- "reference text " ,
427+ "reference_text " ,
422428 ]
423429 split = response_text .split ("------" ) # Citations are separated by ------
424430
@@ -619,16 +625,21 @@ def open_citation(channel: str, timestamp: str, message: Any, params: Dict[str,
619625 title : str = params .get ("title" , "No title available." )
620626 body : str = params .get ("body" , "No citation text available." )
621627 link : str = params .get ("link" , "" )
628+ source_number : str = params .get ("source_number" )
622629
623630 blocks = message .get ("blocks" , [])
631+ new_button_block = '"style": "primary",'
624632
625633 # Remove citation block (and divider), if it exists
626634 blocks = [block for block in blocks if block .get ("block_id" ) not in ["citation_block" , "citation_divider" ]]
627635
628636 # Add formatting
629- title = f"## { title } " # Add title styling
630- body = f"> { body .replace ("\n " , "\n > " )} " # And block quote section
631- link = f"[link]({ link } )" # Make link clickable
637+ title = f"*{ title } *"
638+ body = f"> { body .replace ("\n " , "\n > " ).replace (new_button_block , "" )} "
639+
640+ # Highlight selected citation
641+ i = body .find (f'"action_id": "cit_{ source_number } ",\n ' )
642+ body = body [:i ] + new_button_block + body [i :]
632643
633644 # Add citation content before feedback block
634645 citation_block = {
0 commit comments