Spaces:
Sleeping
Sleeping
Update clare_core.py
Browse files- clare_core.py +5 -1
clare_core.py
CHANGED
|
@@ -13,6 +13,8 @@ from config import (
|
|
| 13 |
CLARE_SYSTEM_PROMPT,
|
| 14 |
LEARNING_MODE_INSTRUCTIONS,
|
| 15 |
)
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# ---------- syllabus 解析 ----------
|
| 18 |
def parse_syllabus_docx(file_path: str, max_lines: int = 15) -> List[str]:
|
|
@@ -265,7 +267,7 @@ def cosine_similarity(a: List[float], b: List[float]) -> float:
|
|
| 265 |
return 0.0
|
| 266 |
return dot / (norm_a * norm_b)
|
| 267 |
|
| 268 |
-
|
| 269 |
def get_embedding(text: str) -> Optional[List[float]]:
|
| 270 |
"""
|
| 271 |
调用 OpenAI Embedding API,将文本编码为向量。
|
|
@@ -355,6 +357,7 @@ def find_similar_past_question(
|
|
| 355 |
return None
|
| 356 |
|
| 357 |
|
|
|
|
| 358 |
def safe_chat_completion(
|
| 359 |
model_name: str,
|
| 360 |
messages: List[Dict[str, str]],
|
|
@@ -561,6 +564,7 @@ def build_messages(
|
|
| 561 |
return messages
|
| 562 |
|
| 563 |
|
|
|
|
| 564 |
def chat_with_clare(
|
| 565 |
message: str,
|
| 566 |
history: List[Tuple[str, str]],
|
|
|
|
| 13 |
CLARE_SYSTEM_PROMPT,
|
| 14 |
LEARNING_MODE_INSTRUCTIONS,
|
| 15 |
)
|
| 16 |
+
from langsmith import traceable
|
| 17 |
+
|
| 18 |
|
| 19 |
# ---------- syllabus 解析 ----------
|
| 20 |
def parse_syllabus_docx(file_path: str, max_lines: int = 15) -> List[str]:
|
|
|
|
| 267 |
return 0.0
|
| 268 |
return dot / (norm_a * norm_b)
|
| 269 |
|
| 270 |
+
@traceable(run_type="embedding", name="get_embedding")
|
| 271 |
def get_embedding(text: str) -> Optional[List[float]]:
|
| 272 |
"""
|
| 273 |
调用 OpenAI Embedding API,将文本编码为向量。
|
|
|
|
| 357 |
return None
|
| 358 |
|
| 359 |
|
| 360 |
+
@traceable(run_type="llm", name="safe_chat_completion")
|
| 361 |
def safe_chat_completion(
|
| 362 |
model_name: str,
|
| 363 |
messages: List[Dict[str, str]],
|
|
|
|
| 564 |
return messages
|
| 565 |
|
| 566 |
|
| 567 |
+
@traceable(run_type="chain", name="chat_with_clare")
|
| 568 |
def chat_with_clare(
|
| 569 |
message: str,
|
| 570 |
history: List[Tuple[str, str]],
|