Spaces:
Running
Running
Update pipeline.py
Browse files- pipeline.py +17 -15
pipeline.py
CHANGED
@@ -77,11 +77,13 @@ logger = logging.getLogger(__name__)
|
|
77 |
from langchain_core.tracers import LangChainTracer
|
78 |
from langsmith import Client
|
79 |
|
80 |
-
|
|
|
81 |
os.environ["LANGSMITH_ENDPOINT"]="https://api.smith.langchain.com"
|
82 |
-
langsmith_client = Client()
|
83 |
-
os.environ["
|
84 |
-
|
|
|
85 |
|
86 |
|
87 |
|
@@ -592,17 +594,17 @@ def is_ethical_conflict(query: str) -> bool:
|
|
592 |
# Main Pipeline
|
593 |
# -------------------------------------------------------
|
594 |
def run_with_chain(query: str) -> str:
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
start_time = time.time()
|
607 |
try:
|
608 |
# 1) Validate
|
|
|
77 |
from langchain_core.tracers import LangChainTracer
|
78 |
from langsmith import Client
|
79 |
|
80 |
+
|
81 |
+
os.environ["LANGCHAIN_TRACING_V2"]="true"
|
82 |
os.environ["LANGSMITH_ENDPOINT"]="https://api.smith.langchain.com"
|
83 |
+
# langsmith_client = Client()
|
84 |
+
os.environ["LANGCHAIN_API_KEY"]=os.getenv("LANGCHAIN_API_KEY")
|
85 |
+
os.environ["LANGCHAIN_PROJECT"]=os.getenv("LANGCHAIN_PROJECT")
|
86 |
+
# tracer = LangChainTracer(project_name=os.environ.get("LANGCHAIN_PROJECT", "healthy_ai_expert"))
|
87 |
|
88 |
|
89 |
|
|
|
594 |
# Main Pipeline
|
595 |
# -------------------------------------------------------
|
596 |
def run_with_chain(query: str) -> str:
|
597 |
+
"""
|
598 |
+
Overall flow:
|
599 |
+
1) Validate & rate-limit
|
600 |
+
2) Mistral moderation =>
|
601 |
+
- If self-harm => self_harm_chain
|
602 |
+
- If hate => refusal
|
603 |
+
- If violence/dangerous => we STILL produce a guided response (ethics) unless it's extreme
|
604 |
+
3) If not refused, check if query is aggression/ethical => route to chain
|
605 |
+
4) Otherwise classify => brand/wellness/out-of-scope => RAG => tailor
|
606 |
+
"""
|
607 |
+
# with tracer.new_trace(name="wellness_pipeline_run") as run:
|
608 |
start_time = time.time()
|
609 |
try:
|
610 |
# 1) Validate
|