Spaces:
Sleeping
Sleeping
Update clare_core.py
Browse files- clare_core.py +14 -11
clare_core.py
CHANGED
|
@@ -14,6 +14,8 @@ from config import (
|
|
| 14 |
LEARNING_MODE_INSTRUCTIONS,
|
| 15 |
)
|
| 16 |
from langsmith import traceable
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
# ---------- syllabus 解析 ----------
|
|
@@ -564,16 +566,7 @@ def build_messages(
|
|
| 564 |
return messages
|
| 565 |
|
| 566 |
# 装饰器
|
| 567 |
-
@traceable(
|
| 568 |
-
run_type="chain",
|
| 569 |
-
name="chat_with_clare",
|
| 570 |
-
metadata={
|
| 571 |
-
"learning_mode": lambda *args, **kwargs: kwargs.get("learning_mode"),
|
| 572 |
-
"language_preference": lambda *args, **kwargs: kwargs.get("language_preference"),
|
| 573 |
-
"doc_type": lambda *args, **kwargs: kwargs.get("doc_type"),
|
| 574 |
-
},
|
| 575 |
-
)
|
| 576 |
-
|
| 577 |
def chat_with_clare(
|
| 578 |
message: str,
|
| 579 |
history: List[Tuple[str, str]],
|
|
@@ -584,8 +577,18 @@ def chat_with_clare(
|
|
| 584 |
course_outline: Optional[List[str]],
|
| 585 |
weaknesses: Optional[List[str]],
|
| 586 |
cognitive_state: Optional[Dict[str, int]],
|
| 587 |
-
rag_context: Optional[str] = None,
|
| 588 |
) -> Tuple[str, List[Tuple[str, str]]]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 589 |
# 构建 messages
|
| 590 |
messages = build_messages(
|
| 591 |
user_message=message,
|
|
|
|
| 14 |
LEARNING_MODE_INSTRUCTIONS,
|
| 15 |
)
|
| 16 |
from langsmith import traceable
|
| 17 |
+
from langsmith.run_helpers import set_run_metadata
|
| 18 |
+
|
| 19 |
|
| 20 |
|
| 21 |
# ---------- syllabus 解析 ----------
|
|
|
|
| 566 |
return messages
|
| 567 |
|
| 568 |
# 装饰器
|
| 569 |
+
@traceable(run_type="chain", name="chat_with_clare")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 570 |
def chat_with_clare(
|
| 571 |
message: str,
|
| 572 |
history: List[Tuple[str, str]],
|
|
|
|
| 577 |
course_outline: Optional[List[str]],
|
| 578 |
weaknesses: Optional[List[str]],
|
| 579 |
cognitive_state: Optional[Dict[str, int]],
|
| 580 |
+
rag_context: Optional[str] = None,
|
| 581 |
) -> Tuple[str, List[Tuple[str, str]]]:
|
| 582 |
+
try:
|
| 583 |
+
set_run_metadata(
|
| 584 |
+
learning_mode=learning_mode,
|
| 585 |
+
language_preference=language_preference,
|
| 586 |
+
doc_type=doc_type,
|
| 587 |
+
)
|
| 588 |
+
except Exception as e:
|
| 589 |
+
print(f"[LangSmith metadata error in chat_with_clare] {repr(e)}")
|
| 590 |
+
|
| 591 |
+
|
| 592 |
# 构建 messages
|
| 593 |
messages = build_messages(
|
| 594 |
user_message=message,
|