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 1
1
import asyncio
2
2
import json
3
+ import re
3
4
from typing import List , Optional , Tuple , Union
4
5
5
6
import structlog
@@ -180,6 +181,20 @@ async def parse_get_prompt_with_output(
180
181
)
181
182
182
183
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
+
183
198
async def match_conversations (
184
199
partial_conversations : List [Optional [PartialConversation ]],
185
200
) -> List [Conversation ]:
@@ -206,6 +221,8 @@ async def match_conversations(
206
221
for chat_id , sorted_convers in sorted_convers .items ():
207
222
questions_answers = []
208
223
for partial_conversation in sorted_convers :
224
+ partial_conversation .question_answer .question .message = parse_question_answer (
225
+ partial_conversation .question_answer .question .message )
209
226
questions_answers .append (partial_conversation .question_answer )
210
227
conversations .append (
211
228
Conversation (
You can’t perform that action at this time.
0 commit comments