This repository was archived by the owner on Jun 5, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 11import asyncio
22import json
3+ import re
34from typing import List , Optional , Tuple , Union
45
56import structlog
@@ -180,6 +181,20 @@ async def parse_get_prompt_with_output(
180181 )
181182
182183
184+ def parse_question_answer (input_text : str ) -> str :
185+ # given a string, detect if we have a pattern of "Context: xxx \n\nQuery: xxx" and strip it
186+ pattern = r'^Context:.*?\n\n\s*Query:\s*(.*)$'
187+
188+ # Search using the regex pattern
189+ match = re .search (pattern , input_text , re .DOTALL )
190+
191+ # If a match is found, return the captured group after "Query:"
192+ if match :
193+ return match .group (1 )
194+ else :
195+ return input_text
196+
197+
183198async def match_conversations (
184199 partial_conversations : List [Optional [PartialConversation ]],
185200) -> List [Conversation ]:
@@ -206,6 +221,8 @@ async def match_conversations(
206221 for chat_id , sorted_convers in sorted_convers .items ():
207222 questions_answers = []
208223 for partial_conversation in sorted_convers :
224+ partial_conversation .question_answer .question .message = parse_question_answer (
225+ partial_conversation .question_answer .question .message )
209226 questions_answers .append (partial_conversation .question_answer )
210227 conversations .append (
211228 Conversation (
You can’t perform that action at this time.
0 commit comments