diff options
| author | karpathy <andrej.karpathy@gmail.com> | 2025-11-22 15:08:53 -0800 |
|---|---|---|
| committer | karpathy <andrej.karpathy@gmail.com> | 2025-11-22 15:08:53 -0800 |
| commit | 827bfd3d3ecc34ac5f6a21003c785460d1b02d2b (patch) | |
| tree | c291d2ebe0696621a8aad8927a2c570e8de2f5dc /backend/council.py | |
| parent | eb0eb26f4cefa4880c895ff017f312e8674f9b73 (diff) | |
Label maker add
Diffstat (limited to 'backend/council.py')
| -rw-r--r-- | backend/council.py | 38 |
1 files changed, 38 insertions, 0 deletions
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. |
