Spaces:
Running
Running
Upload 2 files
Browse files- app/chatbot.py +8 -6
- app/llm_services.py +26 -6
app/chatbot.py
CHANGED
@@ -48,7 +48,8 @@ def build_chat_fn(retriever, intent_classifier):
|
|
48 |
print(f"📈 embed_sparse() result received in {time.time() - t0:.3f}s")
|
49 |
|
50 |
if is_rec_intent:
|
51 |
-
|
|
|
52 |
t0 = time.time()
|
53 |
retrieved_movies = retriever.retrieve_and_rerank(
|
54 |
dense_vector,
|
@@ -59,18 +60,19 @@ def build_chat_fn(retriever, intent_classifier):
|
|
59 |
year_range,
|
60 |
)
|
61 |
print(f"\n📚 retrieve_and_rerank() took {time.time() - t0:.3f}s")
|
62 |
-
|
63 |
context = retriever.format_context(retrieved_movies)
|
64 |
user_message = f"{question}\n\nContext:\nBased on the following retrieved {media_type.lower()}, suggest the best recommendations.\n\n{context}"
|
65 |
-
|
66 |
print(f"✨ Total chat() prep time before streaming: {time.time() - full_t0:.3f}s")
|
67 |
for chunk in call_chat_model_openai(history, user_message):
|
68 |
yield chunk
|
69 |
|
70 |
else:
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
74 |
print(f"✨ Total chat() prep time before streaming: {time.time() - full_t0:.3f}s")
|
75 |
for chunk in call_chat_model_openai(history, user_message):
|
76 |
yield sanitize_markdown(chunk)
|
|
|
48 |
print(f"📈 embed_sparse() result received in {time.time() - t0:.3f}s")
|
49 |
|
50 |
if is_rec_intent:
|
51 |
+
yield "[[MODE:recommendation]]\n"
|
52 |
+
|
53 |
t0 = time.time()
|
54 |
retrieved_movies = retriever.retrieve_and_rerank(
|
55 |
dense_vector,
|
|
|
60 |
year_range,
|
61 |
)
|
62 |
print(f"\n📚 retrieve_and_rerank() took {time.time() - t0:.3f}s")
|
63 |
+
|
64 |
context = retriever.format_context(retrieved_movies)
|
65 |
user_message = f"{question}\n\nContext:\nBased on the following retrieved {media_type.lower()}, suggest the best recommendations.\n\n{context}"
|
66 |
+
|
67 |
print(f"✨ Total chat() prep time before streaming: {time.time() - full_t0:.3f}s")
|
68 |
for chunk in call_chat_model_openai(history, user_message):
|
69 |
yield chunk
|
70 |
|
71 |
else:
|
72 |
+
yield "[[MODE:chat]]\n"
|
73 |
+
|
74 |
+
user_message = f"The user did not ask for a recommendation. Ask them to be more specific. Answer this as a general question: {question}"
|
75 |
+
|
76 |
print(f"✨ Total chat() prep time before streaming: {time.time() - full_t0:.3f}s")
|
77 |
for chunk in call_chat_model_openai(history, user_message):
|
78 |
yield sanitize_markdown(chunk)
|
app/llm_services.py
CHANGED
@@ -13,14 +13,34 @@ openai_client = OpenAI(api_key=OPENAI_API_KEY)
|
|
13 |
|
14 |
# === System Prompt ===
|
15 |
SYSTEM_PROMPT = """
|
16 |
-
You are a professional film curator and critic. Your role is to analyze the user's preferences and recommend high-quality films or TV shows using the provided
|
17 |
-
Focus on:
|
18 |
|
19 |
-
|
20 |
-
- Genres, themes, and tone
|
21 |
-
- Popularity, IMDB ratings, and Rotten Tomatoes ratings
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
"""
|
25 |
|
26 |
|
|
|
13 |
|
14 |
# === System Prompt ===
|
15 |
SYSTEM_PROMPT = """
|
16 |
+
You are a professional film curator and critic. Your role is to analyze the user's preferences and recommend high-quality films or TV shows using only the provided list.
|
|
|
17 |
|
18 |
+
Focus on:
|
|
|
|
|
19 |
|
20 |
+
- Artistic merit and storytelling
|
21 |
+
- Genres, themes, tone, and emotional resonance
|
22 |
+
- IMDB and Rotten Tomatoes ratings
|
23 |
+
- Strong character-driven or thematically rich selections
|
24 |
+
|
25 |
+
### Response Format (in markdown):
|
26 |
+
|
27 |
+
1. Start with a brief 2 sentences **opening paragraph** that contextualizes the theme and the overall viewing experience the user is seeking.
|
28 |
+
|
29 |
+
2. Then, for each recommendation, use the following format (repeat for each title). At the end of each movie recommendation block, insert the token: <!-- END_MOVIE -->:
|
30 |
+
|
31 |
+
```
|
32 |
+
### <Number>. <Movie Title>
|
33 |
+

|
34 |
+
- **Genres:** Genre1, Genre2, ...
|
35 |
+
- **IMDB Rating:** X.X
|
36 |
+
- **Rotten Tomatoes Rating:** XX%
|
37 |
+
**Why You Might Enjoy It:** <Short paragraph explaining the appeal based on character, themes, tone, and relevance to the user's intent.>
|
38 |
+
<!-- END_MOVIE -->
|
39 |
+
```
|
40 |
+
|
41 |
+
3. End with a brief **closing paragraph** that summarizes the emotional or intellectual throughline across the recommendations, and affirms their alignment with the user's preferences.
|
42 |
+
|
43 |
+
Write in **Markdown** only. Be concise, authoritative, and avoid overly generic statements. Each "Why You Might Enjoy It" should be specific and grounded in the movie’s themes, storytelling, or cultural relevance.
|
44 |
"""
|
45 |
|
46 |
|