Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions backend/models/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@ def conversations_to_string(

return "\n\n---------------------\n\n".join(result).strip()

def get_transcript(self, include_timestamps: bool, people: List[Person] = None) -> str:
def get_transcript(self, include_timestamps: bool, people: List[Person] = None, user_name: str = None) -> str:
# Warn: missing transcript for workflow source, external integration source
return TranscriptSegment.segments_as_string(
self.transcript_segments, include_timestamps=include_timestamps, people=people
self.transcript_segments, include_timestamps=include_timestamps, user_name=user_name, people=people
)

def get_photos_descriptions(self, include_timestamps: bool = False) -> str:
Expand Down Expand Up @@ -450,9 +450,9 @@ class CreateConversation(BaseModel):
processing_conversation_id: Optional[str] = None
calendar_meeting_context: Optional[CalendarMeetingContext] = None

def get_transcript(self, include_timestamps: bool, people: List[Person] = None) -> str:
def get_transcript(self, include_timestamps: bool, people: List[Person] = None, user_name: str = None) -> str:
return TranscriptSegment.segments_as_string(
self.transcript_segments, include_timestamps=include_timestamps, people=people
self.transcript_segments, include_timestamps=include_timestamps, user_name=user_name, people=people
)

def get_person_ids(self) -> List[str]:
Expand Down
10 changes: 7 additions & 3 deletions backend/utils/conversations/process_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def _get_structured(
conversation: Union[Conversation, CreateConversation, ExternalIntegrationCreateConversation],
force_process: bool = False,
people: List[Person] = None,
user_name: str = None,
) -> Tuple[Structured, bool]:
try:
tz = notification_db.get_user_time_zone(uid)
Expand Down Expand Up @@ -139,7 +140,7 @@ def _get_structured(
# not supported conversation source
raise HTTPException(status_code=400, detail=f'Invalid conversation source: {conversation.text_source}')

transcript_text = conversation.get_transcript(False, people=people)
transcript_text = conversation.get_transcript(False, people=people, user_name=user_name)

# For re-processing, we don't discard, just re-structure.
if force_process:
Expand Down Expand Up @@ -345,7 +346,7 @@ def _trigger_apps(
def execute_app(app):
with track_usage(uid, Features.CONVERSATION_APPS):
result = get_app_result(
conversation.get_transcript(False, people=people), conversation.photos, app, language_code=language_code
conversation.get_transcript(False, people=people, user_name=user_name), conversation.photos, app, language_code=language_code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user_name undefined here - will cause NameError

user_name is not a parameter of _trigger_apps() nor is it defined in the function scope. When execute_app runs, it will raise NameError: name 'user_name' is not defined.

Fix needed:

  1. Add user_name: str = None parameter to _trigger_apps() signature (line 286)
  2. Pass user_name=user_name when calling _trigger_apps() (line 696)
def _trigger_apps(
    uid: str,
    conversation: Conversation,
    is_reprocess: bool = False,
    app_id: Optional[str] = None,
    language_code: str = 'en',
    people: List[Person] = None,
    user_name: str = None,  # Add this
):

And at line 696:

_trigger_apps(
    uid, conversation, is_reprocess=is_reprocess, app_id=app_id, 
    language_code=language_code, people=people, user_name=user_name
)

).strip()
conversation.apps_results.append(AppResult(app_id=app.id, content=result))
if not is_reprocess:
Expand Down Expand Up @@ -631,7 +632,10 @@ def process_conversation(
people_data = users_db.get_people_by_ids(uid, list(set(person_ids)))
people = [Person(**p) for p in people_data]

structured, discarded = _get_structured(uid, language_code, conversation, force_process, people=people)
from database.auth import get_user_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move import to module level per coding standards

The import is inside the function, violating rule 40d2fa4f (Backend Python import rules - no in-function imports). While this file has other in-function imports, best practice is to import at the module level.

Move to top of file:

Suggested change
from database.auth import get_user_name
from database.auth import get_user_name

Context Used: Rule from dashboard - Backend Python import rules - no in-function imports, follow module hierarchy (source)

user_name = get_user_name(uid)

structured, discarded = _get_structured(uid, language_code, conversation, force_process, people=people, user_name=user_name)
conversation = _get_conversation_obj(uid, structured, conversation)

# AI-based folder assignment
Expand Down