Skip to content

Building AI agents, atomically

black formatting

KennyVaneetvelde052c4a33b88d
diff --git a/atomic-examples/dspy-integration/dspy_integration/bridge.py b/atomic-examples/dspy-integration/dspy_integration/bridge.py
index 0737a71..900dabe 100644
--- a/atomic-examples/dspy-integration/dspy_integration/bridge.py
+++ b/atomic-examples/dspy-integration/dspy_integration/bridge.py
@@ -58,9 +58,7 @@ def python_type_to_dspy_type(python_type: Any) -> Any:
return str # Default to string for complex types
-def pydantic_to_dspy_fields(
- schema: Type[BaseModel], field_type: str = "input"
-) -> Dict[str, tuple]:
+def pydantic_to_dspy_fields(schema: Type[BaseModel], field_type: str = "input") -> Dict[str, tuple]:
"""
Convert Pydantic schema fields to DSPy field definitions.
@@ -183,9 +181,7 @@ class DSPyAtomicModule(dspy.Module):
self.output_schema = output_schema
# Create DSPy signature from schemas
- self.signature = create_dspy_signature_from_schemas(
- input_schema, output_schema, instructions
- )
+ self.signature = create_dspy_signature_from_schemas(input_schema, output_schema, instructions)
# Create the predictor
if use_chain_of_thought:
diff --git a/atomic-examples/dspy-integration/dspy_integration/domain/datasets.py b/atomic-examples/dspy-integration/dspy_integration/domain/datasets.py
index 5cf9af4..10ad99f 100644
--- a/atomic-examples/dspy-integration/dspy_integration/domain/datasets.py
+++ b/atomic-examples/dspy-integration/dspy_integration/domain/datasets.py
@@ -292,12 +292,7 @@ _ROMANCE_EXAMPLES: List[MovieExample] = [
# Combine all training examples
TRAINING_DATASET: List[MovieExample] = (
- _ACTION_EXAMPLES
- + _COMEDY_EXAMPLES
- + _DRAMA_EXAMPLES
- + _HORROR_EXAMPLES
- + _SCIFI_EXAMPLES
- + _ROMANCE_EXAMPLES
+ _ACTION_EXAMPLES + _COMEDY_EXAMPLES + _DRAMA_EXAMPLES + _HORROR_EXAMPLES + _SCIFI_EXAMPLES + _ROMANCE_EXAMPLES
)
@@ -451,10 +446,5 @@ _CULTURAL_TESTS: List[MovieExample] = [
# Combine all test examples
TEST_DATASET: List[MovieExample] = (
- _SARCASM_TESTS
- + _MULTIGENRE_TESTS
- + _MISLEADING_TESTS
- + _SUBVERTED_TESTS
- + _SUBTLE_TESTS
- + _CULTURAL_TESTS
+ _SARCASM_TESTS + _MULTIGENRE_TESTS + _MISLEADING_TESTS + _SUBVERTED_TESTS + _SUBTLE_TESTS + _CULTURAL_TESTS
)
diff --git a/atomic-examples/dspy-integration/dspy_integration/main.py b/atomic-examples/dspy-integration/dspy_integration/main.py
index 83aae82..fccffdb 100644
--- a/atomic-examples/dspy-integration/dspy_integration/main.py
+++ b/atomic-examples/dspy-integration/dspy_integration/main.py
@@ -141,13 +141,8 @@ def main() -> None:
# Display configuration
console.print("\n[dim]Using model: gpt-4o-mini[/dim]")
- console.print(
- f"[dim]Training set: {len(TRAINING_DATASET)} examples (balanced across 6 genres)[/dim]"
- )
- console.print(
- f"[dim]Test set: {len(TEST_DATASET)} challenging examples "
- "(sarcasm, multi-genre, etc.)[/dim]\n"
- )
+ console.print(f"[dim]Training set: {len(TRAINING_DATASET)} examples (balanced across 6 genres)[/dim]")
+ console.print(f"[dim]Test set: {len(TEST_DATASET)} challenging examples " "(sarcasm, multi-genre, etc.)[/dim]\n")
# Run demonstration
try:
diff --git a/atomic-examples/dspy-integration/dspy_integration/presentation/console.py b/atomic-examples/dspy-integration/dspy_integration/presentation/console.py
index 05d80f5..0333f3c 100644
--- a/atomic-examples/dspy-integration/dspy_integration/presentation/console.py
+++ b/atomic-examples/dspy-integration/dspy_integration/presentation/console.py
@@ -128,8 +128,7 @@ def display_results_table(
show_confidence: Whether to show confidence column
"""
table = Table(
- title=f"{title}: {eval_result.accuracy:.1%} Accuracy "
- f"({eval_result.correct}/{eval_result.total})",
+ title=f"{title}: {eval_result.accuracy:.1%} Accuracy " f"({eval_result.correct}/{eval_result.total})",
box=box.ROUNDED,
)
diff --git a/atomic-examples/dspy-integration/dspy_integration/stages/stage1_dspy.py b/atomic-examples/dspy-integration/dspy_integration/stages/stage1_dspy.py
index 86c0736..f771816 100644
--- a/atomic-examples/dspy-integration/dspy_integration/stages/stage1_dspy.py
+++ b/atomic-examples/dspy-integration/dspy_integration/stages/stage1_dspy.py
@@ -55,9 +55,7 @@ class MovieGenreSignature(dspy.Signature):
"""
review: str = dspy.InputField(desc="The movie review text to classify")
- genre: GenreType = dspy.OutputField(
- desc="The primary genre: action, comedy, drama, horror, sci-fi, or romance"
- )
+ genre: GenreType = dspy.OutputField(desc="The primary genre: action, comedy, drama, horror, sci-fi, or romance")
confidence: float = dspy.OutputField(desc="Confidence score between 0.0 and 1.0")
reasoning: str = dspy.OutputField(desc="Brief explanation for the classification")
@@ -135,9 +133,7 @@ def run_stage1_raw_dspy(api_key: str) -> Tuple[EvalResult, Dict[str, Any]]:
# Step 8: Display results
_display_stage_results(eval_result, predictions)
- behind_scenes = _create_behind_scenes_data(
- unoptimized_prompt, optimized_prompt, optimized_classify
- )
+ behind_scenes = _create_behind_scenes_data(unoptimized_prompt, optimized_prompt, optimized_classify)
return eval_result, behind_scenes
@@ -236,9 +232,7 @@ def _capture_optimized_prompt(
prompt_str = json.dumps(optimized_prompt, indent=2)
truncated = prompt_str[:3500] + ("..." if len(prompt_str) > 3500 else "")
- content = (
- "[dim]Notice the auto-selected few-shot examples with reasoning:[/dim]\n\n" + truncated
- )
+ content = "[dim]Notice the auto-selected few-shot examples with reasoning:[/dim]\n\n" + truncated
display_panel(content, "Optimized DSPy Prompt (With Auto-Selected Examples)", "green")
return optimized_prompt
@@ -269,9 +263,7 @@ def _run_optimization(lm: dspy.LM, classify: dspy.Module) -> dspy.Module:
expected_genre = str(example.genre).lower().strip()
return pred_genre == expected_genre
- with create_progress_context(
- "[cyan]Running DSPy optimization (30 training examples)..."
- ) as progress:
+ with create_progress_context("[cyan]Running DSPy optimization (30 training examples)...") as progress:
task = progress.add_task("Optimizing...", total=None)
optimizer = dspy.BootstrapFewShot(
@@ -323,9 +315,7 @@ def _evaluate_model(
optimized_classify: dspy.Module,
) -> Tuple[EvalResult, List[Dict[str, Any]]]:
"""Evaluate the optimized model on test set."""
- display_step_header(
- f"Step 1.6: Evaluation on Test Set ({len(TEST_DATASET)} challenging examples)"
- )
+ display_step_header(f"Step 1.6: Evaluation on Test Set ({len(TEST_DATASET)} challenging examples)")
predictions = []
start_time = time.time()
@@ -410,8 +400,6 @@ def _create_behind_scenes_data(
return {
"unoptimized_prompt_sample": str(unoptimized_prompt)[:500],
"optimized_prompt_sample": str(optimized_prompt)[:500],
- "num_demos_selected": (
- len(optimized_classify.demos) if hasattr(optimized_classify, "demos") else "N/A"
- ),
+ "num_demos_selected": (len(optimized_classify.demos) if hasattr(optimized_classify, "demos") else "N/A"),
"training_examples": 30,
}
diff --git a/atomic-examples/dspy-integration/dspy_integration/stages/stage2_atomic.py b/atomic-examples/dspy-integration/dspy_integration/stages/stage2_atomic.py
index 969f3ed..ba6335e 100644
--- a/atomic-examples/dspy-integration/dspy_integration/stages/stage2_atomic.py
+++ b/atomic-examples/dspy-integration/dspy_integration/stages/stage2_atomic.py
@@ -304,8 +304,7 @@ def _display_stage_results(
# Show sample outputs
samples = "\n".join(
[
- f" • genre='{predictions[i]['genre']}' (Literal) "
- f"confidence={predictions[i]['confidence']:.2f} (float)"
+ f" • genre='{predictions[i]['genre']}' (Literal) " f"confidence={predictions[i]['confidence']:.2f} (float)"
for i in range(min(3, len(predictions)))
]
)
diff --git a/atomic-examples/dspy-integration/dspy_integration/stages/stage3_combined.py b/atomic-examples/dspy-integration/dspy_integration/stages/stage3_combined.py
index 71b847c..e25429a 100644
--- a/atomic-examples/dspy-integration/dspy_integration/stages/stage3_combined.py
+++ b/atomic-examples/dspy-integration/dspy_integration/stages/stage3_combined.py
@@ -230,9 +230,7 @@ def _run_optimization(
expected_genre = str(example.genre).lower().strip()
return pred_genre == expected_genre
- with create_progress_context(
- f"[green]Running optimization ({len(trainset)} training examples)..."
- ) as progress:
+ with create_progress_context(f"[green]Running optimization ({len(trainset)} training examples)...") as progress:
task = progress.add_task("Optimizing...", total=None)
optimizer = dspy.BootstrapFewShot(