mtyrrell commited on
Commit
f32f200
·
1 Parent(s): 6eb6385

sources fix

Browse files
Files changed (1) hide show
  1. src/components/generator/sources.py +12 -6
src/components/generator/sources.py CHANGED
@@ -1,9 +1,7 @@
1
  import re
2
  import logging
3
  logger = logging.getLogger(__name__)
4
- from typing import List, Dict, Any, Union, Optional, Tuple
5
- import ast
6
- from langchain_core.messages import SystemMessage, HumanMessage
7
  from langchain_core.documents import Document
8
 
9
 
@@ -11,10 +9,18 @@ from langchain_core.documents import Document
11
  # Core Processing Functions
12
  # ---------------------------------------------------------------------
13
  def parse_citations(response: str) -> List[int]:
14
- """Parse citation numbers from response text"""
15
- citation_pattern = r'\[(\d+)\]'
 
16
  matches = re.findall(citation_pattern, response)
17
- citation_numbers = sorted(list(set(int(match) for match in matches)))
 
 
 
 
 
 
 
18
  logger.debug(f"Probable Citations found: {citation_numbers}")
19
  return citation_numbers
20
 
 
1
  import re
2
  import logging
3
  logger = logging.getLogger(__name__)
4
+ from typing import List, Dict, Any, Optional, Tuple
 
 
5
  from langchain_core.documents import Document
6
 
7
 
 
9
  # Core Processing Functions
10
  # ---------------------------------------------------------------------
11
  def parse_citations(response: str) -> List[int]:
12
+ """Parse citation numbers from response text, handling both [1] and [1,2,3] formats"""
13
+ # Match both single citations [1] and comma-separated citations [1,2,3,4,5]
14
+ citation_pattern = r'\[([\d,\s]+)\]'
15
  matches = re.findall(citation_pattern, response)
16
+
17
+ citation_numbers = set()
18
+ for match in matches:
19
+ # Split by comma and extract all numbers
20
+ numbers = re.findall(r'\d+', match)
21
+ citation_numbers.update(int(num) for num in numbers)
22
+
23
+ citation_numbers = sorted(list(citation_numbers))
24
  logger.debug(f"Probable Citations found: {citation_numbers}")
25
  return citation_numbers
26