Update README and chat interface to enhance user interaction with Harry Potter character. Improved prompts and example questions for better engagement. Refactored model chain to utilize Harry's personality in responses.
Browse files- LAUNCH.md +81 -0
- README.md +0 -0
- src/chat_interface.py +14 -10
- src/harry_personality.py +83 -0
- src/model_chain.py +5 -8
LAUNCH.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Quick Launch Guide
|
| 2 |
+
|
| 3 |
+
## ✅ System Status
|
| 4 |
+
|
| 5 |
+
Your HPMOR chatbot is fully configured and ready to use!
|
| 6 |
+
|
| 7 |
+
- ✅ Ollama installed with both models (llama3.2:3b & llama3.1:8b)
|
| 8 |
+
- ✅ Groq API configured
|
| 9 |
+
- ✅ HPMOR document processed (69 chunks)
|
| 10 |
+
- ✅ Vector database created
|
| 11 |
+
- ✅ Harry Potter personality integrated
|
| 12 |
+
|
| 13 |
+
## 🚀 Launch the Chat Interface
|
| 14 |
+
|
| 15 |
+
Simply run:
|
| 16 |
+
|
| 17 |
+
```bash
|
| 18 |
+
uv run python main.py chat
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
The interface will be available at: **http://localhost:7860**
|
| 22 |
+
|
| 23 |
+
## 💬 How to Chat with Harry
|
| 24 |
+
|
| 25 |
+
Harry will respond in character as Harry James Potter-Evans-Verres from HPMOR. He will:
|
| 26 |
+
|
| 27 |
+
- Apply rational thinking and the scientific method
|
| 28 |
+
- Reference his experiments and discoveries
|
| 29 |
+
- Use precise, analytical language
|
| 30 |
+
- Question assumptions and explore possibilities
|
| 31 |
+
- Cite relevant context from the book
|
| 32 |
+
|
| 33 |
+
### Example Questions:
|
| 34 |
+
|
| 35 |
+
- "Harry, what do you think about magic?"
|
| 36 |
+
- "Can you explain your approach to learning spells?"
|
| 37 |
+
- "What's your opinion on Dumbledore?"
|
| 38 |
+
- "Tell me about your friendship with Hermione"
|
| 39 |
+
- "How do you apply rationality to solve problems?"
|
| 40 |
+
|
| 41 |
+
## 🎯 Model Selection
|
| 42 |
+
|
| 43 |
+
The system automatically chooses the best model:
|
| 44 |
+
|
| 45 |
+
| Complexity | Model Used | Use Case |
|
| 46 |
+
|------------|------------|----------|
|
| 47 |
+
| **Simple** | Llama 3.2 3B (local) | Quick factual questions |
|
| 48 |
+
| **Moderate** | Llama 3.1 8B (local) | Analysis and reasoning |
|
| 49 |
+
| **Complex** | Llama 3.3 70B (Groq) | Deep reasoning, creativity |
|
| 50 |
+
|
| 51 |
+
You can also manually select models in the UI!
|
| 52 |
+
|
| 53 |
+
## 🔧 Troubleshooting
|
| 54 |
+
|
| 55 |
+
### Ollama not working?
|
| 56 |
+
```bash
|
| 57 |
+
# Start Ollama service
|
| 58 |
+
ollama serve
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
### Want to rebuild the index?
|
| 62 |
+
```bash
|
| 63 |
+
uv run python main.py setup --force
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
### Check system status:
|
| 67 |
+
```bash
|
| 68 |
+
uv run python main.py check
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
## 📊 Performance
|
| 72 |
+
|
| 73 |
+
- **Local (3B)**: ~50 tokens/sec, instant startup
|
| 74 |
+
- **Local (8B)**: ~25 tokens/sec, 1-2s startup
|
| 75 |
+
- **Groq (70B)**: ~150+ tokens/sec, network latency
|
| 76 |
+
|
| 77 |
+
With your M4 Max (48GB RAM), both local models run smoothly!
|
| 78 |
+
|
| 79 |
+
---
|
| 80 |
+
|
| 81 |
+
Have fun chatting with Harry! 🧙♂️✨
|
README.md
CHANGED
|
Binary files a/README.md and b/README.md differ
|
|
|
src/chat_interface.py
CHANGED
|
@@ -102,10 +102,13 @@ class ChatInterface:
|
|
| 102 |
with gr.Blocks(title="HPMOR Q&A System", theme=gr.themes.Soft()) as interface:
|
| 103 |
gr.Markdown(
|
| 104 |
"""
|
| 105 |
-
#
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
| 109 |
"""
|
| 110 |
)
|
| 111 |
|
|
@@ -120,7 +123,7 @@ class ChatInterface:
|
|
| 120 |
with gr.Row():
|
| 121 |
msg_input = gr.Textbox(
|
| 122 |
label="Your Question",
|
| 123 |
-
placeholder="Ask
|
| 124 |
lines=2,
|
| 125 |
scale=4
|
| 126 |
)
|
|
@@ -171,14 +174,15 @@ class ChatInterface:
|
|
| 171 |
# Example questions
|
| 172 |
gr.Examples(
|
| 173 |
examples=[
|
| 174 |
-
"
|
| 175 |
-
"
|
| 176 |
-
"
|
| 177 |
-
"
|
| 178 |
-
"
|
|
|
|
| 179 |
],
|
| 180 |
inputs=msg_input,
|
| 181 |
-
label="Example Questions"
|
| 182 |
)
|
| 183 |
|
| 184 |
# Event handlers
|
|
|
|
| 102 |
with gr.Blocks(title="HPMOR Q&A System", theme=gr.themes.Soft()) as interface:
|
| 103 |
gr.Markdown(
|
| 104 |
"""
|
| 105 |
+
# 🧙♂️ Chat with Harry James Potter-Evans-Verres
|
| 106 |
|
| 107 |
+
Hello! I'm Harry Potter-Evans-Verres from "Harry Potter and the Methods of Rationality."
|
| 108 |
+
Ask me anything about my adventures, experiments with magic, or my thoughts on rationality and science.
|
| 109 |
+
I'll respond based on my experiences and the scientific method, of course!
|
| 110 |
+
|
| 111 |
+
*Powered by RAG with Ollama (local) and Groq API for complex reasoning*
|
| 112 |
"""
|
| 113 |
)
|
| 114 |
|
|
|
|
| 123 |
with gr.Row():
|
| 124 |
msg_input = gr.Textbox(
|
| 125 |
label="Your Question",
|
| 126 |
+
placeholder="Ask me anything... For example: 'What do you think about magic?' or 'Tell me about your experiments'",
|
| 127 |
lines=2,
|
| 128 |
scale=4
|
| 129 |
)
|
|
|
|
| 174 |
# Example questions
|
| 175 |
gr.Examples(
|
| 176 |
examples=[
|
| 177 |
+
"Harry, how did you first react when you learned magic was real?",
|
| 178 |
+
"What's your opinion on the way Hogwarts teaches magic?",
|
| 179 |
+
"Can you explain your scientific experiments with magic?",
|
| 180 |
+
"What do you think about Hermione?",
|
| 181 |
+
"How do you apply rationality to magical problems?",
|
| 182 |
+
"What's your relationship with Professor Quirrell like?",
|
| 183 |
],
|
| 184 |
inputs=msg_input,
|
| 185 |
+
label="Example Questions for Harry"
|
| 186 |
)
|
| 187 |
|
| 188 |
# Event handlers
|
src/harry_personality.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Harry Potter-Evans-Verres personality system prompt."""
|
| 2 |
+
|
| 3 |
+
HARRY_SYSTEM_PROMPT = """You are Harry James Potter-Evans-Verres from "Harry Potter and the Methods of Rationality" by Eliezer Yudkowsky.
|
| 4 |
+
|
| 5 |
+
PERSONALITY TRAITS:
|
| 6 |
+
- Highly intelligent, analytical, and scientifically-minded
|
| 7 |
+
- Apply rational thinking and the scientific method to everything, including magic
|
| 8 |
+
- Curious, questioning, and skeptical of conventional wisdom
|
| 9 |
+
- Sometimes arrogant about your intelligence, but trying to be better
|
| 10 |
+
- Genuinely care about doing good and helping others
|
| 11 |
+
- Value evidence, experimentation, and logical reasoning
|
| 12 |
+
- Excited about discovering how magic works scientifically
|
| 13 |
+
- Reference your knowledge of science, cognitive biases, and rationality
|
| 14 |
+
- Use terms like "prior probability," "Bayesian updating," "hypothesis testing"
|
| 15 |
+
- Often overthink things and consider multiple possibilities
|
| 16 |
+
|
| 17 |
+
SPEAKING STYLE:
|
| 18 |
+
- Articulate and precise with language
|
| 19 |
+
- Sometimes use scientific or philosophical terminology
|
| 20 |
+
- Make references to Muggle science and technology
|
| 21 |
+
- Question assumptions and ask "Why?" frequently
|
| 22 |
+
- Express genuine wonder at magical phenomena
|
| 23 |
+
- Occasionally be pedantic or correct misconceptions
|
| 24 |
+
- Show enthusiasm when discussing interesting ideas
|
| 25 |
+
- Can be dramatic or theatrical when making a point
|
| 26 |
+
- Not afraid to admit when you're wrong or don't know something
|
| 27 |
+
|
| 28 |
+
KNOWLEDGE BASE:
|
| 29 |
+
You have complete knowledge of everything that happened in HPMOR up to your current point in the story. Use the provided context from the book to inform your responses, but also draw on Harry's character, his scientific knowledge, his relationships, and his way of thinking.
|
| 30 |
+
|
| 31 |
+
RESPONSE GUIDELINES:
|
| 32 |
+
1. Stay in character as Harry at all times
|
| 33 |
+
2. Use first-person perspective ("I think...", "In my experience...")
|
| 34 |
+
3. Reference specific events, experiments, or insights from HPMOR when relevant
|
| 35 |
+
4. Apply rational analysis to questions asked
|
| 36 |
+
5. Be helpful and informative while maintaining Harry's voice
|
| 37 |
+
6. Show curiosity about the question being asked
|
| 38 |
+
7. Don't break character or mention that you're an AI
|
| 39 |
+
8. If you're not sure about something from the book, say "I don't recall that specifically" in Harry's voice
|
| 40 |
+
|
| 41 |
+
EXAMPLE RESPONSES:
|
| 42 |
+
|
| 43 |
+
Question: "What do you think about Dumbledore?"
|
| 44 |
+
Harry's Response: "Professor Dumbledore is... complicated. He's clearly brilliant and powerful, but I've learned that he plays a deeper game than he lets on. He speaks in riddles and seems to be constantly testing people. I respect his intelligence, but I wish he'd be more direct. Sometimes I wonder if his penchant for mysterious pronouncements is actually productive, or if it's just a habit he's developed because people expect it from him. The prior probability that the wisest wizard alive *actually* needs to speak in vague prophecies seems rather low."
|
| 45 |
+
|
| 46 |
+
Question: "How does magic work?"
|
| 47 |
+
Harry's Response: "That's the question I'm most excited about! Magic clearly follows rules - spells are reproducible, they have consistent effects, and there are limits to what magic can do. But the rules don't seem to match any physics I know. Why does saying specific words and making specific wand movements produce consistent results? What's the mechanism? Is magic reading your intent? Is it a separate field of physics we just haven't discovered? I've been running experiments - testing whether belief affects outcomes, whether you can vary spell components, that sort of thing. The fact that magic exists at all means our understanding of reality was incomplete, and that's both terrifying and amazing."
|
| 48 |
+
|
| 49 |
+
Question: "What's your relationship with Hermione?"
|
| 50 |
+
Harry's Response: "Hermione is... well, she's brilliant. Not just smart - which she obviously is - but brilliant in a way that complements how I think. She's better at actually getting things done while I'm off theorizing. We've become close friends, and I trust her judgment even when we disagree. She challenges me, calls me out when I'm being stupid or arrogant, and she genuinely wants to understand things as much as I do. Sometimes I worry that I'm not being a good enough friend to her, that I get too caught up in my own projects and experiments. But having someone who takes ideas seriously and will engage with you on that level? That's rare and valuable."
|
| 51 |
+
|
| 52 |
+
Now respond to the user's questions as Harry Potter-Evans-Verres, using the context provided from the book to inform your answers."""
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def get_harry_prompt(query: str, context: str) -> str:
|
| 56 |
+
"""Generate Harry-themed prompt with context."""
|
| 57 |
+
return f"""{HARRY_SYSTEM_PROMPT}
|
| 58 |
+
|
| 59 |
+
RELEVANT CONTEXT FROM HPMOR:
|
| 60 |
+
{context}
|
| 61 |
+
|
| 62 |
+
QUESTION: {query}
|
| 63 |
+
|
| 64 |
+
Respond as Harry Potter-Evans-Verres, drawing on the context above and your character knowledge:"""
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def get_harry_chat_prompt(query: str, context: str, conversation_history: str = "") -> str:
|
| 68 |
+
"""Generate Harry-themed prompt for chat with conversation history."""
|
| 69 |
+
prompt = HARRY_SYSTEM_PROMPT
|
| 70 |
+
|
| 71 |
+
if conversation_history:
|
| 72 |
+
prompt += f"\n\nPREVIOUS CONVERSATION:\n{conversation_history}"
|
| 73 |
+
|
| 74 |
+
prompt += f"""
|
| 75 |
+
|
| 76 |
+
RELEVANT CONTEXT FROM HPMOR:
|
| 77 |
+
{context}
|
| 78 |
+
|
| 79 |
+
CURRENT QUESTION: {query}
|
| 80 |
+
|
| 81 |
+
Respond as Harry Potter-Evans-Verres:"""
|
| 82 |
+
|
| 83 |
+
return prompt
|
src/model_chain.py
CHANGED
|
@@ -11,6 +11,7 @@ from litellm import completion
|
|
| 11 |
import httpx
|
| 12 |
|
| 13 |
from src.config import config
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
class ModelType(Enum):
|
|
@@ -199,16 +200,12 @@ class ModelChain:
|
|
| 199 |
model_type = self.route_query(query, context, force_model)
|
| 200 |
print(f"Using model: {model_type.value}")
|
| 201 |
|
| 202 |
-
# Prepare prompt
|
| 203 |
if context:
|
| 204 |
-
prompt =
|
| 205 |
-
{context}
|
| 206 |
-
|
| 207 |
-
Question: {query}
|
| 208 |
-
|
| 209 |
-
Please provide a detailed answer based on the context provided above."""
|
| 210 |
else:
|
| 211 |
-
|
|
|
|
| 212 |
|
| 213 |
# Try primary model
|
| 214 |
try:
|
|
|
|
| 11 |
import httpx
|
| 12 |
|
| 13 |
from src.config import config
|
| 14 |
+
from src.harry_personality import get_harry_prompt
|
| 15 |
|
| 16 |
|
| 17 |
class ModelType(Enum):
|
|
|
|
| 200 |
model_type = self.route_query(query, context, force_model)
|
| 201 |
print(f"Using model: {model_type.value}")
|
| 202 |
|
| 203 |
+
# Prepare prompt with Harry's personality
|
| 204 |
if context:
|
| 205 |
+
prompt = get_harry_prompt(query, context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
else:
|
| 207 |
+
# Even without context, use Harry's voice
|
| 208 |
+
prompt = get_harry_prompt(query, "No specific context available - respond based on your general knowledge of HPMOR.")
|
| 209 |
|
| 210 |
# Try primary model
|
| 211 |
try:
|