Spaces:
Running
Running
File size: 16,452 Bytes
e90d887 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | """All mock responses and content for the NotebookLM prototype."""
import random
import time
import uuid
from datetime import datetime
from state import Artifact
# ββ Chat Mock Responses ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
MOCK_RESPONSES = [
{
"content": (
"Based on the uploaded sources, the key concept revolves around "
"the relationship between the variables discussed in Chapter 3. "
"The author emphasizes that understanding this foundation is critical "
"before moving to advanced topics."
),
"citations": [
{"source": "lecture_notes.pdf", "page": 3, "text": "the relationship between variables..."},
{"source": "textbook_ch3.pdf", "page": 42, "text": "understanding this foundation..."},
],
},
{
"content": (
"The sources indicate three main approaches to this problem:\n\n"
"1. **Direct method** β Apply the formula from Section 2.1\n"
"2. **Iterative approach** β Build up from base cases\n"
"3. **Approximation** β Use the simplified model when precision isn't critical\n\n"
"The textbook recommends starting with the direct method for beginners."
),
"citations": [
{"source": "textbook_ch2.pdf", "page": 15, "text": "direct method... apply the formula"},
],
},
{
"content": (
"I couldn't find specific information about that topic in your "
"uploaded sources. Try uploading additional materials that cover this "
"subject, or rephrase your question to relate more closely to the "
"content in your current sources."
),
"citations": [],
},
{
"content": (
"Great question! According to the lecture slides, this concept "
"was introduced in Week 5. The key takeaway is that the process involves "
"three stages: **initialization**, **processing**, and **validation**. "
"Each stage has specific requirements that must be met before proceeding."
),
"citations": [
{"source": "week5_slides.pptx", "page": 8, "text": "three stages: initialization..."},
{"source": "week5_slides.pptx", "page": 12, "text": "specific requirements..."},
],
},
]
def get_mock_response(query: str) -> dict:
time.sleep(1.2)
return random.choice(MOCK_RESPONSES)
# ββ Artifact Mock Content ββββββββββββββββββββββββββββββββββββββββββββββββββββ
MOCK_CONVERSATION_SUMMARY = {
"brief": """## Conversation Summary (Brief)
**Topics Discussed:**
- Relationship between core variables from Chapter 3
- Three problem-solving methodologies and when to use each
- The three-stage process (initialization β processing β validation)
**Key Questions Asked:**
- What are the main approaches to the problem? β Three methods identified
- How do the lecture notes differ from the textbook? β Application vs. theory
**Unresolved:** No questions remain open from the conversation.
""",
"detailed": """## Conversation Summary (Detailed)
### Discussion Flow
The conversation covered 4 main exchanges exploring the source material.
### Topics Explored
1. **Core Concepts (Q1-Q2):** User asked about the foundational relationship between variables. The AI identified Chapter 3 as the primary source and highlighted it as a prerequisite for advanced topics.
2. **Methodology Comparison (Q3):** User inquired about different problem-solving approaches. Three methods were identified β direct, iterative, and approximation β with trade-offs explained for each.
3. **Process Stages (Q4):** Discussion about the three-stage process introduced in Week 5 lectures: initialization, processing, and validation.
### Key Insights from Chat
- The direct method is recommended as the starting point for beginners
- Lecture notes and textbook provide complementary perspectives
- Each stage has specific requirements that must be met before proceeding
### Citations Used
| Source | Times Referenced |
|--------|----------------|
| textbook_ch3.pdf | 3 |
| lecture_notes.pdf | 2 |
| week5_slides.pptx | 2 |
| textbook_ch2.pdf | 1 |
""",
}
MOCK_DOCUMENT_SUMMARY = {
"brief": """## Document Summary (Brief)
**Core Theme:** The sources examine the relationship between key variables and present multiple problem-solving methodologies.
**Key Takeaways:**
- Three approaches exist: direct method, iterative approach, and approximation
- The direct method provides exact results but requires complete data
- A three-stage process (initialization β processing β validation) underpins the framework
- Lecture materials focus on application; textbook provides theoretical depth
**Bottom Line:** Master the direct method first, then explore alternatives as complexity increases.
""",
"detailed": """## Document Summary (Detailed)
### 1. Foundational Framework
The sources establish a foundational framework centered on the relationship between core variables discussed primarily in Chapter 3. The author emphasizes that a thorough understanding of this relationship is a prerequisite before advancing to more complex topics. The framework operates through a three-stage process:
- **Initialization** β Setting up parameters and base conditions
- **Processing** β Executing the core computational logic
- **Validation** β Verifying outputs meet confidence thresholds
### 2. Methodological Approaches
Three distinct methodological approaches are presented across the sources:
| Method | Best For | Trade-off |
|--------|----------|-----------|
| **Direct** | Complete datasets, exact results needed | Requires full data availability |
| **Iterative** | Incomplete data, convergent solutions | Multiple passes, slower |
| **Approximation** | Quick estimates, non-critical precision | Sacrifices accuracy for speed |
The textbook (Section 2.1) recommends beginners start with the direct method, as it builds intuition for how the formula maps inputs to outputs.
### 3. Cross-Source Analysis
The lecture notes (Week 5) and textbook chapters approach the same material from complementary angles:
- **Lectures** β Emphasize practical application with worked examples
- **Textbook** β Provides theoretical depth, proofs, and edge cases
- **Slides** β Offer visual summaries and quick-reference diagrams
### 4. Key Definitions
- **Confidence threshold** β The minimum acceptable level of certainty for a result
- **Convergence** β The point at which iterative refinements produce negligible improvement
- **Base case** β The simplest instance of a problem used as a starting point
### 5. Conclusion
Mastering these fundamentals is essential before proceeding to advanced modules. The recommended learning path is: direct method β iterative approach β approximation, building complexity gradually.
""",
}
MOCK_PODCAST_SCRIPT = """## Podcast: Deep Dive Study Session
**Alex:** Hey everyone, welcome back to another deep dive study session! I'm Alex, and I'm here with Sam. Today we've got some really meaty material to break down. Sam, I read through the summary and honestly, there's a lot going on. Where do we even start?
**Sam:** Right, so let's zoom out first. The big picture here is about problem-solving methodology β specifically, the idea that there isn't just one way to solve a problem. The sources lay out three distinct approaches, and understanding when to use which one is really the meta-skill they're teaching.
**Alex:** Okay, three approaches. Let's go through them one by one?
**Sam:** Absolutely. So the first one is called the **direct method**. Think of it like having a recipe where you know all the ingredients and all the steps. You plug your values into the formula, follow the steps, and you get your exact answer. Clean, precise, done.
**Alex:** That sounds like the dream scenario. Why doesn't everyone just use that all the time?
**Sam:** Great question β and this is where it gets interesting. The direct method has a strict requirement: you need *complete* data. Every single input has to be known. In academic exercises, sure, they give you everything. But in the real world? You're often working with gaps, estimates, or noisy data.
**Alex:** Ah, so that's where the second approach comes in?
**Sam:** Exactly β the **iterative approach**. Instead of solving it in one shot, you start with your best guess and then keep refining. Each pass gets you closer to the real answer. It's like sculptors β you start with a rough block and keep chipping away until it looks right.
**Alex:** I love that analogy. So how do you know when to stop iterating?
**Sam:** That's actually one of the key concepts β **convergence**. You stop when the difference between iterations becomes so small that it's negligible. The sources define a confidence threshold, and once you're within that threshold, you're done.
**Alex:** Makes sense. And the third method?
**Sam:** **Approximation**. This one is all about pragmatism. Sometimes you don't need five decimal places of precision. You just need a ballpark. Is this going to cost us $100 or $10,000? The approximation method gives you that answer fast, at the cost of some accuracy.
**Alex:** So it's really about matching your tool to the job.
**Sam:** Exactly right. And that's actually what the sources are trying to teach. It's not just "here are three formulas." It's "here's how to think about which tool fits which situation." That metacognitive skill is what separates a good problem-solver from someone who just memorizes formulas.
**Alex:** One thing I noticed in the summary was this three-stage process β initialization, processing, validation. How does that fit in?
**Sam:** Good catch. That process applies to *all three* methods. Regardless of which approach you choose, you always: set up your initial conditions, run the computation, and then validate your results. It's like a universal wrapper around any problem-solving method.
**Alex:** That's a really clean mental model. I wish my professors had explained it that way.
**Sam:** Ha! Well, that's what the lecture notes try to do β they focus on practical application. The textbook goes deeper into the theory and proofs, but the lectures are where you get the worked examples and intuition.
**Alex:** Alright, I think that's a solid overview. Any final advice for students studying this material?
**Sam:** Start with the direct method. Get really comfortable with it. Once you feel solid, move to iterative, then approximation. Don't try to learn all three at once β build up gradually. And always check your work with that validation step.
**Alex:** Brilliant advice. Thanks Sam, and thanks everyone for listening. Until next time β keep studying smart, not just hard!
"""
MOCK_QUIZ = {
5: """## Practice Quiz (5 Questions)
### Question 1
What is the primary advantage of the direct method?
- A) It works with incomplete data
- B) It provides exact results in a single pass
- C) It is the fastest method
- D) It requires no validation
**Answer: B**
**Explanation:** The direct method applies the formula once to produce exact results, unlike iterative methods that require multiple passes.
---
### Question 2
Which stage comes immediately after initialization in the three-stage process?
- A) Validation
- B) Optimization
- C) Processing
- D) Calibration
**Answer: C**
**Explanation:** The three stages are: initialization β processing β validation.
---
### Question 3
When should the approximation method be preferred?
- A) When working with critical systems
- B) When precision is not the primary concern
- C) When the dataset is very small
- D) When the direct method fails
**Answer: B**
**Explanation:** Approximation trades precision for speed, ideal when exact results aren't required.
---
### Question 4
What does "convergence" refer to in the iterative approach?
- A) The point where the algorithm starts
- B) When iterations produce negligible differences
- C) The final validation step
- D) Combining multiple methods together
**Answer: B**
**Explanation:** Convergence is reached when successive iterations produce results so close together that further refinement is unnecessary.
---
### Question 5
What is the recommended learning order for the three methods?
- A) Approximation β Iterative β Direct
- B) Iterative β Direct β Approximation
- C) Direct β Iterative β Approximation
- D) Any order is equally effective
**Answer: C**
**Explanation:** The textbook recommends starting with the direct method to build intuition, then progressing to iterative and approximation.
""",
10: """## Practice Quiz (10 Questions)
### Question 1
What is the primary advantage of the direct method?
- A) It works with incomplete data
- B) It provides exact results in a single pass
- C) It is the fastest method
- D) It requires no validation
**Answer: B**
---
### Question 2
Which stage comes immediately after initialization?
- A) Validation
- B) Optimization
- C) Processing
- D) Calibration
**Answer: C**
---
### Question 3
When should the approximation method be preferred?
- A) When working with critical systems
- B) When precision is not the primary concern
- C) When the dataset is very small
- D) When the direct method fails
**Answer: B**
---
### Question 4
What does "convergence" mean in the iterative approach?
- A) The point where the algorithm starts
- B) When iterations produce negligible differences
- C) The final validation step
- D) Combining multiple methods
**Answer: B**
---
### Question 5
What is the recommended learning order?
- A) Approximation β Iterative β Direct
- B) Iterative β Direct β Approximation
- C) Direct β Iterative β Approximation
- D) Any order is fine
**Answer: C**
---
### Question 6
What does the direct method require?
- A) Multiple iterations
- B) Complete data
- C) A confidence threshold
- D) An initial estimate
**Answer: B**
---
### Question 7
What is a "confidence threshold"?
- A) How sure you are about your method choice
- B) The minimum acceptable certainty for a result
- C) The maximum number of iterations
- D) The accuracy of the approximation method
**Answer: B**
---
### Question 8
How do lecture notes differ from the textbook?
- A) Lectures focus on theory, textbook on application
- B) Lectures focus on application, textbook on theory
- C) They cover different topics entirely
- D) There is no significant difference
**Answer: B**
---
### Question 9
What is a "base case" in this context?
- A) The most complex problem instance
- B) The simplest problem instance used as a starting point
- C) The final validated result
- D) A failed iteration
**Answer: B**
---
### Question 10
The three-stage process applies to which methods?
- A) Only the direct method
- B) Only the iterative method
- C) Direct and iterative only
- D) All three methods
**Answer: D**
""",
}
def generate_mock_artifact(artifact_type: str, **kwargs) -> Artifact:
time.sleep(1.5)
if artifact_type == "conversation_summary":
style = kwargs.get("style", "detailed")
content = MOCK_CONVERSATION_SUMMARY.get(style, MOCK_CONVERSATION_SUMMARY["detailed"])
title = f"Conversation Summary ({'Brief' if style == 'brief' else 'Detailed'})"
elif artifact_type == "document_summary":
style = kwargs.get("style", "detailed")
content = MOCK_DOCUMENT_SUMMARY.get(style, MOCK_DOCUMENT_SUMMARY["detailed"])
title = f"Document Summary ({'Brief' if style == 'brief' else 'Detailed'})"
elif artifact_type == "podcast":
content = MOCK_PODCAST_SCRIPT
title = "Podcast Episode"
elif artifact_type == "quiz":
num_q = kwargs.get("num_questions", 5)
content = MOCK_QUIZ.get(num_q, MOCK_QUIZ[5])
title = f"Practice Quiz ({num_q}Q)"
else:
content = ""
title = artifact_type
return Artifact(
id=str(uuid.uuid4()),
type=artifact_type,
title=title,
content=content,
audio_path=None,
created_at=datetime.now().isoformat(),
)
|