From 827bfd3d3ecc34ac5f6a21003c785460d1b02d2b Mon Sep 17 00:00:00 2001 From: karpathy Date: Sat, 22 Nov 2025 15:08:53 -0800 Subject: Label maker add --- backend/council.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'backend/council.py') diff --git a/backend/council.py b/backend/council.py index b7f8839..5069abe 100644 --- a/backend/council.py +++ b/backend/council.py @@ -255,6 +255,44 @@ def calculate_aggregate_rankings( return aggregate +async def generate_conversation_title(user_query: str) -> str: + """ + Generate a short title for a conversation based on the first user message. + + Args: + user_query: The first user message + + Returns: + A short title (3-5 words) + """ + title_prompt = f"""Generate a very short title (3-5 words maximum) that summarizes the following question. +The title should be concise and descriptive. Do not use quotes or punctuation in the title. + +Question: {user_query} + +Title:""" + + messages = [{"role": "user", "content": title_prompt}] + + # Use gemini-2.5-flash for title generation (fast and cheap) + response = await query_model("google/gemini-2.5-flash", messages, timeout=30.0) + + if response is None: + # Fallback to a generic title + return "New Conversation" + + title = response.get('content', 'New Conversation').strip() + + # Clean up the title - remove quotes, limit length + title = title.strip('"\'') + + # Truncate if too long + if len(title) > 50: + title = title[:47] + "..." + + return title + + async def run_full_council(user_query: str) -> Tuple[List, List, Dict, Dict]: """ Run the complete 3-stage council process. -- cgit v1.2.3