judgeval 0.1.0__py3-none-any.whl → 0.23.0__py3-none-any.whl
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.
- judgeval/__init__.py +173 -10
- judgeval/api/__init__.py +523 -0
- judgeval/api/api_types.py +413 -0
- judgeval/cli.py +112 -0
- judgeval/constants.py +7 -30
- judgeval/data/__init__.py +1 -3
- judgeval/data/evaluation_run.py +125 -0
- judgeval/data/example.py +14 -40
- judgeval/data/judgment_types.py +396 -146
- judgeval/data/result.py +11 -18
- judgeval/data/scorer_data.py +3 -26
- judgeval/data/scripts/openapi_transform.py +5 -5
- judgeval/data/trace.py +115 -194
- judgeval/dataset/__init__.py +335 -0
- judgeval/env.py +55 -0
- judgeval/evaluation/__init__.py +346 -0
- judgeval/exceptions.py +28 -0
- judgeval/integrations/langgraph/__init__.py +13 -0
- judgeval/integrations/openlit/__init__.py +51 -0
- judgeval/judges/__init__.py +2 -2
- judgeval/judges/litellm_judge.py +77 -16
- judgeval/judges/together_judge.py +88 -17
- judgeval/judges/utils.py +7 -20
- judgeval/judgment_attribute_keys.py +55 -0
- judgeval/{common/logger.py → logger.py} +24 -8
- judgeval/prompt/__init__.py +330 -0
- judgeval/scorers/__init__.py +11 -11
- judgeval/scorers/agent_scorer.py +15 -19
- judgeval/scorers/api_scorer.py +21 -23
- judgeval/scorers/base_scorer.py +54 -36
- judgeval/scorers/example_scorer.py +1 -3
- judgeval/scorers/judgeval_scorers/api_scorers/__init__.py +2 -24
- judgeval/scorers/judgeval_scorers/api_scorers/answer_correctness.py +2 -10
- judgeval/scorers/judgeval_scorers/api_scorers/answer_relevancy.py +2 -2
- judgeval/scorers/judgeval_scorers/api_scorers/faithfulness.py +2 -10
- judgeval/scorers/judgeval_scorers/api_scorers/instruction_adherence.py +2 -14
- judgeval/scorers/judgeval_scorers/api_scorers/prompt_scorer.py +171 -59
- judgeval/scorers/score.py +64 -47
- judgeval/scorers/utils.py +2 -107
- judgeval/tracer/__init__.py +1111 -2
- judgeval/tracer/constants.py +1 -0
- judgeval/tracer/exporters/__init__.py +40 -0
- judgeval/tracer/exporters/s3.py +119 -0
- judgeval/tracer/exporters/store.py +59 -0
- judgeval/tracer/exporters/utils.py +32 -0
- judgeval/tracer/keys.py +63 -0
- judgeval/tracer/llm/__init__.py +7 -0
- judgeval/tracer/llm/config.py +78 -0
- judgeval/tracer/llm/constants.py +9 -0
- judgeval/tracer/llm/llm_anthropic/__init__.py +3 -0
- judgeval/tracer/llm/llm_anthropic/config.py +6 -0
- judgeval/tracer/llm/llm_anthropic/messages.py +452 -0
- judgeval/tracer/llm/llm_anthropic/messages_stream.py +322 -0
- judgeval/tracer/llm/llm_anthropic/wrapper.py +59 -0
- judgeval/tracer/llm/llm_google/__init__.py +3 -0
- judgeval/tracer/llm/llm_google/config.py +6 -0
- judgeval/tracer/llm/llm_google/generate_content.py +127 -0
- judgeval/tracer/llm/llm_google/wrapper.py +30 -0
- judgeval/tracer/llm/llm_openai/__init__.py +3 -0
- judgeval/tracer/llm/llm_openai/beta_chat_completions.py +216 -0
- judgeval/tracer/llm/llm_openai/chat_completions.py +501 -0
- judgeval/tracer/llm/llm_openai/config.py +6 -0
- judgeval/tracer/llm/llm_openai/responses.py +506 -0
- judgeval/tracer/llm/llm_openai/utils.py +42 -0
- judgeval/tracer/llm/llm_openai/wrapper.py +63 -0
- judgeval/tracer/llm/llm_together/__init__.py +3 -0
- judgeval/tracer/llm/llm_together/chat_completions.py +406 -0
- judgeval/tracer/llm/llm_together/config.py +6 -0
- judgeval/tracer/llm/llm_together/wrapper.py +52 -0
- judgeval/tracer/llm/providers.py +19 -0
- judgeval/tracer/managers.py +167 -0
- judgeval/tracer/processors/__init__.py +220 -0
- judgeval/tracer/utils.py +19 -0
- judgeval/trainer/__init__.py +14 -0
- judgeval/trainer/base_trainer.py +122 -0
- judgeval/trainer/config.py +123 -0
- judgeval/trainer/console.py +144 -0
- judgeval/trainer/fireworks_trainer.py +392 -0
- judgeval/trainer/trainable_model.py +252 -0
- judgeval/trainer/trainer.py +70 -0
- judgeval/utils/async_utils.py +39 -0
- judgeval/utils/decorators/__init__.py +0 -0
- judgeval/utils/decorators/dont_throw.py +37 -0
- judgeval/utils/decorators/use_once.py +13 -0
- judgeval/utils/file_utils.py +74 -28
- judgeval/utils/guards.py +36 -0
- judgeval/utils/meta.py +27 -0
- judgeval/utils/project.py +15 -0
- judgeval/utils/serialize.py +253 -0
- judgeval/utils/testing.py +70 -0
- judgeval/utils/url.py +10 -0
- judgeval/{version_check.py → utils/version_check.py} +5 -3
- judgeval/utils/wrappers/README.md +3 -0
- judgeval/utils/wrappers/__init__.py +15 -0
- judgeval/utils/wrappers/immutable_wrap_async.py +74 -0
- judgeval/utils/wrappers/immutable_wrap_async_iterator.py +84 -0
- judgeval/utils/wrappers/immutable_wrap_sync.py +66 -0
- judgeval/utils/wrappers/immutable_wrap_sync_iterator.py +84 -0
- judgeval/utils/wrappers/mutable_wrap_async.py +67 -0
- judgeval/utils/wrappers/mutable_wrap_sync.py +67 -0
- judgeval/utils/wrappers/py.typed +0 -0
- judgeval/utils/wrappers/utils.py +35 -0
- judgeval/v1/__init__.py +88 -0
- judgeval/v1/data/__init__.py +7 -0
- judgeval/v1/data/example.py +44 -0
- judgeval/v1/data/scorer_data.py +42 -0
- judgeval/v1/data/scoring_result.py +44 -0
- judgeval/v1/datasets/__init__.py +6 -0
- judgeval/v1/datasets/dataset.py +214 -0
- judgeval/v1/datasets/dataset_factory.py +94 -0
- judgeval/v1/evaluation/__init__.py +6 -0
- judgeval/v1/evaluation/evaluation.py +182 -0
- judgeval/v1/evaluation/evaluation_factory.py +17 -0
- judgeval/v1/instrumentation/__init__.py +6 -0
- judgeval/v1/instrumentation/llm/__init__.py +7 -0
- judgeval/v1/instrumentation/llm/config.py +78 -0
- judgeval/v1/instrumentation/llm/constants.py +11 -0
- judgeval/v1/instrumentation/llm/llm_anthropic/__init__.py +5 -0
- judgeval/v1/instrumentation/llm/llm_anthropic/config.py +6 -0
- judgeval/v1/instrumentation/llm/llm_anthropic/messages.py +414 -0
- judgeval/v1/instrumentation/llm/llm_anthropic/messages_stream.py +307 -0
- judgeval/v1/instrumentation/llm/llm_anthropic/wrapper.py +61 -0
- judgeval/v1/instrumentation/llm/llm_google/__init__.py +5 -0
- judgeval/v1/instrumentation/llm/llm_google/config.py +6 -0
- judgeval/v1/instrumentation/llm/llm_google/generate_content.py +121 -0
- judgeval/v1/instrumentation/llm/llm_google/wrapper.py +30 -0
- judgeval/v1/instrumentation/llm/llm_openai/__init__.py +5 -0
- judgeval/v1/instrumentation/llm/llm_openai/beta_chat_completions.py +212 -0
- judgeval/v1/instrumentation/llm/llm_openai/chat_completions.py +477 -0
- judgeval/v1/instrumentation/llm/llm_openai/config.py +6 -0
- judgeval/v1/instrumentation/llm/llm_openai/responses.py +472 -0
- judgeval/v1/instrumentation/llm/llm_openai/utils.py +41 -0
- judgeval/v1/instrumentation/llm/llm_openai/wrapper.py +63 -0
- judgeval/v1/instrumentation/llm/llm_together/__init__.py +5 -0
- judgeval/v1/instrumentation/llm/llm_together/chat_completions.py +382 -0
- judgeval/v1/instrumentation/llm/llm_together/config.py +6 -0
- judgeval/v1/instrumentation/llm/llm_together/wrapper.py +57 -0
- judgeval/v1/instrumentation/llm/providers.py +19 -0
- judgeval/v1/integrations/claude_agent_sdk/__init__.py +119 -0
- judgeval/v1/integrations/claude_agent_sdk/wrapper.py +564 -0
- judgeval/v1/integrations/langgraph/__init__.py +13 -0
- judgeval/v1/integrations/openlit/__init__.py +47 -0
- judgeval/v1/internal/api/__init__.py +525 -0
- judgeval/v1/internal/api/api_types.py +413 -0
- judgeval/v1/prompts/__init__.py +6 -0
- judgeval/v1/prompts/prompt.py +29 -0
- judgeval/v1/prompts/prompt_factory.py +189 -0
- judgeval/v1/py.typed +0 -0
- judgeval/v1/scorers/__init__.py +6 -0
- judgeval/v1/scorers/api_scorer.py +82 -0
- judgeval/v1/scorers/base_scorer.py +17 -0
- judgeval/v1/scorers/built_in/__init__.py +17 -0
- judgeval/v1/scorers/built_in/answer_correctness.py +28 -0
- judgeval/v1/scorers/built_in/answer_relevancy.py +28 -0
- judgeval/v1/scorers/built_in/built_in_factory.py +26 -0
- judgeval/v1/scorers/built_in/faithfulness.py +28 -0
- judgeval/v1/scorers/built_in/instruction_adherence.py +28 -0
- judgeval/v1/scorers/custom_scorer/__init__.py +6 -0
- judgeval/v1/scorers/custom_scorer/custom_scorer.py +50 -0
- judgeval/v1/scorers/custom_scorer/custom_scorer_factory.py +16 -0
- judgeval/v1/scorers/prompt_scorer/__init__.py +6 -0
- judgeval/v1/scorers/prompt_scorer/prompt_scorer.py +86 -0
- judgeval/v1/scorers/prompt_scorer/prompt_scorer_factory.py +85 -0
- judgeval/v1/scorers/scorers_factory.py +49 -0
- judgeval/v1/tracer/__init__.py +7 -0
- judgeval/v1/tracer/base_tracer.py +520 -0
- judgeval/v1/tracer/exporters/__init__.py +14 -0
- judgeval/v1/tracer/exporters/in_memory_span_exporter.py +25 -0
- judgeval/v1/tracer/exporters/judgment_span_exporter.py +42 -0
- judgeval/v1/tracer/exporters/noop_span_exporter.py +19 -0
- judgeval/v1/tracer/exporters/span_store.py +50 -0
- judgeval/v1/tracer/judgment_tracer_provider.py +70 -0
- judgeval/v1/tracer/processors/__init__.py +6 -0
- judgeval/v1/tracer/processors/_lifecycles/__init__.py +28 -0
- judgeval/v1/tracer/processors/_lifecycles/agent_id_processor.py +53 -0
- judgeval/v1/tracer/processors/_lifecycles/context_keys.py +11 -0
- judgeval/v1/tracer/processors/_lifecycles/customer_id_processor.py +29 -0
- judgeval/v1/tracer/processors/_lifecycles/registry.py +18 -0
- judgeval/v1/tracer/processors/judgment_span_processor.py +165 -0
- judgeval/v1/tracer/processors/noop_span_processor.py +42 -0
- judgeval/v1/tracer/tracer.py +67 -0
- judgeval/v1/tracer/tracer_factory.py +38 -0
- judgeval/v1/trainers/__init__.py +5 -0
- judgeval/v1/trainers/base_trainer.py +62 -0
- judgeval/v1/trainers/config.py +123 -0
- judgeval/v1/trainers/console.py +144 -0
- judgeval/v1/trainers/fireworks_trainer.py +392 -0
- judgeval/v1/trainers/trainable_model.py +252 -0
- judgeval/v1/trainers/trainers_factory.py +37 -0
- judgeval/v1/utils.py +18 -0
- judgeval/version.py +5 -0
- judgeval/warnings.py +4 -0
- judgeval-0.23.0.dist-info/METADATA +266 -0
- judgeval-0.23.0.dist-info/RECORD +201 -0
- judgeval-0.23.0.dist-info/entry_points.txt +2 -0
- judgeval/clients.py +0 -34
- judgeval/common/__init__.py +0 -13
- judgeval/common/api/__init__.py +0 -3
- judgeval/common/api/api.py +0 -352
- judgeval/common/api/constants.py +0 -165
- judgeval/common/exceptions.py +0 -27
- judgeval/common/storage/__init__.py +0 -6
- judgeval/common/storage/s3_storage.py +0 -98
- judgeval/common/tracer/__init__.py +0 -31
- judgeval/common/tracer/constants.py +0 -22
- judgeval/common/tracer/core.py +0 -1916
- judgeval/common/tracer/otel_exporter.py +0 -108
- judgeval/common/tracer/otel_span_processor.py +0 -234
- judgeval/common/tracer/span_processor.py +0 -37
- judgeval/common/tracer/span_transformer.py +0 -211
- judgeval/common/tracer/trace_manager.py +0 -92
- judgeval/common/utils.py +0 -940
- judgeval/data/datasets/__init__.py +0 -4
- judgeval/data/datasets/dataset.py +0 -341
- judgeval/data/datasets/eval_dataset_client.py +0 -214
- judgeval/data/tool.py +0 -5
- judgeval/data/trace_run.py +0 -37
- judgeval/evaluation_run.py +0 -75
- judgeval/integrations/langgraph.py +0 -843
- judgeval/judges/mixture_of_judges.py +0 -286
- judgeval/judgment_client.py +0 -369
- judgeval/rules.py +0 -521
- judgeval/run_evaluation.py +0 -684
- judgeval/scorers/judgeval_scorers/api_scorers/derailment_scorer.py +0 -14
- judgeval/scorers/judgeval_scorers/api_scorers/execution_order.py +0 -52
- judgeval/scorers/judgeval_scorers/api_scorers/hallucination.py +0 -28
- judgeval/scorers/judgeval_scorers/api_scorers/tool_dependency.py +0 -20
- judgeval/scorers/judgeval_scorers/api_scorers/tool_order.py +0 -27
- judgeval/utils/alerts.py +0 -93
- judgeval/utils/requests.py +0 -50
- judgeval-0.1.0.dist-info/METADATA +0 -202
- judgeval-0.1.0.dist-info/RECORD +0 -73
- {judgeval-0.1.0.dist-info → judgeval-0.23.0.dist-info}/WHEEL +0 -0
- {judgeval-0.1.0.dist-info → judgeval-0.23.0.dist-info}/licenses/LICENSE.md +0 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from fireworks import LLM # type: ignore[import-not-found,import-untyped]
|
|
3
|
+
from .config import TrainerConfig, ModelConfig
|
|
4
|
+
from typing import Optional, Dict, Any, Callable
|
|
5
|
+
from .console import _model_spinner_progress, _print_model_progress
|
|
6
|
+
from judgeval.exceptions import JudgmentRuntimeError
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class TrainableModel:
|
|
10
|
+
"""
|
|
11
|
+
A wrapper class for managing model snapshots during training.
|
|
12
|
+
|
|
13
|
+
This class automatically handles model snapshot creation and management
|
|
14
|
+
during the RFT (Reinforcement Fine-Tuning) process,
|
|
15
|
+
abstracting away manual snapshot management from users.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
config: TrainerConfig
|
|
19
|
+
current_step: int
|
|
20
|
+
_current_model: LLM
|
|
21
|
+
_tracer_wrapper_func: Optional[Callable]
|
|
22
|
+
_base_model: LLM
|
|
23
|
+
|
|
24
|
+
def __init__(self, config: TrainerConfig):
|
|
25
|
+
"""
|
|
26
|
+
Initialize the TrainableModel.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
config: TrainerConfig instance with model configuration
|
|
30
|
+
"""
|
|
31
|
+
try:
|
|
32
|
+
self.config = config
|
|
33
|
+
self.current_step = 0
|
|
34
|
+
self._tracer_wrapper_func = None
|
|
35
|
+
|
|
36
|
+
self._base_model = self._create_base_model()
|
|
37
|
+
self._current_model = self._base_model
|
|
38
|
+
except Exception as e:
|
|
39
|
+
raise JudgmentRuntimeError(
|
|
40
|
+
f"Failed to initialize TrainableModel: {str(e)}"
|
|
41
|
+
) from e
|
|
42
|
+
|
|
43
|
+
@classmethod
|
|
44
|
+
def from_model_config(cls, model_config: ModelConfig) -> "TrainableModel":
|
|
45
|
+
"""
|
|
46
|
+
Create a TrainableModel from a saved ModelConfig.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
model_config: ModelConfig instance with saved model state
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
TrainableModel instance configured to use the saved model
|
|
53
|
+
"""
|
|
54
|
+
# Create a TrainerConfig from the ModelConfig
|
|
55
|
+
trainer_config = TrainerConfig(
|
|
56
|
+
base_model_name=model_config.base_model_name,
|
|
57
|
+
deployment_id=model_config.deployment_id,
|
|
58
|
+
user_id=model_config.user_id,
|
|
59
|
+
model_id=model_config.model_id,
|
|
60
|
+
enable_addons=model_config.enable_addons,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
instance = cls(trainer_config)
|
|
64
|
+
instance.current_step = model_config.current_step
|
|
65
|
+
|
|
66
|
+
if model_config.is_trained and model_config.current_model_name:
|
|
67
|
+
instance._load_trained_model(model_config.current_model_name)
|
|
68
|
+
|
|
69
|
+
return instance
|
|
70
|
+
|
|
71
|
+
def _create_base_model(self):
|
|
72
|
+
"""Create and configure the base model."""
|
|
73
|
+
try:
|
|
74
|
+
with _model_spinner_progress(
|
|
75
|
+
"Creating and deploying base model..."
|
|
76
|
+
) as update_progress:
|
|
77
|
+
update_progress("Creating base model instance...")
|
|
78
|
+
base_model = LLM(
|
|
79
|
+
model=self.config.base_model_name,
|
|
80
|
+
deployment_type="on-demand",
|
|
81
|
+
id=self.config.deployment_id,
|
|
82
|
+
enable_addons=self.config.enable_addons,
|
|
83
|
+
)
|
|
84
|
+
update_progress("Applying deployment configuration...")
|
|
85
|
+
base_model.apply()
|
|
86
|
+
_print_model_progress("Base model deployment ready")
|
|
87
|
+
return base_model
|
|
88
|
+
except Exception as e:
|
|
89
|
+
raise JudgmentRuntimeError(
|
|
90
|
+
f"Failed to create and deploy base model '{self.config.base_model_name}': {str(e)}"
|
|
91
|
+
) from e
|
|
92
|
+
|
|
93
|
+
def _load_trained_model(self, model_name: str):
|
|
94
|
+
"""Load a trained model by name."""
|
|
95
|
+
try:
|
|
96
|
+
with _model_spinner_progress(
|
|
97
|
+
f"Loading and deploying trained model: {model_name}"
|
|
98
|
+
) as update_progress:
|
|
99
|
+
update_progress("Creating trained model instance...")
|
|
100
|
+
self._current_model = LLM(
|
|
101
|
+
model=model_name,
|
|
102
|
+
deployment_type="on-demand-lora",
|
|
103
|
+
base_id=self.config.deployment_id,
|
|
104
|
+
)
|
|
105
|
+
update_progress("Applying deployment configuration...")
|
|
106
|
+
self._current_model.apply()
|
|
107
|
+
_print_model_progress("Trained model deployment ready")
|
|
108
|
+
|
|
109
|
+
if self._tracer_wrapper_func:
|
|
110
|
+
self._tracer_wrapper_func(self._current_model)
|
|
111
|
+
except Exception as e:
|
|
112
|
+
raise JudgmentRuntimeError(
|
|
113
|
+
f"Failed to load and deploy trained model '{model_name}': {str(e)}"
|
|
114
|
+
) from e
|
|
115
|
+
|
|
116
|
+
def get_current_model(self):
|
|
117
|
+
return self._current_model
|
|
118
|
+
|
|
119
|
+
@property
|
|
120
|
+
def chat(self):
|
|
121
|
+
"""OpenAI-compatible chat interface."""
|
|
122
|
+
return self._current_model.chat
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
def completions(self):
|
|
126
|
+
"""OpenAI-compatible completions interface."""
|
|
127
|
+
return self._current_model.completions
|
|
128
|
+
|
|
129
|
+
def advance_to_next_step(self, step: int):
|
|
130
|
+
"""
|
|
131
|
+
Advance to the next training step and update the current model snapshot.
|
|
132
|
+
|
|
133
|
+
Args:
|
|
134
|
+
step: The current training step number
|
|
135
|
+
"""
|
|
136
|
+
try:
|
|
137
|
+
self.current_step = step
|
|
138
|
+
|
|
139
|
+
if step == 0:
|
|
140
|
+
self._current_model = self._base_model
|
|
141
|
+
else:
|
|
142
|
+
model_name = f"accounts/{self.config.user_id}/models/{self.config.model_id}-v{step}"
|
|
143
|
+
with _model_spinner_progress(
|
|
144
|
+
f"Creating and deploying model snapshot: {model_name}"
|
|
145
|
+
) as update_progress:
|
|
146
|
+
update_progress("Creating model snapshot instance...")
|
|
147
|
+
self._current_model = LLM(
|
|
148
|
+
model=model_name,
|
|
149
|
+
deployment_type="on-demand-lora",
|
|
150
|
+
base_id=self.config.deployment_id,
|
|
151
|
+
)
|
|
152
|
+
update_progress("Applying deployment configuration...")
|
|
153
|
+
self._current_model.apply()
|
|
154
|
+
_print_model_progress("Model snapshot deployment ready")
|
|
155
|
+
|
|
156
|
+
if self._tracer_wrapper_func:
|
|
157
|
+
self._tracer_wrapper_func(self._current_model)
|
|
158
|
+
except Exception as e:
|
|
159
|
+
raise JudgmentRuntimeError(
|
|
160
|
+
f"Failed to advance to training step {step}: {str(e)}"
|
|
161
|
+
) from e
|
|
162
|
+
|
|
163
|
+
def perform_reinforcement_step(
|
|
164
|
+
self, dataset, step: int, max_retries: int = 3, initial_backoff: float = 1.0
|
|
165
|
+
):
|
|
166
|
+
"""
|
|
167
|
+
Perform a reinforcement learning step using the current model.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
dataset: Training dataset for the reinforcement step
|
|
171
|
+
step: Current step number for output model naming
|
|
172
|
+
max_retries: Maximum number of retry attempts (default: 3)
|
|
173
|
+
initial_backoff: Initial backoff time in seconds for exponential backoff (default: 1.0)
|
|
174
|
+
|
|
175
|
+
Returns:
|
|
176
|
+
Training job object
|
|
177
|
+
"""
|
|
178
|
+
model_name = f"{self.config.model_id}-v{step + 1}"
|
|
179
|
+
|
|
180
|
+
for attempt in range(max_retries):
|
|
181
|
+
try:
|
|
182
|
+
return self._current_model.reinforcement_step(
|
|
183
|
+
dataset=dataset,
|
|
184
|
+
output_model=model_name,
|
|
185
|
+
epochs=self.config.epochs,
|
|
186
|
+
learning_rate=self.config.learning_rate,
|
|
187
|
+
)
|
|
188
|
+
except Exception as e:
|
|
189
|
+
if attempt < max_retries - 1:
|
|
190
|
+
backoff_time = initial_backoff * (2**attempt)
|
|
191
|
+
time.sleep(backoff_time)
|
|
192
|
+
else:
|
|
193
|
+
raise JudgmentRuntimeError(
|
|
194
|
+
f"Failed to start reinforcement learning step {step + 1} after {max_retries} attempts: {str(e)}"
|
|
195
|
+
) from e
|
|
196
|
+
|
|
197
|
+
def get_model_config(
|
|
198
|
+
self, training_params: Optional[Dict[str, Any]] = None
|
|
199
|
+
) -> ModelConfig:
|
|
200
|
+
"""
|
|
201
|
+
Get the current model configuration for persistence.
|
|
202
|
+
|
|
203
|
+
Args:
|
|
204
|
+
training_params: Optional training parameters to include in config
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
ModelConfig instance with current model state
|
|
208
|
+
"""
|
|
209
|
+
current_model_name = None
|
|
210
|
+
is_trained = False
|
|
211
|
+
|
|
212
|
+
if self.current_step > 0:
|
|
213
|
+
current_model_name = f"accounts/{self.config.user_id}/models/{self.config.model_id}-v{self.current_step}"
|
|
214
|
+
is_trained = True
|
|
215
|
+
|
|
216
|
+
return ModelConfig(
|
|
217
|
+
base_model_name=self.config.base_model_name,
|
|
218
|
+
deployment_id=self.config.deployment_id,
|
|
219
|
+
user_id=self.config.user_id,
|
|
220
|
+
model_id=self.config.model_id,
|
|
221
|
+
enable_addons=self.config.enable_addons,
|
|
222
|
+
current_step=self.current_step,
|
|
223
|
+
total_steps=self.config.num_steps,
|
|
224
|
+
current_model_name=current_model_name,
|
|
225
|
+
is_trained=is_trained,
|
|
226
|
+
training_params=training_params,
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
def save_model_config(
|
|
230
|
+
self, filepath: str, training_params: Optional[Dict[str, Any]] = None
|
|
231
|
+
):
|
|
232
|
+
"""
|
|
233
|
+
Save the current model configuration to a file.
|
|
234
|
+
|
|
235
|
+
Args:
|
|
236
|
+
filepath: Path to save the configuration file
|
|
237
|
+
training_params: Optional training parameters to include in config
|
|
238
|
+
"""
|
|
239
|
+
model_config = self.get_model_config(training_params)
|
|
240
|
+
model_config.save_to_file(filepath)
|
|
241
|
+
|
|
242
|
+
def _register_tracer_wrapper(self, wrapper_func: Callable):
|
|
243
|
+
"""
|
|
244
|
+
Register a tracer wrapper function to be reapplied when models change.
|
|
245
|
+
|
|
246
|
+
This is called internally by the tracer's wrap() function to ensure
|
|
247
|
+
that new model instances created during training are automatically wrapped.
|
|
248
|
+
|
|
249
|
+
Args:
|
|
250
|
+
wrapper_func: Function that wraps a model instance with tracing
|
|
251
|
+
"""
|
|
252
|
+
self._tracer_wrapper_func = wrapper_func
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from judgeval.v1.internal.api import JudgmentSyncClient
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from judgeval.v1.trainers.config import TrainerConfig
|
|
9
|
+
from judgeval.v1.trainers.trainable_model import TrainableModel
|
|
10
|
+
from judgeval.v1.tracer.tracer import Tracer
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TrainersFactory:
|
|
14
|
+
__slots__ = "_client"
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
client: JudgmentSyncClient,
|
|
19
|
+
):
|
|
20
|
+
self._client = client
|
|
21
|
+
|
|
22
|
+
def fireworks(
|
|
23
|
+
self,
|
|
24
|
+
config: TrainerConfig,
|
|
25
|
+
trainable_model: TrainableModel,
|
|
26
|
+
tracer: Tracer,
|
|
27
|
+
project_name: str | None = None,
|
|
28
|
+
):
|
|
29
|
+
from judgeval.v1.trainers.fireworks_trainer import FireworksTrainer
|
|
30
|
+
|
|
31
|
+
return FireworksTrainer(
|
|
32
|
+
config=config,
|
|
33
|
+
trainable_model=trainable_model,
|
|
34
|
+
tracer=tracer,
|
|
35
|
+
project_name=project_name,
|
|
36
|
+
client=self._client,
|
|
37
|
+
)
|
judgeval/v1/utils.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from functools import lru_cache
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
from judgeval.logger import judgeval_logger
|
|
7
|
+
from judgeval.v1.internal.api import JudgmentSyncClient
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@lru_cache(maxsize=128)
|
|
11
|
+
def resolve_project_id(client: JudgmentSyncClient, project_name: str) -> Optional[str]:
|
|
12
|
+
try:
|
|
13
|
+
response = client.projects_resolve({"project_name": project_name})
|
|
14
|
+
project_id = response.get("project_id")
|
|
15
|
+
return str(project_id) if project_id else None
|
|
16
|
+
except Exception as e:
|
|
17
|
+
judgeval_logger.error(f"Failed to resolve project '{project_name}': {str(e)}")
|
|
18
|
+
return None
|
judgeval/version.py
ADDED
judgeval/warnings.py
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: judgeval
|
|
3
|
+
Version: 0.23.0
|
|
4
|
+
Summary: The open source post-building layer for Agent Behavior Monitoring.
|
|
5
|
+
Project-URL: Homepage, https://github.com/JudgmentLabs/judgeval
|
|
6
|
+
Project-URL: Issues, https://github.com/JudgmentLabs/judgeval/issues
|
|
7
|
+
Author-email: Andrew Li <andrew@judgmentlabs.ai>, Alex Shan <alex@judgmentlabs.ai>, Joseph Camyre <joseph@judgmentlabs.ai>
|
|
8
|
+
Maintainer-email: Judgment Labs <contact@judgmentlabs.ai>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE.md
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Requires-Dist: boto3>=1.40.11
|
|
15
|
+
Requires-Dist: click<8.2.0
|
|
16
|
+
Requires-Dist: dotenv>=0.9.9
|
|
17
|
+
Requires-Dist: httpx>=0.28.1
|
|
18
|
+
Requires-Dist: litellm>=1.75.0
|
|
19
|
+
Requires-Dist: opentelemetry-exporter-otlp>=1.36.0
|
|
20
|
+
Requires-Dist: opentelemetry-sdk>=1.36.0
|
|
21
|
+
Requires-Dist: orjson>=3.9.0
|
|
22
|
+
Requires-Dist: typer>=0.9.0
|
|
23
|
+
Provides-Extra: s3
|
|
24
|
+
Requires-Dist: boto3>=1.40.11; extra == 's3'
|
|
25
|
+
Provides-Extra: trainer
|
|
26
|
+
Requires-Dist: fireworks-ai>=0.19.18; extra == 'trainer'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
<div align="center">
|
|
30
|
+
|
|
31
|
+
<a href="https://judgmentlabs.ai/">
|
|
32
|
+
<picture>
|
|
33
|
+
<source media="(prefers-color-scheme: dark)" srcset="assets/logo_darkmode.svg">
|
|
34
|
+
<img src="assets/logo_lightmode.svg" alt="Judgment Logo" width="400" />
|
|
35
|
+
</picture>
|
|
36
|
+
</a>
|
|
37
|
+
|
|
38
|
+
<br>
|
|
39
|
+
|
|
40
|
+
## Agent Behavior Monitoring (ABM)
|
|
41
|
+
|
|
42
|
+
Track and judge any agent behavior in online and offline setups. Set up Sentry-style alerts and analyze agent behaviors / topic patterns at scale!
|
|
43
|
+
|
|
44
|
+
[](https://docs.judgmentlabs.ai/documentation)
|
|
45
|
+
[](https://app.judgmentlabs.ai/register)
|
|
46
|
+
[](https://docs.judgmentlabs.ai/documentation/self-hosting/get-started)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
[](https://x.com/JudgmentLabs)
|
|
50
|
+
[](https://www.linkedin.com/company/judgmentlabs)
|
|
51
|
+
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
</table>
|
|
56
|
+
|
|
57
|
+
## [NEW] 🎆 Agent Reinforcement Learning
|
|
58
|
+
|
|
59
|
+
Train your agents with multi-turn reinforcement learning using judgeval and [Fireworks AI](https://fireworks.ai/)! Judgeval's ABM now integrates with Fireworks' Reinforcement Fine-Tuning (RFT) endpoint, supporting gpt-oss, qwen3, Kimi2, DeepSeek, and more.
|
|
60
|
+
|
|
61
|
+
Judgeval's agent monitoring infra provides a simple harness for integrating GRPO into any Python agent, giving builders a quick method to **try RL with minimal code changes** to their existing agents!
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
await trainer.train(
|
|
65
|
+
agent_function=your_agent_function, # entry point to your agent
|
|
66
|
+
scorers=[RewardScorer()], # Custom scorer you define based on task criteria, acts as reward
|
|
67
|
+
prompts=training_prompts # Tasks
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**That's it!** Judgeval automatically manages trajectory collection and reward tagging - your agent can learn from production data with minimal code changes.
|
|
72
|
+
|
|
73
|
+
👉 Check out the [Wikipedia Racer notebook](https://colab.research.google.com/github/JudgmentLabs/judgment-cookbook/blob/main/rl/WikiRacingAgent_RL.ipynb), where an agent learns to navigate Wikipedia using RL, to see Judgeval in action.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
You can view and monitor training progress for free via the [Judgment Dashboard](https://app.judgmentlabs.ai/).
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
## Judgeval Overview
|
|
80
|
+
|
|
81
|
+
Judgeval is an open-source framework for agent behavior monitoring. Judgeval offers a toolkit to track and judge agent behavior in online and offline setups, enabling you to convert interaction data from production/test environments into improved agents. To get started, try running one of the notebooks below or dive deeper in our [docs](https://docs.judgmentlabs.ai/documentation).
|
|
82
|
+
|
|
83
|
+
Our mission is to unlock the power of production data for agent development, enabling teams to improve their apps by catching real-time failures and optimizing over their users' preferences.
|
|
84
|
+
|
|
85
|
+
## 📚 Cookbooks
|
|
86
|
+
|
|
87
|
+
| Try Out | Notebook | Description |
|
|
88
|
+
|:---------|:-----|:------------|
|
|
89
|
+
| RL | [Wikipedia Racer](https://colab.research.google.com/github/JudgmentLabs/judgment-cookbook/blob/main/rl/WikiRacingAgent_RL.ipynb) | Train agents with reinforcement learning |
|
|
90
|
+
| Online ABM | [Research Agent](https://colab.research.google.com/github/JudgmentLabs/judgment-cookbook/blob/main/monitoring/Research_Agent_Online_Monitoring.ipynb) | Monitor agent behavior in production |
|
|
91
|
+
| Custom Scorers | [HumanEval](https://colab.research.google.com/github/JudgmentLabs/judgment-cookbook/blob/main/custom_scorers/HumanEval_Custom_Scorer.ipynb) | Build custom evaluators for your agents |
|
|
92
|
+
| Offline Testing | [Get Started For Free] | Compare how different prompts, models, or agent configs affect performance across ANY metric |
|
|
93
|
+
|
|
94
|
+
You can access our [repo of cookbooks](https://github.com/JudgmentLabs/judgment-cookbook).
|
|
95
|
+
|
|
96
|
+
You can find a list of [video tutorials for Judgeval use cases](https://www.youtube.com/@Alexshander-JL).
|
|
97
|
+
|
|
98
|
+
## Why Judgeval?
|
|
99
|
+
|
|
100
|
+
🤖 **Simple to run multi-turn RL**: Optimize your agents with multi-turn RL without managing compute infrastructure or data pipelines. Just add a few lines of code to your existing agent code and train!
|
|
101
|
+
|
|
102
|
+
⚙️ **Custom Evaluators**: No restriction to only monitoring with prefab scorers. Judgeval provides simple abstractions for custom Python scorers, supporting any LLM-as-a-judge rubrics/models and code-based scorers that integrate to our live agent-tracking infrastructure. [Learn more](https://docs.judgmentlabs.ai/documentation/evaluation/custom-scorers)
|
|
103
|
+
|
|
104
|
+
🚨 **Production Monitoring**: Run any custom scorer in a hosted, virtualized secure container to flag agent behaviors online in production. Get Slack alerts for failures and add custom hooks to address regressions before they impact users. [Learn more](https://docs.judgmentlabs.ai/documentation/performance/online-evals)
|
|
105
|
+
|
|
106
|
+
📊 **Behavior/Topic Grouping**: Group agent runs by behavior type or topic for deeper analysis. Drill down into subsets of users, agents, or use cases to reveal patterns of agent behavior.
|
|
107
|
+
<!-- Add link to Bucketing docs once we have it -->
|
|
108
|
+
<!--
|
|
109
|
+
TODO: Once we have trainer code docs, plug in here
|
|
110
|
+
-->
|
|
111
|
+
|
|
112
|
+
🧪 **Run experiments on your agents**: Compare test different prompts, models, or agent configs across customer segments. Measure which changes improve agent performance and decrease bad agent behaviors.
|
|
113
|
+
|
|
114
|
+
<!--
|
|
115
|
+
Use this once we have AI PM features:
|
|
116
|
+
|
|
117
|
+
**Run experiments on your agents**: A/B test different prompts, models, or agent configs across customer segments. Measure which changes improve agent performance and decrease bad agent behaviors. [Learn more]
|
|
118
|
+
|
|
119
|
+
-->
|
|
120
|
+
|
|
121
|
+
## 🛠️ Quickstart
|
|
122
|
+
|
|
123
|
+
Get started with Judgeval by installing our SDK using pip:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
pip install judgeval
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Ensure you have your `JUDGMENT_API_KEY` and `JUDGMENT_ORG_ID` environment variables set to connect to the [Judgment Platform](https://app.judgmentlabs.ai/).
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
export JUDGMENT_API_KEY=...
|
|
133
|
+
export JUDGMENT_ORG_ID=...
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**If you don't have keys, [create an account for free](https://app.judgmentlabs.ai/register) on the platform!**
|
|
137
|
+
|
|
138
|
+
### Start monitoring with Judgeval
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from judgeval.tracer import Tracer, wrap
|
|
142
|
+
from judgeval.data import Example
|
|
143
|
+
from judgeval.scorers import AnswerRelevancyScorer
|
|
144
|
+
from openai import OpenAI
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
judgment = Tracer(project_name="default_project")
|
|
148
|
+
client = wrap(OpenAI()) # tracks all LLM calls
|
|
149
|
+
|
|
150
|
+
@judgment.observe(span_type="tool")
|
|
151
|
+
def format_question(question: str) -> str:
|
|
152
|
+
# dummy tool
|
|
153
|
+
return f"Question : {question}"
|
|
154
|
+
|
|
155
|
+
@judgment.observe(span_type="function")
|
|
156
|
+
def run_agent(prompt: str) -> str:
|
|
157
|
+
task = format_question(prompt)
|
|
158
|
+
response = client.chat.completions.create(
|
|
159
|
+
model="gpt-5-mini",
|
|
160
|
+
messages=[{"role": "user", "content": task}]
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
judgment.async_evaluate( # trigger online monitoring
|
|
164
|
+
scorer=AnswerRelevancyScorer(threshold=0.5), # swap with any scorer
|
|
165
|
+
example=Example(input=task, actual_output=response), # customize to your data
|
|
166
|
+
model="gpt-5",
|
|
167
|
+
)
|
|
168
|
+
return response.choices[0].message.content
|
|
169
|
+
|
|
170
|
+
run_agent("What is the capital of the United States?")
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Running this code will deliver monitoring results to your [free platform account](https://app.judgmentlabs.ai/register) and should look like this:
|
|
174
|
+
|
|
175
|
+

|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
### Customizable Scorers Over Agent Behavior
|
|
179
|
+
|
|
180
|
+
Judgeval's strongest suit is the full customization over the types of scorers you can run online monitoring with. No restrictions to only single-prompt LLM judges or prefab scorers - if you can express your scorer
|
|
181
|
+
in python code, judgeval can monitor it! Under the hood, judgeval hosts your scorer in a virtualized secure container, enabling online monitoring for any scorer.
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
First, create a behavior scorer in a file called `helpfulness_scorer.py`:
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from judgeval.data import Example
|
|
188
|
+
from judgeval.scorers.example_scorer import ExampleScorer
|
|
189
|
+
|
|
190
|
+
# Define custom example class
|
|
191
|
+
class QuestionAnswer(Example):
|
|
192
|
+
question: str
|
|
193
|
+
answer: str
|
|
194
|
+
|
|
195
|
+
# Define a server-hosted custom scorer
|
|
196
|
+
class HelpfulnessScorer(ExampleScorer):
|
|
197
|
+
name: str = "Helpfulness Scorer"
|
|
198
|
+
server_hosted: bool = True # Enable server hosting
|
|
199
|
+
async def a_score_example(self, example: QuestionAnswer):
|
|
200
|
+
# Custom scoring logic for agent behavior
|
|
201
|
+
# Can be an arbitrary combination of code and LLM calls
|
|
202
|
+
if len(example.answer) > 10 and "?" not in example.answer:
|
|
203
|
+
self.reason = "Answer is detailed and provides helpful information"
|
|
204
|
+
return 1.0
|
|
205
|
+
else:
|
|
206
|
+
self.reason = "Answer is too brief or unclear"
|
|
207
|
+
return 0.0
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Then deploy your scorer to Judgment's infrastructure:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
echo "pydantic" > requirements.txt
|
|
214
|
+
uv run judgeval upload_scorer helpfulness_scorer.py requirements.txt
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Now you can instrument your agent with monitoring and online evaluation:
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
from judgeval.tracer import Tracer, wrap
|
|
221
|
+
from helpfulness_scorer import HelpfulnessScorer, QuestionAnswer
|
|
222
|
+
from openai import OpenAI
|
|
223
|
+
|
|
224
|
+
judgment = Tracer(project_name="default_project")
|
|
225
|
+
client = wrap(OpenAI()) # tracks all LLM calls
|
|
226
|
+
|
|
227
|
+
@judgment.observe(span_type="tool")
|
|
228
|
+
def format_task(question: str) -> str: # replace with your prompt engineering
|
|
229
|
+
return f"Please answer the following question: {question}"
|
|
230
|
+
|
|
231
|
+
@judgment.observe(span_type="tool")
|
|
232
|
+
def answer_question(prompt: str) -> str: # replace with your LLM system calls
|
|
233
|
+
response = client.chat.completions.create(
|
|
234
|
+
model="gpt-5-mini",
|
|
235
|
+
messages=[{"role": "user", "content": prompt}]
|
|
236
|
+
)
|
|
237
|
+
return response.choices[0].message.content
|
|
238
|
+
|
|
239
|
+
@judgment.observe(span_type="function")
|
|
240
|
+
def run_agent(question: str) -> str:
|
|
241
|
+
task = format_task(question)
|
|
242
|
+
answer = answer_question(task)
|
|
243
|
+
|
|
244
|
+
# Add online evaluation with server-hosted scorer
|
|
245
|
+
judgment.async_evaluate(
|
|
246
|
+
scorer=HelpfulnessScorer(),
|
|
247
|
+
example=QuestionAnswer(question=question, answer=answer),
|
|
248
|
+
sampling_rate=0.9 # Evaluate 90% of agent runs
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
return answer
|
|
252
|
+
|
|
253
|
+
if __name__ == "__main__":
|
|
254
|
+
result = run_agent("What is the capital of the United States?")
|
|
255
|
+
print(result)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Congratulations! Your online eval result should look like this:
|
|
259
|
+
|
|
260
|
+

|
|
261
|
+
|
|
262
|
+
You can now run any online scorer in a secure Firecracker microVMs with no latency impact on your applications.
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
Judgeval is created and maintained by [Judgment Labs](https://judgmentlabs.ai/).
|