Skip to content

Commit

Permalink
Fix chat with files on getting formated message (#1878)
Browse files Browse the repository at this point in the history
  • Loading branch information
beastoin authored Feb 25, 2025
2 parents 6f09659 + b59df46 commit d535a25
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
5 changes: 1 addition & 4 deletions backend/models/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class FileChat(BaseModel):
deleted: bool = False
thumb_name: Optional[str] = ""


def is_image(self):
return self.mime_type.startswith("image")

Expand Down Expand Up @@ -114,7 +113,7 @@ def get_sender_name(message: Message) -> str:
<content>
{message.text}
</content>
{f'<attachments>\n' + '\n'.join([f"<file>{file.name}</file>" for file in message.files]) + '\n</attachments>' if message.files else ''}
{('<attachments>' + ''.join(f"<file>{file.name}</file>" for file in message.files) + '</attachments>') if message.files and len(message.files) > 0 else ''}
</message>
""".replace(' ', '').replace('\n\n\n', '\n\n').strip()
for message in sorted_messages
Expand All @@ -123,7 +122,6 @@ def get_sender_name(message: Message) -> str:
return '\n'.join(formatted_messages)



class ResponseMessage(Message):
ask_for_nps: Optional[bool] = False

Expand Down Expand Up @@ -151,4 +149,3 @@ def add_file_ids(self, new_file_ids: List[str]):
def retrieve_new_file(self, file_ids) -> List:
existing_files = set(self.file_ids or [])
return list(set(file_ids) - existing_files)

1 change: 1 addition & 0 deletions backend/utils/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ class OutputQuestion(BaseModel):

def extract_question_from_conversation(messages: List[Message]) -> str:
# user last messages
print("extract_question_from_conversation")
user_message_idx = len(messages)
for i in range(len(messages) - 1, -1, -1):
if messages[i].sender == MessageSender.ai:
Expand Down
2 changes: 2 additions & 0 deletions backend/utils/retrieval/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class GraphState(TypedDict):


def determine_conversation(state: GraphState):
print("determine_conversation")
question = extract_question_from_conversation(state.get("messages", []))
print("determine_conversation parsed question:", question)

Expand All @@ -127,6 +128,7 @@ def determine_conversation_type(
state: GraphState,
) -> Literal["no_context_conversation", "context_dependent_conversation", "omi_question", "file_chat_question", "persona_question"]:
# chat with files by attachments on the last message
print("determine_conversation_type")
messages = state.get("messages", [])
if len(messages) > 0 and len(messages[-1].files_id) > 0:
return "file_chat_question"
Expand Down

0 comments on commit d535a25

Please sign in to comment.