Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
afcbc52
Updated the DatabricksRM class to use Databricks service principals.
willsmithDB May 27, 2025
784354a
Updated comments for the usage of service principals for the Databric…
willsmithDB May 29, 2025
f06c2ed
Updated print statements to acknowledge auth method.
willsmithDB May 29, 2025
6c3512d
Merge branch 'stanfordnlp:main' into dbx_service_principal_functionality
willsmithDB May 29, 2025
4b00022
Updated print statements to acknowledge auth method.
willsmithDB May 29, 2025
f9b2b9d
Merge remote-tracking branch 'origin/dbx_service_principal_functional…
willsmithDB May 29, 2025
b47fe02
format
chenmoneygithub May 29, 2025
9cf562a
Updated for Oauth support via REST API
willsmithDB Jun 3, 2025
b3a57fa
Merge remote-tracking branch 'origin/dbx_service_principal_functional…
willsmithDB Jun 3, 2025
34fa87c
Updated for Oauth support via REST API
willsmithDB Jun 3, 2025
8fa2465
fix inspect_history function calling issue (#8316)
iPersona Jun 3, 2025
04635ed
fix lint errors and lock deps (#8312)
TomeHirata Jun 3, 2025
20b9242
Revert hotpotqa back to original (from #8234) as it's now alive (#8317)
okhat Jun 3, 2025
13c1e0d
Update versions
okhat Jun 3, 2025
9f24553
Merge branch 'release-2.6.26'
actions-user Jun 3, 2025
aedce91
Updated for Oauth support via REST API
willsmithDB Jun 3, 2025
cc78b46
fix BaseType annotation check (#8318)
okhat Jun 3, 2025
124f444
Update versions
okhat Jun 3, 2025
34e839a
Merge branch 'release-2.6.27a1'
actions-user Jun 3, 2025
1c4b031
Update versions
okhat Jun 3, 2025
37a4626
Merge branch 'release-2.6.27'
actions-user Jun 3, 2025
594fb04
Updated for Oauth support via REST API
willsmithDB Jun 3, 2025
ff8a2e1
Merge remote-tracking branch 'origin/dbx_service_principal_functional…
willsmithDB Jun 3, 2025
554f368
Merge branch 'stanfordnlp:main' into dbx_service_principal_functionality
willsmithDB Jun 3, 2025
0e55841
Updated for Databricks Oauth support via REST API
willsmithDB Jun 3, 2025
49c299f
Merge remote-tracking branch 'origin/dbx_service_principal_functional…
willsmithDB Jun 3, 2025
63020fd
Fix Pydantic v2 deprecation warning in json_adapter (#8263)
brishin Jun 3, 2025
60d6f94
Enable CI testing for all supported python versions (#8321)
chenmoneygithub Jun 3, 2025
4f154a7
Fix the custom type extraction in dspy.BaseType (#8320)
chenmoneygithub Jun 3, 2025
19d846a
Add global max_errors setting (#8319)
okhat Jun 3, 2025
eed2f8c
Wrap langchain tool code example by asyncio runner (#8322)
chenmoneygithub Jun 3, 2025
5bc4a15
add more permission capabilities to PythonInterpreter (#8296)
arnavsinghvi11 Jun 4, 2025
7faec6e
Merge branch 'stanfordnlp:main' into dbx_service_principal_functionality
willsmithDB Jun 4, 2025
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
4 changes: 2 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ your_dspy_program_compiled = labeled_fewshot_optimizer.compile(student = your_ds
```python
from dspy.teleprompt import BootstrapFewShot

fewshot_optimizer = BootstrapFewShot(metric=your_defined_metric, max_bootstrapped_demos=4, max_labeled_demos=16, max_rounds=1, max_errors=5)
fewshot_optimizer = BootstrapFewShot(metric=your_defined_metric, max_bootstrapped_demos=4, max_labeled_demos=16, max_rounds=1, max_errors=10)

your_dspy_program_compiled = fewshot_optimizer.compile(student = your_dspy_program, trainset=trainset)
```
Expand All @@ -281,7 +281,7 @@ your_dspy_program_compiled = fewshot_optimizer.compile(student = your_dspy_progr
```python
from dspy.teleprompt import BootstrapFewShot

fewshot_optimizer = BootstrapFewShot(metric=your_defined_metric, max_bootstrapped_demos=4, max_labeled_demos=16, max_rounds=1, max_errors=5, teacher_settings=dict(lm=gpt4))
fewshot_optimizer = BootstrapFewShot(metric=your_defined_metric, max_bootstrapped_demos=4, max_labeled_demos=16, max_rounds=1, max_errors=10, teacher_settings=dict(lm=gpt4))

your_dspy_program_compiled = fewshot_optimizer.compile(student = your_dspy_program, trainset=trainset)
```
Expand Down
2 changes: 1 addition & 1 deletion dspy/.internal_dspyai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#replace_package_name_marker
name="dspy-ai"
#replace_package_version_marker
version="2.6.25"
version="2.6.27"
description = "DSPy"
readme = "README.md"
authors = [
Expand Down
2 changes: 1 addition & 1 deletion dspy/__metadata__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#replace_package_name_marker
__name__="dspy"
#replace_package_version_marker
__version__="2.6.25"
__version__="2.6.27"
__description__="DSPy"
__url__="https://github.com/stanfordnlp/dspy"
__author__="Omar Khattab"
Expand Down
2 changes: 1 addition & 1 deletion dspy/adapters/json_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ def _get_structured_outputs_response_format(signature: SignatureMeta) -> type[py
# Build the model with extra fields forbidden.
pydantic_model = pydantic.create_model(
"DSPyProgramOutputs",
__config__=pydantic.ConfigDict(extra="forbid"),
**fields,
__config__=type("Config", (), {"extra": "forbid"}),
)

# Generate the initial schema.
Expand Down
10 changes: 7 additions & 3 deletions dspy/adapters/types/base_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ def extract_custom_type_from_annotation(cls, annotation):
This is used to extract all custom types from the annotation of a field, while the annotation can
have arbitrary level of nesting. For example, we detect `Tool` is in `list[dict[str, Tool]]`.
"""
# Direct match
if isinstance(annotation, type) and issubclass(annotation, cls):
return [annotation]
# Direct match. Nested type like `list[dict[str, Event]]` passes `isinstance(annotation, type)` in python 3.10
# while fails in python 3.11. To accomodate users using python 3.10, we need to capture the error and ignore it.
try:
if isinstance(annotation, type) and issubclass(annotation, cls):
return [annotation]
except TypeError:
pass

origin = get_origin(annotation)
if origin is None:
Expand Down
14 changes: 10 additions & 4 deletions dspy/adapters/types/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,23 @@ def from_langchain(cls, tool: "BaseTool") -> "Tool":
A Tool object.

Example:

```python
from langchain.tools import tool
import asyncio
import dspy
from langchain.tools import tool as lc_tool

@tool
@lc_tool
def add(x: int, y: int):
"Add two numbers together."
return x + y

tool = dspy.Tool.from_langchain(add)
print(await tool.acall(x=1, y=2))
dspy_tool = dspy.Tool.from_langchain(add)

async def run_tool():
return await dspy_tool.acall(x=1, y=2)

print(asyncio.run(run_tool()))
# 3
```
"""
Expand Down
2 changes: 1 addition & 1 deletion dspy/clients/base_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def copy(self, **kwargs):
return new_instance

def inspect_history(self, n: int = 1):
return inspect_history(self.history, n)
return pretty_print_history(self.history, n)

def update_global_history(self, entry):
if settings.disable_history:
Expand Down
4 changes: 2 additions & 2 deletions dspy/datasets/hotpotqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def __init__(

from datasets import load_dataset

hf_official_train = load_dataset("vincentkoc/hotpot_qa_archive", "fullwiki", split="train", trust_remote_code=True)
hf_official_dev = load_dataset("vincentkoc/hotpot_qa_archive", "fullwiki", split="validation", trust_remote_code=True)
hf_official_train = load_dataset("hotpot_qa", "fullwiki", split="train", trust_remote_code=True)
hf_official_dev = load_dataset("hotpot_qa", "fullwiki", split="validation", trust_remote_code=True)

official_train = []
for raw_example in hf_official_train:
Expand Down
2 changes: 1 addition & 1 deletion dspy/dsp/colbertv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def forward(self, query: str, k: int = 7, **kwargs):

if kwargs.get("filtered_pids"):
filtered_pids = kwargs.get("filtered_pids")
assert type(filtered_pids) == List[int], "The filtered pids should be a list of integers"
assert isinstance(filtered_pids, list) and all(isinstance(pid, int) for pid in filtered_pids), "The filtered pids should be a list of integers"
device = "cuda" if torch.cuda.is_available() else "cpu"
results = self.searcher.search(
query,
Expand Down
1 change: 1 addition & 0 deletions dspy/dsp/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
stream_listeners=[],
provide_traceback=False, # Whether to include traceback information in error logs.
num_threads=8, # Number of threads to use for parallel processing.
max_errors=10, # Maximum errors before halting operations.
)

# Global base configuration and owner tracking
Expand Down
11 changes: 8 additions & 3 deletions dspy/evaluate/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(
num_threads: Optional[int] = None,
display_progress: bool = False,
display_table: Union[bool, int] = False,
max_errors: int = 5,
max_errors: Optional[int] = None,
return_all_scores: bool = False,
return_outputs: bool = False,
provide_traceback: Optional[bool] = None,
Expand All @@ -71,7 +71,8 @@ def __init__(
display_progress (bool): Whether to display progress during evaluation.
display_table (Union[bool, int]): Whether to display the evaluation results in a table.
If a number is passed, the evaluation results will be truncated to that number before displayed.
max_errors (int): The maximum number of errors to allow before stopping evaluation.
max_errors (Optional[int]): The maximum number of errors to allow before
stopping evaluation. If ``None``, inherits from ``dspy.settings.max_errors``.
return_all_scores (bool): Whether to return scores for every data record in `devset`.
return_outputs (bool): Whether to return the dspy program's outputs for every data in `devset`.
provide_traceback (Optional[bool]): Whether to provide traceback information during evaluation.
Expand Down Expand Up @@ -151,7 +152,11 @@ def __call__(
executor = ParallelExecutor(
num_threads=num_threads,
disable_progress_bar=not display_progress,
max_errors=self.max_errors,
max_errors=(
self.max_errors
if self.max_errors is not None
else dspy.settings.max_errors
),
provide_traceback=self.provide_traceback,
compare_results=True,
)
Expand Down
10 changes: 5 additions & 5 deletions dspy/predict/code_act.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import inspect
from typing import Callable, Union, Type, Optional
import logging
from inspect import Signature
from typing import Callable, Type, Union

import dspy
from dspy.adapters.types.tool import Tool
Expand All @@ -17,15 +17,15 @@ class CodeAct(ReAct, ProgramOfThought):
CodeAct is a module that utilizes the Code Interpreter and predefined tools to solve the problem.
"""

def __init__(self, signature: Union[str, Type[Signature]], tools: list[Callable], max_iters: int = 5):
def __init__(self, signature: Union[str, Type[Signature]], tools: list[Callable], max_iters: int = 5, interpreter: Optional[PythonInterpreter] = None):
"""
Initializes the CodeAct class with the specified model, temperature, and max tokens.

Args:
signature (Union[str, Type[Signature]]): The signature of the module.
tools (list[Callable]): The tool callables to be used. CodeAct only accepts functions and not callable objects.
max_iters (int): The maximum number of iterations to generate the answer.

interpreter: PythonInterpreter instance to use. If None, a new one is instantiated.
Example:
```python
from dspy.predict import CodeAct
Expand Down Expand Up @@ -67,8 +67,8 @@ def factorial(n):
self.codeact = dspy.Predict(codeact_signature)
self.extractor = dspy.ChainOfThought(extract_signature)
# It will raises exception when dspy cannot find available deno instance by now.
self.interpreter = PythonInterpreter()

self.interpreter = interpreter or PythonInterpreter()
def _build_instructions(self, signature, tools):
instructions = [f"{signature.instructions}\n"] if signature.instructions else []
inputs = ", ".join([f"`{k}`" for k in signature.input_fields.keys()])
Expand Down
4 changes: 2 additions & 2 deletions dspy/predict/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ class Parallel:
def __init__(
self,
num_threads: Optional[int] = None,
max_errors: int = 10,
max_errors: Optional[int] = None,
access_examples: bool = True,
return_failed_examples: bool = False,
provide_traceback: Optional[bool] = None,
disable_progress_bar: bool = False,
):
super().__init__()
self.num_threads = num_threads or settings.num_threads
self.max_errors = max_errors
self.max_errors = settings.max_errors if max_errors is None else max_errors
self.access_examples = access_examples
self.return_failed_examples = return_failed_examples
self.provide_traceback = provide_traceback
Expand Down
7 changes: 4 additions & 3 deletions dspy/predict/program_of_thought.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import logging
import re
from typing import Type, Union
from typing import Type, Union, Optional

import dspy
from dspy.primitives.program import Module
Expand All @@ -27,11 +27,12 @@ class ProgramOfThought(Module):
```
"""

def __init__(self, signature: Union[str, Type[Signature]], max_iters=3):
def __init__(self, signature: Union[str, Type[Signature]], max_iters=3, interpreter: Optional[PythonInterpreter] = None):
"""
Args:
signature: The signature of the module.
max_iters: The maximum number of iterations to retry code generation and execution.
interpreter: PythonInterpreter instance to use. If None, a new one is instantiated.
"""
super().__init__()
self.signature = signature = ensure_signature(signature)
Expand Down Expand Up @@ -59,7 +60,7 @@ def __init__(self, signature: Union[str, Type[Signature]], max_iters=3):
),
)
# It will raises exception when dspy cannot find available deno instance by now.
self.interpreter = PythonInterpreter()
self.interpreter = interpreter or PythonInterpreter()

def _generate_signature(self, mode):
signature_dict = dict(self.input_fields)
Expand Down
5 changes: 3 additions & 2 deletions dspy/primitives/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def batch(
self,
examples,
num_threads: Optional[int] = None,
max_errors: int = 10,
max_errors: Optional[int] = None,
return_failed_examples: bool = False,
provide_traceback: Optional[bool] = None,
disable_progress_bar: bool = False,
Expand All @@ -127,10 +127,11 @@ def batch(
examples: List of dspy.Example instances to process.
num_threads: Number of threads to use for parallel processing.
max_errors: Maximum number of errors allowed before stopping execution.
If ``None``, inherits from ``dspy.settings.max_errors``.
return_failed_examples: Whether to return failed examples and exceptions.
provide_traceback: Whether to include traceback information in error logs.
disable_progress_bar: Whether to display the progress bar.

Returns:
List of results, and optionally failed examples and exceptions.
"""
Expand Down
Loading