Spaces:
Sleeping
Sleeping
Update clare_core.py
Browse files- clare_core.py +35 -39
clare_core.py
CHANGED
|
@@ -553,30 +553,32 @@ def chat_with_clare(
|
|
| 553 |
weaknesses: Optional[List[str]],
|
| 554 |
cognitive_state: Optional[Dict[str, int]],
|
| 555 |
) -> Tuple[str, List[Tuple[str, str]]]:
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
|
|
|
| 575 |
|
| 576 |
history = history + [(message, answer)]
|
| 577 |
return answer, history
|
| 578 |
|
| 579 |
|
|
|
|
| 580 |
# ---------- 导出对话为 Markdown ----------
|
| 581 |
def export_conversation(
|
| 582 |
history: List[Tuple[str, str]],
|
|
@@ -665,16 +667,13 @@ def generate_quiz_from_history(
|
|
| 665 |
}
|
| 666 |
)
|
| 667 |
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
except Exception as e:
|
| 676 |
-
quiz_text = f"⚠️ Error generating quiz: {e}"
|
| 677 |
-
|
| 678 |
return quiz_text
|
| 679 |
|
| 680 |
|
|
@@ -738,14 +737,11 @@ def summarize_conversation(
|
|
| 738 |
}
|
| 739 |
)
|
| 740 |
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
except Exception as e:
|
| 749 |
-
summary_text = f"⚠️ Error generating summary: {e}"
|
| 750 |
-
|
| 751 |
return summary_text
|
|
|
|
| 553 |
weaknesses: Optional[List[str]],
|
| 554 |
cognitive_state: Optional[Dict[str, int]],
|
| 555 |
) -> Tuple[str, List[Tuple[str, str]]]:
|
| 556 |
+
# 构建 messages
|
| 557 |
+
messages = build_messages(
|
| 558 |
+
user_message=message,
|
| 559 |
+
history=history,
|
| 560 |
+
language_preference=language_preference,
|
| 561 |
+
learning_mode=learning_mode,
|
| 562 |
+
doc_type=doc_type,
|
| 563 |
+
course_outline=course_outline,
|
| 564 |
+
weaknesses=weaknesses,
|
| 565 |
+
cognitive_state=cognitive_state,
|
| 566 |
+
)
|
| 567 |
+
|
| 568 |
+
# 统一安全调用
|
| 569 |
+
answer = safe_chat_completion(
|
| 570 |
+
model_name=model_name,
|
| 571 |
+
messages=messages,
|
| 572 |
+
lang=language_preference,
|
| 573 |
+
op="chat",
|
| 574 |
+
temperature=0.5,
|
| 575 |
+
)
|
| 576 |
|
| 577 |
history = history + [(message, answer)]
|
| 578 |
return answer, history
|
| 579 |
|
| 580 |
|
| 581 |
+
|
| 582 |
# ---------- 导出对话为 Markdown ----------
|
| 583 |
def export_conversation(
|
| 584 |
history: List[Tuple[str, str]],
|
|
|
|
| 667 |
}
|
| 668 |
)
|
| 669 |
|
| 670 |
+
quiz_text = safe_chat_completion(
|
| 671 |
+
model_name=model_name,
|
| 672 |
+
messages=messages,
|
| 673 |
+
lang=language_preference,
|
| 674 |
+
op="quiz",
|
| 675 |
+
temperature=0.5,
|
| 676 |
+
)
|
|
|
|
|
|
|
|
|
|
| 677 |
return quiz_text
|
| 678 |
|
| 679 |
|
|
|
|
| 737 |
}
|
| 738 |
)
|
| 739 |
|
| 740 |
+
summary_text = safe_chat_completion(
|
| 741 |
+
model_name=model_name,
|
| 742 |
+
messages=messages,
|
| 743 |
+
lang=language_preference,
|
| 744 |
+
op="summary",
|
| 745 |
+
temperature=0.4,
|
| 746 |
+
)
|
|
|
|
|
|
|
|
|
|
| 747 |
return summary_text
|