Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -336,6 +336,18 @@ Rather than providing complete solutions, you should:
|
|
| 336 |
|
| 337 |
Your goal is to be an educational partner who empowers students to succeed through understanding."""
|
| 338 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
# --- LLM Class with Phi-3 Mini ---
|
| 340 |
class Phi3MiniEducationalLLM(Runnable):
|
| 341 |
"""LLM class optimized for Microsoft Phi-3-mini-4k-instruct with 4-bit quantization"""
|
|
|
|
| 336 |
|
| 337 |
Your goal is to be an educational partner who empowers students to succeed through understanding."""
|
| 338 |
|
| 339 |
+
# --- Stop Criteria ---
|
| 340 |
+
|
| 341 |
+
class StopOnSequence(StoppingCriteria):
|
| 342 |
+
def __init__(self, tokenizer, stop_sequence):
|
| 343 |
+
self.tokenizer = tokenizer
|
| 344 |
+
self.stop_sequence = tokenizer.encode(stop_sequence, add_special_tokens=False)
|
| 345 |
+
|
| 346 |
+
def __call__(self, input_ids, scores, **kwargs):
|
| 347 |
+
if input_ids[0, -len(self.stop_sequence):].tolist() == self.stop_sequence:
|
| 348 |
+
return True
|
| 349 |
+
return False
|
| 350 |
+
|
| 351 |
# --- LLM Class with Phi-3 Mini ---
|
| 352 |
class Phi3MiniEducationalLLM(Runnable):
|
| 353 |
"""LLM class optimized for Microsoft Phi-3-mini-4k-instruct with 4-bit quantization"""
|