@langwatch/server 3.1.0-beta.21 → 3.1.0-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/__init__.py +36 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/_logger.py +165 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/batch_clustering.py +153 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/build_response.py +77 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/constants.py +7 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/incremental_clustering.py +325 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/topic_naming.py +432 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/types.py +42 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/utils.py +191 -0
- package/langevals/evaluators/topic_clustering/pyproject.toml +52 -0
- package/langevals/evaluators/topic_clustering/tests/test_topic_clustering.py +239 -0
- package/langevals/evaluators/topic_clustering/tests/test_topic_clustering_integration.py +97 -0
- package/langevals/evaluators/topic_clustering/tests/test_topic_naming.py +72 -0
- package/langevals/langevals/pytest_plugins/pass_rate_plugin.py +7 -1
- package/langevals/langevals/server.py +28 -0
- package/langevals/pyproject.toml +3 -0
- package/langevals/uv.lock +119 -20
- package/langwatch/dist/client/assets/{AnnotationsTable-BDAkYaz6.js → AnnotationsTable-uS_9SQ-g.js} +2 -2
- package/langwatch/dist/client/assets/{BatchEvaluationSummary-DMaQM_VB.js → BatchEvaluationSummary-DtFd8yKJ.js} +2 -2
- package/langwatch/dist/client/assets/{BudgetEditDrawer-CHaqmdIl.js → BudgetEditDrawer-CHEPz0hH.js} +2 -2
- package/langwatch/dist/client/assets/{ChartCard-D14PUg_d.js → ChartCard-s5fMPo7b.js} +2 -2
- package/langwatch/dist/client/assets/{ChatWindow-CRDnlP-Q.js → ChatWindow-C0XSteVJ.js} +2 -2
- package/langwatch/dist/client/assets/ChatWindow-DFEmNXQL.js +1 -0
- package/langwatch/dist/client/assets/{ConfirmDialog-CXIhncvW.js → ConfirmDialog-M94yLNvP.js} +2 -2
- package/langwatch/dist/client/assets/{ContactSalesBlock-CijLBwRC.js → ContactSalesBlock-CnnuZ8iI.js} +2 -2
- package/langwatch/dist/client/assets/{DSPyExperiment-B1YOL2m8.js → DSPyExperiment-CMA6lrlx.js} +2 -2
- package/langwatch/dist/client/assets/{FilterDisplay-BB0xWrLn.js → FilterDisplay-0S3NqCkq.js} +2 -2
- package/langwatch/dist/client/assets/{FormatMoney-w9vr_h0X.js → FormatMoney-CCygtAHg.js} +2 -2
- package/langwatch/dist/client/assets/{FoundryDrawer-CdJDXtpz.js → FoundryDrawer-B35xZ26C.js} +2 -2
- package/langwatch/dist/client/assets/{GatewayErrorPanel-DvE9U2dS.js → GatewayErrorPanel-BsaYQEie.js} +2 -2
- package/langwatch/dist/client/assets/{GatewayLayout-lv1p_6B5.js → GatewayLayout-LvwwrwMf.js} +2 -2
- package/langwatch/dist/client/assets/{GraphsLayout-BJ68J9e-.js → GraphsLayout-DJ-HI9N1.js} +2 -2
- package/langwatch/dist/client/assets/{GroupBindingInputRow-DebZBCnD.js → GroupBindingInputRow-CV-fBkX9.js} +2 -2
- package/langwatch/dist/client/assets/{MessagesTable-B6lYde-x.js → MessagesTable-9taaKCOZ.js} +2 -2
- package/langwatch/dist/client/assets/{NavigationFooter-CiOVzDUh.js → NavigationFooter-Dzvauw3l.js} +2 -2
- package/langwatch/dist/client/assets/{NoDataInfoBlock-quSW_MRm.js → NoDataInfoBlock-CLKl_wlX.js} +2 -2
- package/langwatch/dist/client/assets/{OpsPageShell-DJ1WlI6-.js → OpsPageShell-C_mTziRS.js} +2 -2
- package/langwatch/dist/client/assets/{OptimizationStudio-BlozXjcN.js → OptimizationStudio-D2zpsmJj.js} +8 -12
- package/langwatch/dist/client/assets/{PreconditionsField-BOfcWvmZ.js → PreconditionsField-WXB8kcTK.js} +2 -2
- package/langwatch/dist/client/assets/{SettingsLayout-CLCGxMAe.js → SettingsLayout--1gdEuhv.js} +2 -2
- package/langwatch/dist/client/assets/{SubscriptionPage-J8b2Zaj6.js → SubscriptionPage-B0ox_4kM.js} +2 -2
- package/langwatch/dist/client/assets/{VirtualKeySecretReveal-DR1VDLy7.js → VirtualKeySecretReveal-CRbI1dKQ.js} +2 -2
- package/langwatch/dist/client/assets/{WithPermissionGuard-DD8uo3UK.js → WithPermissionGuard-B4Jo8E5-.js} +2 -2
- package/langwatch/dist/client/assets/{__...path__-BZVaIayJ.js → __...path__-BF2zkD84.js} +2 -2
- package/langwatch/dist/client/assets/{_experiment_-B1aT-wS3.js → _experiment_-D02aoVQk.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-oI_eq-I_.js → _id_-Ch8YmTiM.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-DAqPuO73.js → _id_-D6ZvwHpH.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-DUngklVb.js → _id_-DOC1ZkBm.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-jFDAfbob.js → _id_-DfWwW6_N.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-BKBrWGG0.js → _id_-DxUo4W7J.js} +2 -2
- package/langwatch/dist/client/assets/_not-found-DDh108-i.js +1 -0
- package/langwatch/dist/client/assets/{_project_-Bt1tayHB.js → _project_-_UUt5Ar9.js} +2 -2
- package/langwatch/dist/client/assets/{_runId_-CfvnDt5H.js → _runId_-Dimwzp48.js} +2 -2
- package/langwatch/dist/client/assets/_slug_-BMvKBwS_.js +2 -0
- package/langwatch/dist/client/assets/{_slug_-DZAdl0QS.js → _slug_-CE6VoDSC.js} +2 -2
- package/langwatch/dist/client/assets/{_slug_-DmoWXjKT.js → _slug_-OiOLG1Mv.js} +2 -2
- package/langwatch/dist/client/assets/{_team_-DL_wKSWK.js → _team_-DKvmwO_5.js} +2 -2
- package/langwatch/dist/client/assets/{_workflow_-DcMXLPUe.js → _workflow_-FkilKiB-.js} +3 -3
- package/langwatch/dist/client/assets/{_workflow_-NI9bac7d.js → _workflow_-gJZppg3h.js} +2 -2
- package/langwatch/dist/client/assets/{access-audit-CFwNwusI.js → access-audit-xcUVYMMT.js} +2 -2
- package/langwatch/dist/client/assets/{agents-Di4XRwcn.js → agents-D32g91cu.js} +2 -2
- package/langwatch/dist/client/assets/{all-C273mlDB.js → all-vnREzDZj.js} +2 -2
- package/langwatch/dist/client/assets/{analytics-CEAcSf6B.js → analytics-DP6Y4Feh.js} +2 -2
- package/langwatch/dist/client/assets/{annotation-scores-CHfn4LQp.js → annotation-scores-CjD4CEB6.js} +2 -2
- package/langwatch/dist/client/assets/{annotations-CHZQrha6.js → annotations-1rVXiDRQ.js} +2 -2
- package/langwatch/dist/client/assets/{api-keys-BT7HExHM.js → api-keys-BJpKyuaz.js} +2 -2
- package/langwatch/dist/client/assets/{audit-log-BGk-51Dt.js → audit-log-BdUdZjxp.js} +2 -2
- package/langwatch/dist/client/assets/{authentication-DvwXfkp-.js → authentication-8mQB00CC.js} +2 -2
- package/langwatch/dist/client/assets/{authorize-tXpHrWyw.js → authorize-BpUueMNW.js} +2 -2
- package/langwatch/dist/client/assets/{authorize-CRu9xlpU.js → authorize-CbNBtmxW.js} +2 -2
- package/langwatch/dist/client/assets/{automations-CjDvz9Ak.js → automations-34KMkRxd.js} +2 -2
- package/langwatch/dist/client/assets/{billing-plans-FUqEPN62.js → billing-plans-BUQp08MI.js} +2 -2
- package/langwatch/dist/client/assets/{budgets-BV6_RHrs.js → budgets-CdelE8Hv.js} +2 -2
- package/langwatch/dist/client/assets/{cache-rules-CtYA79E_.js → cache-rules-D2m1QlNJ.js} +2 -2
- package/langwatch/dist/client/assets/choose-C0LdeUiH.js +2 -0
- package/langwatch/dist/client/assets/{command-bar-CaJygoez.js → command-bar-DUK45yin.js} +7 -9
- package/langwatch/dist/client/assets/custom-hBq2K4FJ.js +1 -0
- package/langwatch/dist/client/assets/{datasets-vLWpH84_.js → datasets-ErNNhmjg.js} +2 -2
- package/langwatch/dist/client/assets/{dejaview-DwVR3RGg.js → dejaview-BaD4_v90.js} +2 -2
- package/langwatch/dist/client/assets/{dist-SwV3YZv3.js → dist-Cds4Mqhj.js} +4 -6
- package/langwatch/dist/client/assets/{edit-CyxsmQmW.js → edit-DpT8ejBV.js} +2 -2
- package/langwatch/dist/client/assets/{evaluations-BfgeZMph.js → evaluations-BdQ2Dm2r.js} +2 -2
- package/langwatch/dist/client/assets/{evaluations-HSQIMvbX.js → evaluations-C90I4VAr.js} +2 -2
- package/langwatch/dist/client/assets/{evaluators-DLHVvnrh.js → evaluators-ig_ugRLt.js} +2 -2
- package/langwatch/dist/client/assets/{foundry-Ckq0WjPU.js → foundry-B-X_80pD.js} +2 -2
- package/langwatch/dist/client/assets/{gateway-CDSYPZ6w.js → gateway-CS_mtJx-.js} +2 -2
- package/langwatch/dist/client/assets/{groups-CCCRUqPj.js → groups-Bp90ChP3.js} +2 -2
- package/langwatch/dist/client/assets/{index-Bm6z2fM9.js → index-TNQ6uyis.js} +4 -4
- package/langwatch/dist/client/assets/{license-CHOarGWr.js → license-CgnlvyuI.js} +2 -2
- package/langwatch/dist/client/assets/{me-CBya_vXs.js → me-DEqhm_KC.js} +2 -2
- package/langwatch/dist/client/assets/{members-lIFLh-rh.js → members-CUJANDtH.js} +2 -2
- package/langwatch/dist/client/assets/{messages-CG9j8Dz8.js → messages-fQBfCjvp.js} +2 -2
- package/langwatch/dist/client/assets/{metrics-C9pzeaI6.js → metrics-DeIxebpD.js} +2 -2
- package/langwatch/dist/client/assets/{model-costs-Bc5uqjkl.js → model-costs-C1RbgK--.js} +2 -2
- package/langwatch/dist/client/assets/{model-providers-B5UjRgS_.js → model-providers-Pv3ML_-t.js} +2 -2
- package/langwatch/dist/client/assets/{my-queue-BkEfiWyR.js → my-queue-BLre2NMr.js} +2 -2
- package/langwatch/dist/client/assets/{ops-Cc-g-CMn.js → ops-CCw-FJaT.js} +2 -2
- package/langwatch/dist/client/assets/{organization-features-CoIKKHkQ.js → organization-features-rqg-75mI.js} +2 -2
- package/langwatch/dist/client/assets/{organizations-DWcQUTzi.js → organizations-DjCzIHVx.js} +2 -2
- package/langwatch/dist/client/assets/{persistence-CTQ44vGL.js → persistence-BPvHS0F6.js} +2 -2
- package/langwatch/dist/client/assets/{plans-Dq3eFg5K.js → plans-Ch2Ol-Fd.js} +2 -2
- package/langwatch/dist/client/assets/{projections-CTNj1QBM.js → projections-it4FOVjm.js} +2 -2
- package/langwatch/dist/client/assets/{projects-BxM7C87h.js → projects-CjWZFLfn.js} +2 -2
- package/langwatch/dist/client/assets/{prompts-DhXnJT6e.js → prompts-DilmFH_s.js} +2 -2
- package/langwatch/dist/client/assets/{providers-DW7VWdqq.js → providers-tlLT_lTF.js} +2 -2
- package/langwatch/dist/client/assets/{reports-D3QFKhNP.js → reports-vlrcTrLs.js} +2 -2
- package/langwatch/dist/client/assets/{roles-B_0t5DWA.js → roles-DNgi-NQ9.js} +2 -2
- package/langwatch/dist/client/assets/{scenarios-BX3XslU0.js → scenarios-BmG_wDkR.js} +2 -2
- package/langwatch/dist/client/assets/{scim-DDsLO39r.js → scim-BKr1_FHt.js} +2 -2
- package/langwatch/dist/client/assets/{secrets-BvEGwDCy.js → secrets-CU8ocTGv.js} +2 -2
- package/langwatch/dist/client/assets/{settings-9giNiAQQ.js → settings-CDzdoYVK.js} +2 -2
- package/langwatch/dist/client/assets/{setup-HxXKoVKG.js → setup-nEvn2rjN.js} +2 -2
- package/langwatch/dist/client/assets/{subscription-DhyswDze.js → subscription-BPNl_6jF.js} +3 -3
- package/langwatch/dist/client/assets/{subscriptions-Dyyau22a.js → subscriptions-D0G-OE5C.js} +2 -2
- package/langwatch/dist/client/assets/{teams-DRmeAxzf.js → teams-DThgDQvB.js} +2 -2
- package/langwatch/dist/client/assets/{textOverflowHeuristic-JibhpzDV.js → textOverflowHeuristic-DTC8-Ffx.js} +2 -2
- package/langwatch/dist/client/assets/{topic-clustering-Bllfw5rZ.js → topic-clustering-BR2Mbpao.js} +2 -2
- package/langwatch/dist/client/assets/{topics-CpiGYxqb.js → topics-CI8GoNqp.js} +2 -2
- package/langwatch/dist/client/assets/{traceExecutor-CiHXJB0V.js → traceExecutor-CDUGyUaw.js} +2 -2
- package/langwatch/dist/client/assets/{usage-BnsstwBY.js → usage-B4mR7ut_.js} +2 -2
- package/langwatch/dist/client/assets/{usage-CoyGtJoI.js → usage-C8fbffYi.js} +2 -2
- package/langwatch/dist/client/assets/{useAdminResource-SPC5iBHM.js → useAdminResource-SmnnHro6.js} +2 -2
- package/langwatch/dist/client/assets/{useAnnotationQueues-2DKZTC7r.js → useAnnotationQueues-CA6Vk--V.js} +2 -2
- package/langwatch/dist/client/assets/{useAvailableEvaluators-HndTl2LV.js → useAvailableEvaluators-hmbmcRQr.js} +2 -2
- package/langwatch/dist/client/assets/{useDeleteDatasetConfirmation-BgWN6Qqb.js → useDeleteDatasetConfirmation-BCK_zUUe.js} +2 -2
- package/langwatch/dist/client/assets/{useWorkflowStore-e1wFCvo2.js → useWorkflowStore-QUJ3J8X9.js} +2 -2
- package/langwatch/dist/client/assets/{users-C6wjliCC.js → users-CfhanCfR.js} +2 -2
- package/langwatch/dist/client/assets/{users-tF6ZKeV1.js → users-HjuN3o6k.js} +2 -2
- package/langwatch/dist/client/assets/{virtual-keys-BL-65S0B.js → virtual-keys-Bj-MhW66.js} +2 -2
- package/langwatch/dist/client/assets/{wizard-faGkpZDT.js → wizard-dRWCVVx6.js} +2 -2
- package/langwatch/dist/client/assets/{workbench-Oj0s_YR-.js → workbench-CuixH3G1.js} +2 -2
- package/langwatch/dist/client/assets/{workflows-Cu9k-Twu.js → workflows-BT6m4Yu9.js} +2 -2
- package/langwatch/dist/client/index.html +3 -3
- package/langwatch/scripts/seed-dogfood-password.ts +163 -0
- package/langwatch/src/app/api/workflows/post_event/__tests__/post-event-evaluator.integration.test.ts +458 -0
- package/langwatch/src/app/api/workflows/post_event/__tests__/post-event-routing.test.ts +180 -0
- package/langwatch/src/app/api/workflows/post_event/__tests__/post-event.integration.test.ts +274 -0
- package/langwatch/src/app/api/workflows/post_event/post-event.ts +29 -1
- package/langwatch/src/components/agents/AgentCodeEditorDrawer.tsx +4 -5
- package/langwatch/src/components/agents/__tests__/AgentCodeEditorDrawer.integration.test.tsx +40 -0
- package/langwatch/src/components/evaluations/wizard/hooks/evaluation-wizard-store/slices/factories/__tests__/code-execution-node.factory.unit.test.ts +47 -0
- package/langwatch/src/components/evaluations/wizard/hooks/evaluation-wizard-store/slices/factories/code-execution-node.factory.ts +2 -4
- package/langwatch/src/components/experiments/BatchEvaluationV2/BatchEvaluationV2EvaluationResults.tsx +6 -1
- package/langwatch/src/optimization_studio/__tests__/registry.test.ts +29 -1
- package/langwatch/src/optimization_studio/components/Optimize.tsx +17 -3
- package/langwatch/src/optimization_studio/components/properties/AgentPropertiesPanel.tsx +4 -5
- package/langwatch/src/optimization_studio/hooks/workflowStoreCore.ts +17 -6
- package/langwatch/src/optimization_studio/hooks/workflowStoreCore.unit.test.ts +42 -0
- package/langwatch/src/optimization_studio/registry.ts +2 -4
- package/langwatch/src/optimization_studio/server/lambda/index.ts +12 -2
- package/langwatch/src/server/api/routers/workflows.ts +18 -0
- package/langwatch/src/server/evaluations-v3/execution/workflowBuilder.ts +3 -2
- package/langwatch/src/server/evaluations-v3/services/__tests__/experiment-run.service.getRun-null.unit.test.ts +71 -0
- package/langwatch/src/server/evaluations-v3/services/experiment-run.service.ts +18 -9
- package/langwatch/src/server/modelProviders/utils.ts +11 -1
- package/langwatch/src/server/nlpgo/__tests__/nlpgoFetch.integration.test.ts +248 -0
- package/langwatch/src/server/nlpgo/nlpgoFetch.ts +142 -0
- package/langwatch/src/server/routes/__tests__/playground-proxy.integration.test.ts +242 -0
- package/langwatch/src/server/routes/playground.ts +11 -1
- package/langwatch/src/server/routes/workflows.ts +17 -0
- package/langwatch/src/server/topicClustering/topicClustering.ts +33 -8
- package/langwatch/src/server/workflows/runWorkflow.ts +10 -13
- package/langwatch_nlp/langwatch_nlp/topic_clustering/topic_naming.py +39 -32
- package/langwatch_nlp/scripts/entrypoint.sh +67 -0
- package/package.json +1 -1
- package/packages/server/dist/cli.cjs +67 -94
- package/langwatch/dist/client/assets/ChatWindow-DzB-tNlQ.js +0 -1
- package/langwatch/dist/client/assets/_not-found-PEUaWdF3.js +0 -1
- package/langwatch/dist/client/assets/_slug_-C-8AjsjC.js +0 -2
- package/langwatch/dist/client/assets/choose--PBky27o.js +0 -2
- package/langwatch/dist/client/assets/custom-CSiS1liN.js +0 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "langevals-topic_clustering"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "LangEvals Topic Clustering — special evaluator for batch + incremental topic clustering. Migrated from langwatch_nlp/topic_clustering."
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "Rogerio Chaves", email = "rogerio@langwatch.ai"},
|
|
7
|
+
]
|
|
8
|
+
license = {text = "MIT"}
|
|
9
|
+
requires-python = ">=3.11"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"langevals-core>=0.1.0",
|
|
12
|
+
"fastapi>=0.111.1,<1",
|
|
13
|
+
# Pinned to match the rest of the langevals workspace (>=1.79.0 across
|
|
14
|
+
# langevals-core, ragas, langevals, legacy). Tightening to >=1.81.3 forced
|
|
15
|
+
# uv to look for pre-releases of langchain-openai (constrained <0.3.0 by
|
|
16
|
+
# the legacy evaluator), which broke the workspace lock resolution.
|
|
17
|
+
"litellm>=1.79.0",
|
|
18
|
+
"numpy>=1.26.4,<3",
|
|
19
|
+
"scikit-learn>=1.5.2,<2",
|
|
20
|
+
"scipy>=1.14.1,<2",
|
|
21
|
+
"tenacity>=8.5.0,<9",
|
|
22
|
+
"structlog>=24.1.0",
|
|
23
|
+
"nanoid>=2.0.0,<3",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[dependency-groups]
|
|
27
|
+
test = [
|
|
28
|
+
"pytest>=7.4.2",
|
|
29
|
+
"python-dotenv>=1.0.1",
|
|
30
|
+
# Imported by the ported test suite (pytest_httpx for HTTPXMock,
|
|
31
|
+
# pandas for the integration-test CSV fixtures, httpx for direct
|
|
32
|
+
# client calls). Without them, pytest collection fails on import,
|
|
33
|
+
# which compounds with langevals's pass_rate_plugin assuming
|
|
34
|
+
# session.pass_rates was set in pytest_collection_modifyitems and
|
|
35
|
+
# produces an obscured AttributeError instead of the real
|
|
36
|
+
# ModuleNotFoundError. Pinning here keeps the test deps scoped to
|
|
37
|
+
# the topic_clustering workspace member.
|
|
38
|
+
"pytest-httpx>=0.30.0",
|
|
39
|
+
"pandas>=2.2.3,<3",
|
|
40
|
+
"httpx>=0.27.0",
|
|
41
|
+
]
|
|
42
|
+
dev = ["ipykernel>=6.29.4"]
|
|
43
|
+
|
|
44
|
+
[build-system]
|
|
45
|
+
requires = ["hatchling"]
|
|
46
|
+
build-backend = "hatchling.build"
|
|
47
|
+
|
|
48
|
+
[tool.hatch.build.targets.wheel]
|
|
49
|
+
packages = ["langevals_topic_clustering"]
|
|
50
|
+
|
|
51
|
+
[tool.uv.sources]
|
|
52
|
+
langevals-core = { workspace = true }
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import random
|
|
4
|
+
import re
|
|
5
|
+
import pytest
|
|
6
|
+
from fastapi import FastAPI
|
|
7
|
+
from fastapi.testclient import TestClient
|
|
8
|
+
import httpx
|
|
9
|
+
import pandas as pd
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
import langevals_topic_clustering.batch_clustering as batch_clustering
|
|
13
|
+
import langevals_topic_clustering.incremental_clustering as incremental_clustering
|
|
14
|
+
|
|
15
|
+
from langevals_topic_clustering.types import TopicClusteringResponse, Trace
|
|
16
|
+
from pytest_httpx import HTTPXMock
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@pytest.fixture(scope="module")
|
|
20
|
+
def client():
|
|
21
|
+
app = FastAPI()
|
|
22
|
+
batch_clustering.setup_endpoints(app)
|
|
23
|
+
incremental_clustering.setup_endpoints(app)
|
|
24
|
+
return TestClient(app)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.mark.integration
|
|
28
|
+
@pytest.mark.skipif(
|
|
29
|
+
not os.path.exists("notebooks/data/traces_for_topics_KAXYxPR8MUgTcP8CF193y.csv"),
|
|
30
|
+
reason="Test CSV data file not available"
|
|
31
|
+
)
|
|
32
|
+
class TestTopicClusteringIntegration:
|
|
33
|
+
@pytest.mark.asyncio
|
|
34
|
+
async def test_it_does_batch_clustering(self, client, httpx_mock: HTTPXMock):
|
|
35
|
+
# Look at the jupyter notebook to see how to download this data
|
|
36
|
+
df = pd.read_csv(f"notebooks/data/traces_for_topics_KAXYxPR8MUgTcP8CF193y.csv")
|
|
37
|
+
df["embeddings"] = df["embeddings"].apply(
|
|
38
|
+
lambda x: list(map(float, x[1:-1].split(", ")))
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
traces: list[Trace] = []
|
|
42
|
+
for _, row in df[0:100].iterrows():
|
|
43
|
+
traces.append(
|
|
44
|
+
Trace(
|
|
45
|
+
trace_id=row["trace_id"],
|
|
46
|
+
input=row["input"],
|
|
47
|
+
embeddings=row["embeddings"],
|
|
48
|
+
topic_id=None,
|
|
49
|
+
subtopic_id=None,
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
def mock_openai(request: httpx.Request):
|
|
54
|
+
if "/embeddings" in str(request.url):
|
|
55
|
+
return httpx.Response(
|
|
56
|
+
status_code=200,
|
|
57
|
+
json={
|
|
58
|
+
"object": "list",
|
|
59
|
+
"data": [
|
|
60
|
+
{
|
|
61
|
+
"object": "embedding",
|
|
62
|
+
"index": 0,
|
|
63
|
+
"embedding": [random.random()] * 1536,
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"model": "text-embedding-3-small",
|
|
67
|
+
"usage": {"prompt_tokens": 5, "total_tokens": 5},
|
|
68
|
+
},
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
return httpx.Response(
|
|
72
|
+
status_code=200,
|
|
73
|
+
json=create_openai_chat_completion_mock(
|
|
74
|
+
len(re.findall(r"topic_\d+", str(request.content)))
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
httpx_mock.add_callback(
|
|
79
|
+
mock_openai,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
response = client.post(
|
|
83
|
+
"/topics/batch_clustering",
|
|
84
|
+
json={
|
|
85
|
+
"model": "openai/gpt-5-mini",
|
|
86
|
+
"litellm_params": {},
|
|
87
|
+
"embeddings_litellm_params": {
|
|
88
|
+
"model": "openai/text-embedding-3-small",
|
|
89
|
+
"api_key": os.getenv("OPENAI_API_KEY", "dummy-key-for-mocked-tests"),
|
|
90
|
+
},
|
|
91
|
+
"traces": traces,
|
|
92
|
+
},
|
|
93
|
+
)
|
|
94
|
+
result: TopicClusteringResponse = response.json()
|
|
95
|
+
|
|
96
|
+
assert response.status_code == 200
|
|
97
|
+
assert len(result["topics"]) > 0
|
|
98
|
+
assert "sample topic name" in result["topics"][0]["name"]
|
|
99
|
+
assert len(result["subtopics"]) > 0
|
|
100
|
+
assert len(result["traces"]) > 0
|
|
101
|
+
assert result["cost"]["amount"] > 0
|
|
102
|
+
|
|
103
|
+
response = client.post(
|
|
104
|
+
"/topics/incremental_clustering",
|
|
105
|
+
json={
|
|
106
|
+
"model": "openai/gpt-5-mini",
|
|
107
|
+
"litellm_params": {},
|
|
108
|
+
"embeddings_litellm_params": {
|
|
109
|
+
"model": "openai/text-embedding-3-small",
|
|
110
|
+
"api_key": os.getenv("OPENAI_API_KEY", "dummy-key-for-mocked-tests"),
|
|
111
|
+
},
|
|
112
|
+
"topics": result["topics"],
|
|
113
|
+
"subtopics": result["subtopics"],
|
|
114
|
+
"traces": traces,
|
|
115
|
+
},
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
assert response.status_code == 200
|
|
119
|
+
result: TopicClusteringResponse = response.json()
|
|
120
|
+
|
|
121
|
+
assert len(result["traces"]) > 0
|
|
122
|
+
assert len(result["topics"]) == 0
|
|
123
|
+
assert len(result["subtopics"]) == 0
|
|
124
|
+
assert result["cost"]["amount"] == 0
|
|
125
|
+
|
|
126
|
+
@pytest.mark.asyncio
|
|
127
|
+
@pytest.mark.skip # uncomment to run this test, it intentionally throws errors multiple times before succeeding to test retry and error handling
|
|
128
|
+
async def test_it_works_even_if_azure_throws_error_for_certain_requests(
|
|
129
|
+
self, client, httpx_mock: HTTPXMock
|
|
130
|
+
):
|
|
131
|
+
# Look at the jupyter notebook to see how to download this data
|
|
132
|
+
df = pd.read_csv(f"notebooks/data/traces_for_topics_KAXYxPR8MUgTcP8CF193y.csv")
|
|
133
|
+
df["embeddings"] = df["embeddings"].apply(
|
|
134
|
+
lambda x: list(map(float, x[1:-1].split(", ")))
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
traces: list[Trace] = []
|
|
138
|
+
for _, row in df[0:100].iterrows():
|
|
139
|
+
traces.append(
|
|
140
|
+
Trace(
|
|
141
|
+
trace_id=row["trace_id"],
|
|
142
|
+
input=row["input"],
|
|
143
|
+
embeddings=row["embeddings"],
|
|
144
|
+
topic_id=None,
|
|
145
|
+
subtopic_id=None,
|
|
146
|
+
)
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
requests = {}
|
|
150
|
+
|
|
151
|
+
def fail_specific_request(request: httpx.Request):
|
|
152
|
+
if "/embeddings" in str(request.url):
|
|
153
|
+
return httpx.Response(
|
|
154
|
+
status_code=200,
|
|
155
|
+
json={
|
|
156
|
+
"object": "list",
|
|
157
|
+
"data": [
|
|
158
|
+
{
|
|
159
|
+
"object": "embedding",
|
|
160
|
+
"index": 0,
|
|
161
|
+
"embedding": [random.random()] * 1536,
|
|
162
|
+
}
|
|
163
|
+
],
|
|
164
|
+
"model": "text-embedding-3-small",
|
|
165
|
+
"usage": {"prompt_tokens": 5, "total_tokens": 5},
|
|
166
|
+
},
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
if str(request.content) not in requests:
|
|
170
|
+
requests[str(request.content)] = True
|
|
171
|
+
|
|
172
|
+
if list(requests.keys()).index(str(request.content)) == 0:
|
|
173
|
+
raise Exception("stop")
|
|
174
|
+
|
|
175
|
+
return httpx.Response(
|
|
176
|
+
status_code=200,
|
|
177
|
+
json=create_openai_chat_completion_mock(
|
|
178
|
+
len(re.findall(r"topic_\d+", str(request.content)))
|
|
179
|
+
),
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
httpx_mock.add_callback(
|
|
183
|
+
fail_specific_request,
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
response = client.post(
|
|
187
|
+
"/topics/batch_clustering",
|
|
188
|
+
json={
|
|
189
|
+
"model": "openai/gpt-5-mini",
|
|
190
|
+
"litellm_params": {},
|
|
191
|
+
"embeddings_litellm_params": {
|
|
192
|
+
"model": "openai/text-embedding-3-small",
|
|
193
|
+
"api_key": os.getenv("OPENAI_API_KEY", "dummy-key-for-mocked-tests"),
|
|
194
|
+
},
|
|
195
|
+
"traces": traces,
|
|
196
|
+
},
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
assert response.status_code == 200
|
|
200
|
+
assert response.json()
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def create_openai_chat_completion_mock(n):
|
|
204
|
+
return {
|
|
205
|
+
"id": "chatcmpl-86zIvz53Wa4qTc1ksUt3coF5yTvm7",
|
|
206
|
+
"object": "chat.completion",
|
|
207
|
+
"created": 1696676313,
|
|
208
|
+
"model": "gpt-5-mini",
|
|
209
|
+
"choices": [
|
|
210
|
+
{
|
|
211
|
+
"index": 0,
|
|
212
|
+
"logprobs": None,
|
|
213
|
+
"message": {
|
|
214
|
+
"role": "assistant",
|
|
215
|
+
"content": None,
|
|
216
|
+
"function_call": None,
|
|
217
|
+
"tool_calls": [
|
|
218
|
+
{
|
|
219
|
+
"function": {
|
|
220
|
+
"name": "test",
|
|
221
|
+
"arguments": json.dumps(
|
|
222
|
+
dict(
|
|
223
|
+
[
|
|
224
|
+
(f"topic_{index}", "sample topic name")
|
|
225
|
+
for index in range(n)
|
|
226
|
+
]
|
|
227
|
+
),
|
|
228
|
+
ensure_ascii=False,
|
|
229
|
+
),
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
],
|
|
233
|
+
},
|
|
234
|
+
"finish_reason": "stop",
|
|
235
|
+
}
|
|
236
|
+
],
|
|
237
|
+
"usage": {"prompt_tokens": 5, "completion_tokens": 16, "total_tokens": 21},
|
|
238
|
+
"system_fingerprint": None,
|
|
239
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pytest
|
|
3
|
+
from fastapi import FastAPI
|
|
4
|
+
from fastapi.testclient import TestClient
|
|
5
|
+
import pandas as pd
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import langevals_topic_clustering.batch_clustering as batch_clustering
|
|
9
|
+
import langevals_topic_clustering.incremental_clustering as incremental_clustering
|
|
10
|
+
|
|
11
|
+
from langevals_topic_clustering.types import TopicClusteringResponse, Trace
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@pytest.fixture(scope="module")
|
|
15
|
+
def client():
|
|
16
|
+
app = FastAPI()
|
|
17
|
+
batch_clustering.setup_endpoints(app)
|
|
18
|
+
incremental_clustering.setup_endpoints(app)
|
|
19
|
+
return TestClient(app)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
CSV_DATA_PATH: Path = Path("notebooks/data/traces_for_topics_KAXYxPR8MUgTcP8CF193y.csv")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TestTopicClusteringIntegration:
|
|
26
|
+
@pytest.mark.integration
|
|
27
|
+
@pytest.mark.asyncio
|
|
28
|
+
@pytest.mark.skipif(
|
|
29
|
+
not CSV_DATA_PATH.exists() or not os.getenv("AZURE_OPENAI_ENDPOINT") or not os.getenv("OPENAI_API_KEY"),
|
|
30
|
+
reason="Test data CSV file or required environment variables (AZURE_OPENAI_ENDPOINT, OPENAI_API_KEY) not available"
|
|
31
|
+
)
|
|
32
|
+
# NOTE: disable httpx_mock to see it working fully integrated
|
|
33
|
+
async def test_it_does_batch_clustering(self, client):
|
|
34
|
+
# Look at the jupyter notebook to see how to download this data
|
|
35
|
+
df = pd.read_csv(CSV_DATA_PATH)
|
|
36
|
+
df["embeddings"] = df["embeddings"].apply(
|
|
37
|
+
lambda x: list(map(float, x[1:-1].split(", ")))
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
traces: list[Trace] = []
|
|
41
|
+
for _, row in df[0:100].iterrows():
|
|
42
|
+
traces.append(
|
|
43
|
+
Trace(
|
|
44
|
+
trace_id=row["trace_id"],
|
|
45
|
+
input=row["input"],
|
|
46
|
+
topic_id=None,
|
|
47
|
+
subtopic_id=None,
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
response = client.post(
|
|
52
|
+
"/topics/batch_clustering",
|
|
53
|
+
json={
|
|
54
|
+
"litellm_params": {
|
|
55
|
+
"api_base": os.environ["AZURE_OPENAI_ENDPOINT"],
|
|
56
|
+
"model": "azure/gpt-5-mini",
|
|
57
|
+
},
|
|
58
|
+
"embeddings_litellm_params": {
|
|
59
|
+
"api_key": os.environ["OPENAI_API_KEY"],
|
|
60
|
+
"model": "openai/text-embedding-3-small",
|
|
61
|
+
},
|
|
62
|
+
"traces": traces,
|
|
63
|
+
},
|
|
64
|
+
)
|
|
65
|
+
result: TopicClusteringResponse = response.json()
|
|
66
|
+
|
|
67
|
+
assert response.status_code == 200
|
|
68
|
+
assert len(result["topics"]) > 0
|
|
69
|
+
assert type(result["topics"][0]["name"]) == str
|
|
70
|
+
assert len(result["subtopics"]) > 0
|
|
71
|
+
assert len(result["traces"]) > 0
|
|
72
|
+
assert result["cost"]["amount"] > 0
|
|
73
|
+
|
|
74
|
+
response = client.post(
|
|
75
|
+
"/topics/incremental_clustering",
|
|
76
|
+
json={
|
|
77
|
+
"litellm_params": {
|
|
78
|
+
"api_base": os.environ["AZURE_OPENAI_ENDPOINT"],
|
|
79
|
+
"model": "azure/gpt-5-mini",
|
|
80
|
+
},
|
|
81
|
+
"embeddings_litellm_params": {
|
|
82
|
+
"api_key": os.environ["OPENAI_API_KEY"],
|
|
83
|
+
"model": "openai/text-embedding-3-small",
|
|
84
|
+
},
|
|
85
|
+
"topics": result["topics"],
|
|
86
|
+
"subtopics": result["subtopics"],
|
|
87
|
+
"traces": traces,
|
|
88
|
+
},
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
assert response.status_code == 200
|
|
92
|
+
result: TopicClusteringResponse = response.json()
|
|
93
|
+
|
|
94
|
+
assert len(result["traces"]) > 0
|
|
95
|
+
assert len(result["topics"]) == 0
|
|
96
|
+
assert len(result["subtopics"]) == 0
|
|
97
|
+
assert result["cost"]["amount"] == 0
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import unittest
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from langevals_topic_clustering.topic_naming import (
|
|
6
|
+
generate_topic_names,
|
|
7
|
+
improve_similar_names,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TopicClusteringTopicNamingTestCase(unittest.IsolatedAsyncioTestCase):
|
|
12
|
+
@pytest.mark.integration
|
|
13
|
+
@pytest.mark.skipif(
|
|
14
|
+
not os.getenv("AZURE_OPENAI_ENDPOINT"),
|
|
15
|
+
reason="AZURE_OPENAI_ENDPOINT environment variable not set"
|
|
16
|
+
)
|
|
17
|
+
async def test_it_generates_topic_names(self):
|
|
18
|
+
topic_names, _cost = generate_topic_names(
|
|
19
|
+
{
|
|
20
|
+
"model": "azure/gpt-4-1106-preview",
|
|
21
|
+
"api_base": os.environ["AZURE_OPENAI_ENDPOINT"],
|
|
22
|
+
},
|
|
23
|
+
[
|
|
24
|
+
["example1", "example2"],
|
|
25
|
+
["foo", "bar"],
|
|
26
|
+
],
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
assert len(topic_names) == 2
|
|
30
|
+
print("\n\ntopic_names", topic_names, "\n\n")
|
|
31
|
+
assert type(topic_names[0]) == str
|
|
32
|
+
assert type(topic_names[1]) == str
|
|
33
|
+
|
|
34
|
+
topic_names, _cost = improve_similar_names(
|
|
35
|
+
litellm_params={
|
|
36
|
+
"model": "azure/gpt-4-1106-preview",
|
|
37
|
+
"api_base": os.environ["AZURE_OPENAI_ENDPOINT"],
|
|
38
|
+
},
|
|
39
|
+
embeddings_litellm_params={"model": "openai/text-embedding-3-small"},
|
|
40
|
+
topic_names=topic_names, # type: ignore
|
|
41
|
+
topic_examples=[
|
|
42
|
+
["example1", "example2"],
|
|
43
|
+
["foo", "bar"],
|
|
44
|
+
],
|
|
45
|
+
max_iterations=3,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
assert len(topic_names) == 2
|
|
49
|
+
print("\n\nimproved topic_names", topic_names, "\n\n")
|
|
50
|
+
assert type(topic_names[0]) == str
|
|
51
|
+
assert type(topic_names[1]) == str
|
|
52
|
+
|
|
53
|
+
@pytest.mark.integration
|
|
54
|
+
@pytest.mark.skipif(
|
|
55
|
+
not os.getenv("AZURE_OPENAI_ENDPOINT"),
|
|
56
|
+
reason="AZURE_OPENAI_ENDPOINT environment variable not set"
|
|
57
|
+
)
|
|
58
|
+
async def test_it_avoid_already_existing_topic_names(self):
|
|
59
|
+
topic_names, _cost = generate_topic_names(
|
|
60
|
+
{
|
|
61
|
+
"model": "azure/gpt-4-1106-preview",
|
|
62
|
+
"api_base": os.environ["AZURE_OPENAI_ENDPOINT"],
|
|
63
|
+
},
|
|
64
|
+
[
|
|
65
|
+
["example1", "example2"],
|
|
66
|
+
["foo", "bar"],
|
|
67
|
+
],
|
|
68
|
+
existing=["Generic Examples"],
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
print("\n\ntopic_names", topic_names, "\n\n")
|
|
72
|
+
assert topic_names[0] != "Generic Examples"
|
|
@@ -85,7 +85,13 @@ def pytest_runtest_logreport(report):
|
|
|
85
85
|
|
|
86
86
|
|
|
87
87
|
def pytest_sessionfinish(session, exitstatus):
|
|
88
|
-
|
|
88
|
+
# `pass_rates` is set in pytest_collection_modifyitems which only runs
|
|
89
|
+
# if collection succeeds. If collection errors out (import failure,
|
|
90
|
+
# missing dep, etc.) sessionfinish still runs and would AttributeError
|
|
91
|
+
# here, masking the real failure with an unhelpful traceback. Default
|
|
92
|
+
# to {} so the underlying collection error remains visible.
|
|
93
|
+
pass_rates = getattr(session, "pass_rates", {})
|
|
94
|
+
for group_name, data in pass_rates.items():
|
|
89
95
|
pass_rate = len(data["passed"]) / data["total"]
|
|
90
96
|
required_rate = data["required_rate"]
|
|
91
97
|
if pass_rate < required_rate:
|
|
@@ -111,6 +111,34 @@ for evaluator_name, evaluator_package in evaluators.items():
|
|
|
111
111
|
create_evaluator_routes(evaluator_cls)
|
|
112
112
|
|
|
113
113
|
|
|
114
|
+
# Special-case: topic_clustering is a langevals workspace member but does
|
|
115
|
+
# NOT fit the per-trace evaluator interface (it's a batch operation that
|
|
116
|
+
# returns topics + assignments, not a per-trace score). It registers its
|
|
117
|
+
# own /topics/batch_clustering and /topics/incremental_clustering routes
|
|
118
|
+
# via a register_routes(app) hook. Imported conditionally so per-evaluator
|
|
119
|
+
# Lambda builds (--extra azure / openai / ragas / …) that don't include
|
|
120
|
+
# topic_clustering keep working.
|
|
121
|
+
def _maybe_register_topic_clustering_routes() -> None:
|
|
122
|
+
only_filter = (
|
|
123
|
+
sys.argv[2].split(",")
|
|
124
|
+
if len(sys.argv) > 2 and sys.argv[1] == "--only"
|
|
125
|
+
else None
|
|
126
|
+
)
|
|
127
|
+
if only_filter is not None and "topic_clustering" not in only_filter:
|
|
128
|
+
return
|
|
129
|
+
try:
|
|
130
|
+
from langevals_topic_clustering import register_routes as _register
|
|
131
|
+
except ImportError:
|
|
132
|
+
# Package not installed in this build; skip silently — matches the
|
|
133
|
+
# per-evaluator deploy model where each Lambda only ships one extra.
|
|
134
|
+
return
|
|
135
|
+
print("Loading langevals_topic_clustering (special routes)")
|
|
136
|
+
_register(app)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
_maybe_register_topic_clustering_routes()
|
|
140
|
+
|
|
141
|
+
|
|
114
142
|
@app.get("/healthcheck")
|
|
115
143
|
async def healthcheck():
|
|
116
144
|
return {"status": "healthy"}
|
package/langevals/pyproject.toml
CHANGED
|
@@ -28,6 +28,7 @@ lingua = ["langevals-lingua"]
|
|
|
28
28
|
langevals = ["langevals-langevals"]
|
|
29
29
|
presidio = ["langevals-presidio"]
|
|
30
30
|
legacy = ["langevals-legacy"]
|
|
31
|
+
topic_clustering = ["langevals-topic_clustering"]
|
|
31
32
|
all = [
|
|
32
33
|
"langevals-azure",
|
|
33
34
|
"langevals-langevals",
|
|
@@ -36,6 +37,7 @@ all = [
|
|
|
36
37
|
"langevals-ragas",
|
|
37
38
|
"langevals-presidio",
|
|
38
39
|
"langevals-openai",
|
|
40
|
+
"langevals-topic_clustering",
|
|
39
41
|
]
|
|
40
42
|
|
|
41
43
|
[project.scripts]
|
|
@@ -79,6 +81,7 @@ langevals-lingua = { workspace = true }
|
|
|
79
81
|
langevals-langevals = { workspace = true }
|
|
80
82
|
langevals-presidio = { workspace = true }
|
|
81
83
|
langevals-legacy = { workspace = true }
|
|
84
|
+
langevals-topic_clustering = { workspace = true }
|
|
82
85
|
|
|
83
86
|
# PyTorch CPU index for Linux
|
|
84
87
|
[[tool.uv.index]]
|