Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LLM_TEMPERATURE=0.7

##### LANGSMITH TRACING ####
LANGSMITH_TRACING_ENABLED=False
LANGSMITH_TRACING_V2=false
LANGSMITH_PROJECT=fake_project
LANGSMITH_ENDPOINT=https://api.smith.langchain.com
LANGSMITH_API_KEY=FAKE_LANGSMITH_API_KEY
Expand Down
1 change: 1 addition & 0 deletions k8s/welearn-api/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ config:
DATA_COLLECTION_ORIGIN_PREFIX: welearn
SESSION_COOKIE_DOMAIN: .lp-i.dev
LANGSMITH_TRACING_ENABLED: "true"
LANGSMITH_TRACING_V2: "true"
LANGSMITH_PROJECT: WeLearn_Dev
LANGSMITH_ENDPOINT: https://eu.api.smith.langchain.com
ENV: development
Expand Down
1 change: 1 addition & 0 deletions k8s/welearn-api/values.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ config:
ENV: production
SESSION_COOKIE_DOMAIN: learningplanetinstitute.org
LANGSMITH_TRACING_ENABLED: "true"
LANGSMITH_TRACING_V2: "true"
LANGSMITH_PROJECT: WeLearn_Prod
LANGSMITH_ENDPOINT: https://eu.api.smith.langchain.com
SMTP_HOST: smtp.eu.mailgun.org
Expand Down
1 change: 1 addition & 0 deletions k8s/welearn-api/values.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ config:
SESSION_COOKIE_DOMAIN: .lp-i.xyz
ENV: staging
LANGSMITH_TRACING_ENABLED: "true"
LANGSMITH_TRACING_V2: "true"
LANGSMITH_PROJECT: WeLearn_Staging
LANGSMITH_ENDPOINT: https://eu.api.smith.langchain.com
# uvicorn reads X-Forwarded-For only from the Traefik pods (same CIDR as dev)
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ env =
DATA_COLLECTION_ORIGIN_PREFIX=workshop
ENV=test
LANGSMITH_TRACING_ENABLED=false
LANGSMITH_TRACING_V2=false
EMBEDDING_MODELS_TO_PRELOAD=[]
# feature flags at their defaults, so a developer's .env or shell cannot change what
# the tests see; a test that needs another value patches settings itself
Expand Down
3 changes: 1 addition & 2 deletions src/app/chat/services/abst_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from src.app.chat.services.helpers import latest_tool_docs
from src.app.chat.services.thread_access import OWNER_METADATA_KEY
from src.app.search.services.search import SearchService
from src.app.shared.infra.tracing import TraceComponent
from src.app.shared.utils.db_errors import describe_error
from src.app.shared.utils.dependencies import get_settings
from src.app.shared.utils.logger import logger as utils_logger
Expand Down Expand Up @@ -308,7 +307,7 @@ async def agent_message(
settings = get_settings()

metadata: dict[str, Any] = {
"component": TraceComponent.CHAT_AGENT.value,
"component": "chat_agent",
"environment": settings.ENV,
"thread_id": str(thread_id) if thread_id else None,
"corpora": list(corpora) if corpora else None,
Expand Down
11 changes: 0 additions & 11 deletions src/app/shared/infra/tracing.py

This file was deleted.

3 changes: 1 addition & 2 deletions src/app/tutor/services/adaptation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from langsmith import traceable

from src.app.shared.domain.documents import EnhancedDocumentSlice
from src.app.shared.infra.tracing import TraceName
from src.app.shared.utils.logger import logger as utils_logger
from src.app.tutor.domain.adaptation import (
AdaptationAnswer,
Expand Down Expand Up @@ -476,7 +475,7 @@ async def check(
return to_verification(answer, resources, change)


@traceable(name=TraceName.TUTOR_ADAPTATION.value)
@traceable(name="Tutor adaptation")
async def adapt_course(
course: ConfirmedCourse, connection: ChosenConnection, lang: TutorLang
) -> AdaptationProposal:
Expand Down
27 changes: 23 additions & 4 deletions src/app/tutor/services/extractor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from langchain_core.runnables import RunnableConfig
from langchain_mistralai import ChatMistralAI # type: ignore
from langsmith import traceable
from pydantic import BaseModel

from src.app.shared.infra.tracing import TraceName
from src.app.shared.utils.dependencies import get_settings
from src.app.shared.utils.logger import logger as utils_logger
from src.app.tutor.domain.models import ExtractorOutput, ExtractorOutputList, TutorLang
Expand Down Expand Up @@ -80,18 +80,37 @@ def build_extractor_messages(documents: str, lang: TutorLang) -> list[tuple[str,
]


@traceable(name=TraceName.FILES_SUMMARY_EXTRACTOR.value)
@traceable(name="Tutor documents summarization")
async def extract_files_summaries(
documents: str, lang: TutorLang
) -> ExtractorOutputList:
"""Summarize each document and extract its main themes."""
model = await _get_model()
structured = model.with_structured_output(_Extracts)
result = await structured.ainvoke(build_extractor_messages(documents, lang))

config: RunnableConfig = {
"run_name": "tutor.file_extraction",
"metadata": {
"operation": "extract_files_summaries",
"lang": lang,
"schema": _Extracts.__name__,
"input_chars": len(documents),
},
}

result = await structured.ainvoke(
build_extractor_messages(documents, lang),
config=config,
)
if not isinstance(result, _Extracts):
raise ValueError("Extractor returned an unexpected output")

logger.debug("extract_files_summaries nb_extracts=%s", len(result.extracts))
logger.info(
"tutor_file_extraction_complete nb_extracts=%s input_chars=%s lang=%s",
len(result.extracts),
len(documents),
lang,
)
return ExtractorOutputList(
extracts=[
ExtractorOutput(
Expand Down
10 changes: 8 additions & 2 deletions src/app/tutor/services/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from pydantic import BaseModel, ValidationError

from src.app.shared.domain.exceptions import LLMUnavailableError, UnusableLLMOutputError
from src.app.shared.infra.tracing import TraceName
from src.app.shared.utils.dependencies import get_settings
from src.app.shared.utils.logger import logger as utils_logger
from src.app.tutor.domain.models import TutorLang
Expand Down Expand Up @@ -186,7 +185,7 @@ def build_messages(
return [("system", system), ("human", human)]


@traceable(name=TraceName.TUTOR_STRUCTURED_CALL.value)
@traceable(name="Tutor structured call")
async def structured_call(
prompt_name: str,
lang: TutorLang,
Expand Down Expand Up @@ -216,6 +215,7 @@ async def structured_call(
"prompt": prompt_name,
"lang": lang,
"prompt_version": prompt_version(prompt_name),
"schema": schema.__name__,
},
}

Expand All @@ -241,6 +241,12 @@ async def structured_call(
error = type(e).__name__
else:
if is_usable is None or is_usable(answer):
logger.info(
"tutor_structured_call_success prompt=%s lang=%s attempts=%s",
prompt_name,
lang,
attempt,
)
return answer
error = "NotUsable"
# no content in the logs: the answer may quote the teacher's course
Expand Down
2 changes: 2 additions & 0 deletions src/app/tutor/services/syllabus.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from langchain_core.language_models import BaseChatModel
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnableConfig
from langsmith import traceable
from pydantic import ValidationError

from src.app.shared.utils.logger import logger as utils_logger
Expand Down Expand Up @@ -390,6 +391,7 @@ def build_user_prompt(
return "\n\n".join(parts)


@traceable(name="Tutor syllabus generation")
async def generate_syllabus(
message: MessageWithResources,
model: BaseChatModel,
Expand Down
Loading