Skip to content

Commit

Permalink
feat: remove context and query from messages endpoint
Browse files Browse the repository at this point in the history
When sending the initial message to the dashboard endpoint, strip
the initial prefixes with context and query

Closes: #398
  • Loading branch information
yrobla committed Jan 2, 2025
1 parent 6d619f2 commit b44a0a7
Showing 1 changed file with 17 additions and 0 deletions.
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

0 comments on commit b44a0a7

Please sign in to comment.