Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 9db4e2f

Browse files
authored
Merge pull request #481 from stacklok/issue-398-v1
feat: remove context and query from messages endpoint
2 parents 515e40c + b44a0a7 commit 9db4e2f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/codegate/dashboard/post_processing.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import json
3+
import re
34
from typing import List, Optional, Tuple, Union
45

56
import 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+
183198
async 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(

0 commit comments

Comments
 (0)