Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/codegate/dashboard/post_processing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import json
import re
from typing import List, Optional, Tuple, Union

import structlog
Expand Down Expand Up @@ -180,6 +181,20 @@ async def parse_get_prompt_with_output(
)


def parse_question_answer(input_text: str) -> str:
# given a string, detect if we have a pattern of "Context: xxx \n\nQuery: xxx" and strip it
pattern = r'^Context:.*?\n\n\s*Query:\s*(.*)$'

# Search using the regex pattern
match = re.search(pattern, input_text, re.DOTALL)

# If a match is found, return the captured group after "Query:"
if match:
return match.group(1)
else:
return input_text


async def match_conversations(
partial_conversations: List[Optional[PartialConversation]],
) -> List[Conversation]:
Expand All @@ -206,6 +221,8 @@ async def match_conversations(
for chat_id, sorted_convers in sorted_convers.items():
questions_answers = []
for partial_conversation in sorted_convers:
partial_conversation.question_answer.question.message = parse_question_answer(
partial_conversation.question_answer.question.message)
questions_answers.append(partial_conversation.question_answer)
conversations.append(
Conversation(
Expand Down