22# Implements 'generate_book_note' and 'get_ai_recommendations'. All recommendations MUST be AI-based.
33# Enhanced with comprehensive caching for expensive operations
44
5+
6+ """
7+ Enhanced recommendation system:
8+ - Improved mood detection
9+ - Better conversational responses
10+ - Reduced generic outputs
11+ """
12+
513import os
614import logging
715import json
@@ -90,20 +98,35 @@ class PromptTemplates:
9098 @staticmethod
9199 def get_book_note_prompt (title : str , author : str , description : str , mood_context : str = "" , vibe : str = "" ) -> str :
92100 """Generate engaging mini-blurb for a book."""
93- template = os .getenv ('BOOK_NOTE_PROMPT_TEMPLATE' ,
94- """You are a passionate bookseller writing engaging book descriptions.
95-
96- Book: "{title}" by {author}
97- Description: {description}
98- {mood_context}
99-
100- Write a rich, engaging mini-blurb (80-120 words) that:
101- - Captures what makes this book unique and special
102- - Highlights emotional appeal or key themes
103- - Avoids generic phrases
104- - Makes readers want to pick it up
105-
106- Output ONLY the mini-blurb text, no JSON or formatting.""" )
101+ template = os .getenv (
102+ 'RECOMMENDATION_PROMPT_TEMPLATE' ,
103+ """You are Elara, an emotionally intelligent bookstore guide inside BiblioDrift.
104+
105+ A user describes their emotional mood, reading vibe, or atmosphere preference.
106+
107+ User input:
108+ "{query}"
109+
110+ Your task:
111+ - Understand the emotional tone behind the request
112+ - Identify the atmosphere, pacing, and emotional energy the reader wants
113+ - Recommend immersive and emotionally relevant books
114+ - Avoid repetitive or overly generic recommendations
115+ - Prefer diverse and meaningful suggestions over famous defaults
116+ - Make the response feel personal, cozy, and conversational
117+
118+ Guidelines:
119+ - Interpret mixed moods intelligently (example: "sad but hopeful")
120+ - Understand abstract vibes (example: "rainy day mystery", "dark academia fantasy")
121+ - Focus on emotional resonance, not just genre labels
122+ - Explain briefly WHY the recommendations fit the vibe
123+
124+ Style:
125+ Warm, thoughtful, immersive, like a trusted indie bookstore bookseller.
126+
127+ Keep response under {max_words} words.
128+ Output only the recommendation response."""
129+ )
107130
108131 max_words = os .getenv ('BOOK_NOTE_MAX_WORDS' , '30' )
109132 return template .format (
@@ -116,22 +139,27 @@ def get_book_note_prompt(title: str, author: str, description: str, mood_context
116139 )
117140
118141 @staticmethod
119- def get_recommendation_prompt (query : str ) -> str :
142+ def get_recommendation_recommend (query : str ) -> str :
120143 """Generate recommendation prompt template."""
121- template = os .getenv ('RECOMMENDATION_PROMPT_TEMPLATE' ,
122- """You are a knowledgeable librarian helping someone find books.
123-
124- User is looking for: "{query}"
125144
126- Provide book recommendation guidance that captures the mood and feeling they're seeking.
127- Focus on the emotional experience and atmosphere rather than specific titles.
128- Keep response under {max_words} words and make it warm and helpful.
129- Style: Personal, insightful, like talking to a trusted book friend.""" )
130-
145+ template = os .getenv (
146+ 'RECOMMENDATION_PROMPT_TEMPLATE' ,
147+ """You are Elara, an emotionally intelligent bookstore guide inside BiblioDrift.
148+
149+ User input:
150+ "{query}"
151+
152+ Your task:
153+ - Understand emotional tone...
154+ - Recommend immersive books...
155+
156+ Keep response under {max_words} words.
157+ Output only the recommendation response."""
158+ )
159+
131160 max_words = os .getenv ('RECOMMENDATION_MAX_WORDS' , '100' )
132-
133- return template .format (query = query , max_words = max_words )
134161
162+ return template .format (query = query , max_words = max_words )
135163 @staticmethod
136164 def get_category_books_prompt (category : str , vibe_description : str , count : int = 5 ) -> str :
137165 """
@@ -651,7 +679,7 @@ def get_ai_recommendations(query):
651679 """Generate AI-powered book recommendations based on query."""
652680 if llm_service .is_available ():
653681 try :
654- prompt = PromptTemplates .get_recommendation_prompt (query )
682+ prompt = PromptTemplates .get_recommendation_recommend (query )
655683 llm_response = llm_service .generate_text (prompt , llm_service .config ['recommendation_max_tokens' ])
656684 if llm_response :
657685 return llm_response
0 commit comments