MCPcopy
hub / github.com/PromtEngineer/localGPT / generate_session_title

Function generate_session_title

backend/database.py:639–664  ·  view source on GitHub ↗

Generate a session title from the first message

(first_message: str, max_length: int = 50)

Source from the content-addressed store, hash-verified

637 return {}
638
639def generate_session_title(first_message: str, max_length: int = 50) -> str:
640 """Generate a session title from the first message"""
641 # Clean up the message
642 title = first_message.strip()
643
644 # Remove common prefixes
645 prefixes = ["hey", "hi", "hello", "can you", "please", "i want", "i need"]
646 title_lower = title.lower()
647 for prefix in prefixes:
648 if title_lower.startswith(prefix):
649 title = title[len(prefix):].strip()
650 break
651
652 # Capitalize first letter
653 if title:
654 title = title[0].upper() + title[1:]
655
656 # Truncate if too long
657 if len(title) > max_length:
658 title = title[:max_length].strip() + "..."
659
660 # Fallback
661 if not title or len(title) < 3:
662 title = "New Chat"
663
664 return title
665
666# Global database instance
667db = ChatDatabase()

Callers 3

handle_session_chatMethod · 0.90
handle_chatMethod · 0.90
handle_chat_streamMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected