repo
stringlengths
7
90
file_url
stringlengths
81
315
file_path
stringlengths
4
228
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 14:38:15
2026-01-05 02:33:18
truncated
bool
2 classes
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/retrievers/retrieve.py
dspy/retrievers/retrieve.py
import random from dspy.predict.parameter import Parameter from dspy.primitives.prediction import Prediction from dspy.utils.callback import with_callbacks def single_query_passage(passages): passages_dict = {key: [] for key in list(passages[0].keys())} for docs in passages: for key, value in docs.it...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/retrievers/__init__.py
dspy/retrievers/__init__.py
from dspy.retrievers.embeddings import Embeddings from dspy.retrievers.retrieve import Retrieve __all__ = ["Embeddings", "Retrieve"]
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/retrievers/embeddings.py
dspy/retrievers/embeddings.py
import json import os from typing import Any import numpy as np from dspy.utils.unbatchify import Unbatchify class Embeddings: def __init__( self, corpus: list[str], embedder, k: int = 5, callbacks: list[Any] | None = None, cache: bool = False, brute_force...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/retrievers/weaviate_rm.py
dspy/retrievers/weaviate_rm.py
import dspy from dspy.dsp.utils import dotdict from dspy.primitives.prediction import Prediction try: from uuid import uuid4 import weaviate from weaviate.util import get_valid_uuid except ImportError as err: raise ImportError( "The 'weaviate' extra is required to use WeaviateRM. Install it w...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/xml_adapter.py
dspy/adapters/xml_adapter.py
import re from typing import Any from pydantic.fields import FieldInfo from dspy.adapters.chat_adapter import ChatAdapter, FieldInfoWithName from dspy.adapters.utils import format_field_value, translate_field_type from dspy.signatures.signature import Signature from dspy.utils.callback import BaseCallback class XML...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/utils.py
dspy/adapters/utils.py
import ast import enum import inspect import json import types from collections.abc import Mapping from typing import Any, Literal, Union, get_args, get_origin import json_repair import pydantic from pydantic import TypeAdapter from pydantic.fields import FieldInfo from dspy.adapters.types.base_type import Type as Ds...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/__init__.py
dspy/adapters/__init__.py
from dspy.adapters.base import Adapter from dspy.adapters.chat_adapter import ChatAdapter from dspy.adapters.json_adapter import JSONAdapter from dspy.adapters.two_step_adapter import TwoStepAdapter from dspy.adapters.types import Audio, Code, File, History, Image, Reasoning, Tool, ToolCalls, Type from dspy.adapters.xm...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/base.py
dspy/adapters/base.py
import logging from typing import TYPE_CHECKING, Any, get_origin import json_repair import litellm from dspy.adapters.types import History, Type from dspy.adapters.types.base_type import split_message_content_for_custom_types from dspy.adapters.types.reasoning import Reasoning from dspy.adapters.types.tool import Too...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/chat_adapter.py
dspy/adapters/chat_adapter.py
import re import textwrap from typing import Any, NamedTuple from litellm import ContextWindowExceededError from pydantic.fields import FieldInfo from dspy.adapters.base import Adapter from dspy.adapters.utils import ( format_field_value, get_annotation_name, get_field_description_string, parse_value,...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/baml_adapter.py
dspy/adapters/baml_adapter.py
""" Custom adapter for improving structured outputs using the information from Pydantic models. Based on the format used by BAML: https://github.com/BoundaryML/baml """ import inspect import types from typing import Any, Literal, Union, get_args, get_origin from pydantic import BaseModel from dspy.adapters.json_adap...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/json_adapter.py
dspy/adapters/json_adapter.py
import json import logging from typing import Any, get_origin import json_repair import litellm import pydantic import regex from pydantic.fields import FieldInfo from dspy.adapters.chat_adapter import ChatAdapter, FieldInfoWithName from dspy.adapters.types.tool import ToolCalls from dspy.adapters.utils import ( ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/two_step_adapter.py
dspy/adapters/two_step_adapter.py
from typing import Any import json_repair from dspy.adapters.base import Adapter from dspy.adapters.chat_adapter import ChatAdapter from dspy.adapters.types import ToolCalls from dspy.adapters.utils import get_field_description_string from dspy.clients import LM from dspy.signatures.field import InputField from dspy....
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/types/image.py
dspy/adapters/types/image.py
import base64 import io import mimetypes import os import warnings from functools import lru_cache from typing import Any, Union from urllib.parse import urlparse import pydantic import requests from dspy.adapters.types.base_type import Type try: from PIL import Image as PILImage PIL_AVAILABLE = True except...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/types/citation.py
dspy/adapters/types/citation.py
from typing import Any, Optional import pydantic from dspy.adapters.types.base_type import Type from dspy.utils.annotation import experimental @experimental(version="3.0.4") class Citations(Type): """Citations extracted from an LM response with source references. This type represents citations returned by ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/types/file.py
dspy/adapters/types/file.py
import base64 import mimetypes import os from typing import Any import pydantic from dspy.adapters.types.base_type import Type class File(Type): """A file input type for DSPy. See https://platform.openai.com/docs/api-reference/chat/create#chat_create-messages-user_message-content-array_of_content_parts-file...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/types/history.py
dspy/adapters/types/history.py
from typing import Any import pydantic class History(pydantic.BaseModel): """Class representing the conversation history. The conversation history is a list of messages, each message entity should have keys from the associated signature. For example, if you have the following signature: ``` cla...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/types/audio.py
dspy/adapters/types/audio.py
import base64 import io import mimetypes import os from typing import Any, Union import pydantic import requests from dspy.adapters.types.base_type import Type try: import soundfile as sf SF_AVAILABLE = True except ImportError: SF_AVAILABLE = False def _normalize_audio_format(audio_format: str) -> str...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/types/document.py
dspy/adapters/types/document.py
from typing import Any, Literal import pydantic from dspy.adapters.types.base_type import Type from dspy.utils.annotation import experimental @experimental(version="3.0.4") class Document(Type): """A document type for providing content that can be cited by language models. This type represents documents th...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/types/code.py
dspy/adapters/types/code.py
import re from typing import Any, ClassVar import pydantic from pydantic import create_model from dspy.adapters.types.base_type import Type class Code(Type): """Code type in DSPy. This type is useful for code generation and code analysis. Example 1: dspy.Code as output type in code generation: ``...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/types/__init__.py
dspy/adapters/types/__init__.py
from dspy.adapters.types.audio import Audio from dspy.adapters.types.base_type import Type from dspy.adapters.types.code import Code from dspy.adapters.types.file import File from dspy.adapters.types.history import History from dspy.adapters.types.image import Image from dspy.adapters.types.reasoning import Reasoning f...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/types/tool.py
dspy/adapters/types/tool.py
import asyncio import inspect from typing import TYPE_CHECKING, Any, Callable, get_origin, get_type_hints import pydantic from jsonschema import ValidationError, validate from pydantic import BaseModel, TypeAdapter, create_model from dspy.adapters.types.base_type import Type from dspy.dsp.utils.settings import settin...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/types/base_type.py
dspy/adapters/types/base_type.py
import json import re from typing import TYPE_CHECKING, Any, Optional, get_args, get_origin import json_repair import pydantic from litellm import ModelResponseStream if TYPE_CHECKING: from dspy.clients.lm import LM from dspy.signatures.signature import Signature CUSTOM_TYPE_START_IDENTIFIER = "<<CUSTOM-TYPE...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/adapters/types/reasoning.py
dspy/adapters/types/reasoning.py
from typing import TYPE_CHECKING, Any, Optional import litellm import pydantic from dspy.adapters.types.base_type import Type if TYPE_CHECKING: from dspy.clients.lm import LM from dspy.signatures.signature import Signature class Reasoning(Type): """Reasoning type in DSPy. This type is useful when ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/propose/dataset_summary_generator.py
dspy/propose/dataset_summary_generator.py
import re import dspy from dspy.propose.utils import strip_prefix class ObservationSummarizer(dspy.Signature): ("""Given a series of observations I have made about my dataset, please summarize them into a brief 2-3 sentence summary which highlights only the most important details.""") observations = dspy.Inp...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/propose/utils.py
dspy/propose/utils.py
import inspect import json import re import dspy try: from IPython.core.magics.code import extract_symbols except ImportError: # Won't be able to read code from jupyter notebooks extract_symbols = None from dspy.predict.parameter import Parameter from dspy.teleprompt.utils import get_signature, new_getfi...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/propose/__init__.py
dspy/propose/__init__.py
from dspy.propose.grounded_proposer import GroundedProposer __all__ = [ "GroundedProposer", ]
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/propose/grounded_proposer.py
dspy/propose/grounded_proposer.py
import random import dspy from dspy.propose.dataset_summary_generator import create_dataset_summary from dspy.propose.propose_base import Proposer from dspy.propose.utils import ( create_example_string, create_predictor_level_history_string, get_dspy_source_code, strip_prefix, ) from dspy.teleprompt.ut...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/propose/propose_base.py
dspy/propose/propose_base.py
from abc import ABC, abstractmethod class Proposer(ABC): def __init__(self): pass @abstractmethod def propose_instructions_for_program(self): pass def propose_instruction_for_predictor(self): pass
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/experimental/__init__.py
dspy/experimental/__init__.py
from dspy.adapters.types.citation import Citations from dspy.adapters.types.document import Document __all__ = [ "Citations", "Document", ]
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/evaluate/metrics.py
dspy/evaluate/metrics.py
# TODO: This should move internally. Same for passage_match. dspy.metrics.answer_exact_match, dspy.metrics.answer_passage_match import re import string import unicodedata from collections import Counter from dspy.dsp.utils.utils import print_message def EM(prediction, answers_list): # noqa: N802 """Compute the...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/evaluate/auto_evaluation.py
dspy/evaluate/auto_evaluation.py
from dspy.predict.chain_of_thought import ChainOfThought from dspy.primitives import Module from dspy.signatures import InputField, OutputField, Signature class SemanticRecallPrecision(Signature): """ Compare a system's response to the ground truth to compute its recall and precision. If asked to reason, ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/evaluate/__init__.py
dspy/evaluate/__init__.py
from dspy.evaluate.auto_evaluation import CompleteAndGrounded, SemanticF1 from dspy.evaluate.evaluate import Evaluate, EvaluationResult from dspy.evaluate.metrics import EM, answer_exact_match, answer_passage_match, normalize_text __all__ = [ "EM", "normalize_text", "answer_exact_match", "answer_passag...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/evaluate/evaluate.py
dspy/evaluate/evaluate.py
import csv import importlib import json import logging import types from typing import TYPE_CHECKING, Any, Callable if TYPE_CHECKING: import pandas as pd import tqdm import dspy from dspy.primitives.prediction import Prediction from dspy.utils.callback import with_callbacks from dspy.utils.parallelizer import Pa...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/clients/lm_local.py
dspy/clients/lm_local.py
import datetime import logging import random import socket import string import subprocess import threading import time from typing import TYPE_CHECKING, Any import requests from dspy.clients.provider import Provider, TrainingJob from dspy.clients.utils_finetune import TrainDataFormat, save_data if TYPE_CHECKING: ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/clients/utils_finetune.py
dspy/clients/utils_finetune.py
import os from enum import Enum from typing import Any, Literal, TypedDict import orjson import dspy from dspy.adapters.base import Adapter from dspy.utils.caching import DSPY_CACHEDIR class TrainingStatus(str, Enum): not_started = "not_started" pending = "pending" running = "running" succeeded = "s...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/clients/lm.py
dspy/clients/lm.py
import logging import os import re import threading import warnings from typing import Any, Literal, cast import litellm import pydantic from anyio.streams.memory import MemoryObjectSendStream from asyncer import syncify import dspy from dspy.clients.cache import request_cache from dspy.clients.openai import OpenAIPr...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/clients/base_lm.py
dspy/clients/base_lm.py
import datetime import uuid from typing import Any from dspy.dsp.utils import settings from dspy.utils.callback import with_callbacks from dspy.utils.inspect_history import pretty_print_history MAX_HISTORY_SIZE = 10_000 GLOBAL_HISTORY = [] class BaseLM: """Base class for handling LLM calls. Most users can ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/clients/databricks.py
dspy/clients/databricks.py
import logging import os import re import time from typing import TYPE_CHECKING, Any import orjson import requests from dspy.clients.provider import Provider, TrainingJob from dspy.clients.utils_finetune import TrainDataFormat, get_finetune_directory if TYPE_CHECKING: from databricks.sdk import WorkspaceClient ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/clients/__init__.py
dspy/clients/__init__.py
import logging import os from pathlib import Path import litellm from dspy.clients.base_lm import BaseLM, inspect_history from dspy.clients.cache import Cache from dspy.clients.embedding import Embedder from dspy.clients.lm import LM from dspy.clients.provider import Provider, TrainingJob logger = logging.getLogger(...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/clients/embedding.py
dspy/clients/embedding.py
from typing import Any, Callable import litellm import numpy as np from dspy.clients.cache import request_cache class Embedder: """DSPy embedding class. The class for computing embeddings for text inputs. This class provides a unified interface for both: 1. Hosted embedding models (e.g. OpenAI's text-...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/clients/cache.py
dspy/clients/cache.py
import copy import inspect import logging import threading from functools import wraps from hashlib import sha256 from typing import Any import cloudpickle import orjson import pydantic from cachetools import LRUCache from diskcache import FanoutCache logger = logging.getLogger(__name__) class Cache: """DSPy Ca...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/clients/provider.py
dspy/clients/provider.py
from abc import abstractmethod from concurrent.futures import Future from threading import Thread from typing import TYPE_CHECKING, Any from dspy.clients.utils_finetune import TrainDataFormat if TYPE_CHECKING: from dspy.clients.lm import LM class TrainingJob(Future): def __init__( self, thre...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/clients/openai.py
dspy/clients/openai.py
import time from datetime import datetime from typing import Any import openai from dspy.clients.provider import Provider, TrainingJob from dspy.clients.utils_finetune import TrainDataFormat, TrainingStatus, save_data class TrainingJobOpenAI(TrainingJob): def __init__(self, *args, **kwargs): super().__i...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/conftest.py
tests/conftest.py
import copy import os import pytest from tests.test_utils.server import litellm_test_server, read_litellm_test_server_request_logs # noqa: F401 SKIP_DEFAULT_FLAGS = ["reliability", "extra", "llm_call"] @pytest.fixture(autouse=True) def clear_settings(): """Ensures that the settings are cleared after each test...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/__init__.py
tests/__init__.py
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/predict/test_retry.py
tests/predict/test_retry.py
# import functools # import pydantic # import dspy # from dspy.primitives.assertions import assert_transform_module, backtrack_handler # from dspy.utils import DummyLM # def test_retry_simple(): # predict = dspy.Predict("question -> answer") # retry_module = dspy.Retry(predict) # # Test Retry has creat...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/predict/test_best_of_n.py
tests/predict/test_best_of_n.py
import pytest import dspy from dspy.predict.best_of_n import BestOfN from dspy.predict.predict import Predict from dspy.primitives.prediction import Prediction from dspy.utils.dummies import DummyLM class DummyModule(dspy.Module): def __init__(self, signature, forward_fn): super().__init__() self...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/predict/test_aggregation.py
tests/predict/test_aggregation.py
from dspy.evaluate import normalize_text from dspy.predict.aggregation import majority from dspy.primitives.prediction import Completions, Prediction def test_majority_with_prediction(): prediction = Prediction.from_completions([{"answer": "2"}, {"answer": "2"}, {"answer": "3"}]) result = majority(prediction)...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/predict/test_refine.py
tests/predict/test_refine.py
import pytest import dspy from dspy.predict.predict import Predict from dspy.predict.refine import Refine from dspy.primitives.prediction import Prediction from dspy.utils.dummies import DummyLM class DummyModule(dspy.Module): def __init__(self, signature, forward_fn): super().__init__() self.pre...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/predict/test_parallel.py
tests/predict/test_parallel.py
import dspy from dspy.utils.dummies import DummyLM def test_parallel_module(): lm = DummyLM( [ {"output": "test output 1"}, {"output": "test output 2"}, {"output": "test output 3"}, {"output": "test output 4"}, {"output": "test output 5"}, ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/predict/test_predict.py
tests/predict/test_predict.py
import asyncio import copy import enum import time import types from datetime import datetime from unittest.mock import patch import orjson import pydantic import pytest from litellm import ModelResponse from pydantic import BaseModel, HttpUrl import dspy from dspy import Predict, Signature from dspy.predict.predict ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/predict/test_chain_of_thought.py
tests/predict/test_chain_of_thought.py
import pytest import dspy from dspy import ChainOfThought from dspy.utils import DummyLM def test_initialization_with_string_signature(): lm = DummyLM([{"reasoning": "find the number after 1", "answer": "2"}]) dspy.configure(lm=lm) predict = ChainOfThought("question -> answer") assert list(predict.pr...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/predict/test_multi_chain_comparison.py
tests/predict/test_multi_chain_comparison.py
import dspy from dspy.utils.dummies import DummyLM class BasicQA(dspy.Signature): """Answer questions with short factoid answers.""" question = dspy.InputField() answer = dspy.OutputField(desc="often between 1 and 5 words") # Example completions generated by a model for reference completions = [ ds...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/predict/test_code_act.py
tests/predict/test_code_act.py
import shutil import pytest import dspy from dspy import Signature from dspy.predict import CodeAct from dspy.utils import DummyLM # This test suite requires deno to be installed. Please install deno following https://docs.deno.com/runtime/getting_started/installation/ is_deno_available = shutil.which("deno") is not...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/predict/test_knn.py
tests/predict/test_knn.py
import numpy as np import pytest import dspy from dspy.predict import KNN from dspy.utils import DummyVectorizer def mock_example(question: str, answer: str) -> dspy.Example: """Creates a mock DSP example with specified question and answer.""" return dspy.Example(question=question, answer=answer).with_inputs...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/predict/test_react.py
tests/predict/test_react.py
import re import litellm import pytest from pydantic import BaseModel import dspy from dspy.utils.dummies import DummyLM @pytest.mark.extra def test_tool_observation_preserves_custom_type(): pytest.importorskip("PIL.Image") from PIL import Image captured_calls = [] class SpyChatAdapter(dspy.ChatAd...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/predict/test_program_of_thought.py
tests/predict/test_program_of_thought.py
import shutil from unittest.mock import patch import pytest import dspy from dspy import ProgramOfThought, Signature from dspy.utils import DummyLM # This test suite requires deno to be installed. Please install deno following https://docs.deno.com/runtime/getting_started/installation/ is_deno_available = shutil.whi...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/metadata/test_metadata.py
tests/metadata/test_metadata.py
import re import dspy def test_metadata(): assert dspy.__name__ == "dspy" assert re.match(r"\d+\.\d+\.\d+", dspy.__version__) assert dspy.__author__ == "Omar Khattab" assert dspy.__author_email__ == "okhattab@stanford.edu" assert dspy.__url__ == "https://github.com/stanfordnlp/dspy" assert ds...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/signatures/test_custom_types.py
tests/signatures/test_custom_types.py
import pydantic import pytest import dspy from dspy import Signature def test_basic_custom_type_resolution(): """Test basic custom type resolution with both explicit and automatic mapping.""" class CustomType(pydantic.BaseModel): value: str # Custom types can be explicitly mapped explicit_s...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/signatures/test_adapter_image.py
tests/signatures/test_adapter_image.py
import os import tempfile from io import BytesIO import pydantic import pytest import requests from PIL import Image as PILImage import dspy from dspy.adapters.types.image import encode_image from dspy.utils.dummies import DummyLM @pytest.fixture def sample_pil_image(): """Fixture to provide a sample image for ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/signatures/test_adapter_file.py
tests/signatures/test_adapter_file.py
import os import tempfile import pydantic import pytest import dspy from dspy.adapters.types.file import encode_file_to_dict from dspy.utils.dummies import DummyLM @pytest.fixture def sample_text_file(): with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".txt") as tmp_file: tmp_file.write(...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/signatures/test_signature.py
tests/signatures/test_signature.py
from types import UnionType from typing import Any, Optional, Union import pydantic import pytest import dspy from dspy import InputField, OutputField, Signature, infer_prefix from dspy.utils.dummies import DummyLM def test_field_types_and_custom_attributes(): class TestSignature(Signature): """Instruct...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/streaming/test_streaming.py
tests/streaming/test_streaming.py
import asyncio import time from dataclasses import dataclass from unittest import mock from unittest.mock import AsyncMock import pydantic import pytest from asyncer import syncify from litellm.types.utils import Delta, ModelResponseStream, StreamingChoices import dspy from dspy.adapters.types import Type from dspy.e...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
true
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/teleprompt/test_gepa_instruction_proposer.py
tests/teleprompt/test_gepa_instruction_proposer.py
from dataclasses import dataclass from typing import Any import dspy from dspy.teleprompt.gepa import instruction_proposal from dspy.utils.dummies import DummyLM def count_messages_with_image_url_pattern(messages): """Helper to count image URLs in messages - borrowed from image adapter tests""" pattern = {"t...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/teleprompt/test_finetune.py
tests/teleprompt/test_finetune.py
# TODO
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/teleprompt/test_gepa_tool_optimization.py
tests/teleprompt/test_gepa_tool_optimization.py
"""Tests for GEPA's tool optimization (ReAct modules). Test categories: 1. Detection - Compile-time detection of dspy.ReAct modules 2. Application - build_program applies optimized instructions and tool descriptions DSPy ReAct Design Note: DSPy's ReAct uses two predictors: - react: reasoning/acting loop -...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/teleprompt/test_utils.py
tests/teleprompt/test_utils.py
from unittest.mock import Mock import dspy from dspy.teleprompt.utils import eval_candidate_program class DummyModule(dspy.Module): def __init__(self): super().__init__() def forward(self, **kwargs): pass def test_eval_candidate_program_full_trainset(): trainset = [1, 2, 3, 4, 5] c...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/teleprompt/test_bootstrap_trace.py
tests/teleprompt/test_bootstrap_trace.py
from typing import Any from unittest import mock from litellm import Choices, Message, ModelResponse import dspy from dspy.primitives.example import Example from dspy.teleprompt.bootstrap_trace import FailedPrediction, bootstrap_trace_data def test_bootstrap_trace_data(): """Test bootstrap_trace_data function w...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/teleprompt/test_copro_optimizer.py
tests/teleprompt/test_copro_optimizer.py
import dspy from dspy import Example from dspy.teleprompt.signature_opt import COPRO from dspy.utils.dummies import DummyLM # Define a simple metric function for testing def simple_metric(example, prediction): # Simplified metric for testing: true if prediction matches expected output return example.output ==...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/teleprompt/test_random_search.py
tests/teleprompt/test_random_search.py
import dspy from dspy import Example from dspy.predict import Predict from dspy.teleprompt import BootstrapFewShotWithRandomSearch from dspy.utils.dummies import DummyLM class SimpleModule(dspy.Module): def __init__(self, signature): super().__init__() self.predictor = Predict(signature) def ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/teleprompt/test_gepa.py
tests/teleprompt/test_gepa.py
import json import threading from typing import Any from unittest import mock import pytest import dspy import dspy.clients from dspy import Example from dspy.predict import Predict from dspy.teleprompt.gepa import instruction_proposal from dspy.utils.dummies import DummyLM class SimpleModule(dspy.Module): def ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/teleprompt/test_ensemble.py
tests/teleprompt/test_ensemble.py
import pytest import dspy from dspy.teleprompt import Ensemble class MockProgram(dspy.Module): def __init__(self, output): super().__init__() self.output = output def forward(self, *args, **kwargs): return self.output # Simple reduction function to test with def mock_reduce_fn(outp...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/teleprompt/test_bootstrap.py
tests/teleprompt/test_bootstrap.py
import pytest import dspy from dspy import Example from dspy.predict import Predict from dspy.teleprompt import BootstrapFewShot from dspy.utils.dummies import DummyLM # Define a simple metric function for testing def simple_metric(example, prediction, trace=None): # Simplified metric for testing: true if predic...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/teleprompt/test_teleprompt.py
tests/teleprompt/test_teleprompt.py
from dspy.teleprompt.teleprompt import Teleprompter class DummyTeleprompter(Teleprompter): def __init__(self, param1: int, param2: str): super().__init__() self.param1 = param1 self.param2 = param2 def compile(self, student, *, trainset, teacher=None, valset=None, **kwargs): r...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/teleprompt/test_grpo.py
tests/teleprompt/test_grpo.py
from dspy.teleprompt.grpo import GRPO def test_grpo_dataset_shuffler(): dataset = [1, 2, 3] grpo = GRPO( num_dspy_examples_per_grpo_step=3, exclude_demos=True, ) trainset_instances = [] for i in range(4): trainset_instances.append(grpo.select_training_sample_and_update_shu...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/teleprompt/test_knn_fewshot.py
tests/teleprompt/test_knn_fewshot.py
import pytest import dspy from dspy.teleprompt.knn_fewshot import KNNFewShot from dspy.utils.dummies import DummyLM, DummyVectorizer def mock_example(question: str, answer: str) -> dspy.Example: """Creates a mock DSP example with specified question and answer.""" return dspy.Example(question=question, answer...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/teleprompt/test_bootstrap_finetune.py
tests/teleprompt/test_bootstrap_finetune.py
from unittest.mock import patch import dspy from dspy import Example from dspy.predict import Predict from dspy.teleprompt import BootstrapFinetune from dspy.utils.dummies import DummyLM # Define a simple metric function for testing def simple_metric(example, prediction, trace=None): return example.output == pre...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/datasets/test_dataset.py
tests/datasets/test_dataset.py
import tempfile import uuid import pytest from dspy import Example from dspy.datasets.dataset import Dataset dummy_data = """content,question,answer "This is content 1","What is this?","This is answer 1" "This is content 2","What is that?","This is answer 2" """ class CSVDataset(Dataset): def __init__(self, fi...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/callback/test_callback.py
tests/callback/test_callback.py
import time import pytest import dspy from dspy.utils.callback import ACTIVE_CALL_ID, BaseCallback, with_callbacks from dspy.utils.dummies import DummyLM @pytest.fixture(autouse=True) def reset_settings(): # Make sure the settings are reset after each test original_settings = dspy.settings.copy() yield...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/utils/test_usage_tracker.py
tests/utils/test_usage_tracker.py
from unittest import mock from pydantic import BaseModel import dspy from dspy.utils.usage_tracker import UsageTracker, track_usage def test_add_usage_entry(): """Test adding usage entries to the tracker.""" tracker = UsageTracker() # Test with a single usage entry usage_entry = { "prompt_t...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/utils/test_langchain_tool.py
tests/utils/test_langchain_tool.py
import importlib import pytest if importlib.util.find_spec("langchain_core") is None: pytest.skip(reason="langchain_core is not installed", allow_module_level=True) from pydantic import BaseModel from dspy.utils.langchain_tool import convert_langchain_tool @pytest.mark.asyncio @pytest.mark.extra async def tes...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/utils/test_mcp.py
tests/utils/test_mcp.py
import asyncio import importlib import pytest from dspy.utils.mcp import convert_mcp_tool if importlib.util.find_spec("mcp") is None: pytest.skip(reason="mcp is not installed", allow_module_level=True) @pytest.mark.asyncio @pytest.mark.extra async def test_convert_mcp_tool(): from mcp import ClientSession,...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/utils/test_magicattr.py
tests/utils/test_magicattr.py
import pytest from dspy.utils import magicattr class Test: l = [1, 2] a = [0, [1, 2, [3, 4]]] b = {"x": {"y": "y"}, "z": [1, 2]} z = "z" class Person: settings = { "autosave": True, "style": {"height": 30, "width": 200}, "themes": ["light", "dark"], } def __init...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/utils/test_parallelizer.py
tests/utils/test_parallelizer.py
import time import pytest from dspy.utils.parallelizer import ParallelExecutor def test_worker_threads_independence(): def task(item): # Each thread maintains its own state by appending to a thread-local list return item * 2 data = [1, 2, 3, 4, 5] executor = ParallelExecutor(num_threads...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/utils/test_annotation.py
tests/utils/test_annotation.py
from dspy.utils.annotation import experimental def test_experimental_decorator_on_function(): @experimental def test_function(): """A test function.""" return "test" assert "Experimental: This function may change or be removed in a future release without warning." in test_function.__doc__...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/utils/test_unbatchify.py
tests/utils/test_unbatchify.py
import time from concurrent.futures import Future from unittest.mock import MagicMock from dspy.utils.unbatchify import Unbatchify def simple_batch_processor(batch): """A simple batch function that adds 1 to each item.""" return [item + 1 for item in batch] def submit(self, input_item: any) -> Future: ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/utils/__init__.py
tests/utils/__init__.py
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/utils/test_syncify.py
tests/utils/test_syncify.py
import asyncio import dspy def test_syncify_in_place(): class MyProgram(dspy.Module): async def aforward(self, x: int) -> int: await asyncio.sleep(0.01) return x + 1 sync_program = dspy.syncify(MyProgram()) assert sync_program(1) == 2 assert sync_program(2) == 3 def...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/utils/test_settings.py
tests/utils/test_settings.py
import asyncio import time from concurrent.futures import ThreadPoolExecutor from unittest import mock import pytest from litellm import Choices, Message, ModelResponse import dspy def test_basic_dspy_settings(): dspy.configure(lm=dspy.LM("openai/gpt-4o"), adapter=dspy.JSONAdapter(), callbacks=[lambda x: x]) ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/utils/test_exceptions.py
tests/utils/test_exceptions.py
import dspy from dspy.utils.exceptions import AdapterParseError def test_adapter_parse_error_basic(): adapter_name = "ChatAdapter" signature = dspy.make_signature("question->answer1, answer2") lm_response = "[[ ## answer1 ## ]]\nanswer1" error = AdapterParseError(adapter_name=adapter_name, signature=...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/utils/test_asyncify.py
tests/utils/test_asyncify.py
import asyncio import math from time import sleep, time import pytest import dspy from dspy.utils.asyncify import get_limiter @pytest.mark.anyio async def test_async_limiter(): limiter = get_limiter() assert limiter.total_tokens == 8, "Default async capacity should be 8" assert get_limiter() == limiter,...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/utils/test_saving.py
tests/utils/test_saving.py
import logging from unittest.mock import patch import pytest import dspy from dspy.utils import DummyLM def test_save_predict(tmp_path): predict = dspy.Predict("question->answer") predict.save(tmp_path, save_program=True) assert (tmp_path / "metadata.json").exists() assert (tmp_path / "program.pkl"...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/utils/resources/mcp_server.py
tests/utils/resources/mcp_server.py
from mcp.server.fastmcp import FastMCP from pydantic import BaseModel mcp = FastMCP("test") class Profile(BaseModel): name: str age: int class Account(BaseModel): profile: Profile account_id: str @mcp.tool() def add(a: int, b: int) -> int: """Add two numbers""" return a + b @mcp.tool() ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/primitives/test_base_module.py
tests/primitives/test_base_module.py
import asyncio import logging import os import threading from unittest.mock import patch import pytest from litellm import Choices, Message, ModelResponse from litellm.types.utils import Usage import dspy from dspy.primitives.prediction import Prediction from dspy.utils.dummies import DummyLM def test_deepcopy_basi...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/primitives/test_example.py
tests/primitives/test_example.py
import pytest import dspy from dspy import Example def test_example_initialization(): example = Example(a=1, b=2) assert example.a == 1 assert example.b == 2 def test_example_initialization_from_base(): base = Example(a=1, b=2) example = Example(base=base, c=3) assert example.a == 1 ass...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/primitives/test_module.py
tests/primitives/test_module.py
from pathlib import Path import dspy from dspy.primitives.module import Module, set_attribute_by_name # Adjust the import based on your file structure from dspy.utils import DummyLM class HopModule(dspy.Module): def __init__(self): super().__init__() self.predict1 = dspy.Predict("question -> que...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/primitives/test_python_interpreter.py
tests/primitives/test_python_interpreter.py
import os import random import shutil import pytest from dspy.primitives.python_interpreter import InterpreterError, PythonInterpreter # This test suite requires deno to be installed. Please install deno following https://docs.deno.com/runtime/getting_started/installation/ if shutil.which("deno") is None: pytest...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/reliability/test_generated.py
tests/reliability/test_generated.py
import os import pytest from tests.reliability.generate.utils import load_generated_cases, run_generated_case _DIR_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__))) @pytest.mark.reliability @pytest.mark.parametrize( "generated_case", load_generated_cases(_DIR_PATH), ids=lambda case: case....
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/reliability/test_pydantic_models.py
tests/reliability/test_pydantic_models.py
from enum import Enum from typing import Any, List, Literal import pydantic import pytest import dspy from tests.reliability.utils import assert_program_output_correct, known_failing_models @pytest.mark.reliability def test_qa_with_pydantic_answer_model(): class Answer(pydantic.BaseModel): value: str ...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false
stanfordnlp/dspy
https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/tests/reliability/conftest.py
tests/reliability/conftest.py
import os import pytest import dspy from ..conftest import clear_settings from ..reliability.utils import get_adapter, parse_reliability_conf_yaml # Standard list of models that should be used for periodic DSPy reliability testing MODEL_LIST = [ "gpt-4o", "gpt-4o-mini", "gpt-4-turbo", "gpt-o1-preview...
python
MIT
becb4c9e849a292f71a1f1623acd375aaa32edef
2026-01-04T14:43:07.742507Z
false