isayahc commited on
Commit
a19d954
1 Parent(s): e3a5dff

added extract reponse

Browse files
Files changed (1) hide show
  1. rag_app/utils/utils.py +25 -2
rag_app/utils/utils.py CHANGED
@@ -2,7 +2,7 @@ import hashlib
2
  import datetime
3
  import os
4
  import uuid
5
-
6
  # from rag_app.utils import logger
7
 
8
  # logger = logger.get_console_logger("utils")
@@ -112,4 +112,27 @@ def generate_uuid() -> str:
112
  Returns:
113
  str: A UUID string.
114
  """
115
- return str(uuid.uuid4())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import datetime
3
  import os
4
  import uuid
5
+ from typing import Dict
6
  # from rag_app.utils import logger
7
 
8
  # logger = logger.get_console_logger("utils")
 
112
  Returns:
113
  str: A UUID string.
114
  """
115
+ return str(uuid.uuid4())
116
+
117
+ def extract_responses(text: str) -> Dict[str, str]:
118
+ """
119
+ Extracts the user response and AI response from the provided text.
120
+
121
+ Args:
122
+ text (str): The input text containing user and AI responses.
123
+
124
+ Returns:
125
+ Dict[str, str]: A dictionary with keys 'USER' and 'AI' containing the respective responses.
126
+ """
127
+ user_pattern = re.compile(r'USER: (.*?) \n', re.DOTALL)
128
+ ai_pattern = re.compile(r'AI: (.*?)$', re.DOTALL)
129
+
130
+ user_match = user_pattern.search(text)
131
+ ai_match = ai_pattern.search(text)
132
+
133
+ responses = {
134
+ "USER": user_match.group(1) if user_match else "",
135
+ "AI": ai_match.group(1) if ai_match else ""
136
+ }
137
+
138
+ return responses