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 |
|---|---|---|---|---|---|---|---|---|
stanford-oval/storm | https://github.com/stanford-oval/storm/blob/fb951af7744dab086e34962e9bc6fe878e145f83/examples/storm_examples/helper/process_kaggle_arxiv_abstract_dataset.py | examples/storm_examples/helper/process_kaggle_arxiv_abstract_dataset.py | """Process `arxiv_data_210930-054931.csv`
from https://www.kaggle.com/datasets/spsayakpaul/arxiv-paper-abstracts
to a csv file that is compatible with VectorRM.
"""
from argparse import ArgumentParser
import pandas as pd
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument(
"--in... | python | MIT | fb951af7744dab086e34962e9bc6fe878e145f83 | 2026-01-04T14:44:02.494109Z | false |
stanford-oval/storm | https://github.com/stanford-oval/storm/blob/fb951af7744dab086e34962e9bc6fe878e145f83/examples/costorm_examples/run_costorm_gpt.py | examples/costorm_examples/run_costorm_gpt.py | """
Co-STORM pipeline powered by GPT-4o/4o-mini and Bing search engine.
You need to set up the following environment variables to run this script:
- OPENAI_API_KEY: OpenAI API key
- OPENAI_API_TYPE: OpenAI API type (e.g., 'openai' or 'azure')
- AZURE_API_BASE: Azure API base URL if using Azure API
- AZU... | python | MIT | fb951af7744dab086e34962e9bc6fe878e145f83 | 2026-01-04T14:44:02.494109Z | false |
stanford-oval/storm | https://github.com/stanford-oval/storm/blob/fb951af7744dab086e34962e9bc6fe878e145f83/frontend/demo_light/demo_util.py | frontend/demo_light/demo_util.py | import base64
import datetime
import json
import os
import re
from typing import Optional
import markdown
import pytz
import streamlit as st
# If you install the source code instead of the `knowledge-storm` package,
# Uncomment the following lines:
# import sys
# sys.path.append('../../')
from knowledge_storm import ... | python | MIT | fb951af7744dab086e34962e9bc6fe878e145f83 | 2026-01-04T14:44:02.494109Z | false |
stanford-oval/storm | https://github.com/stanford-oval/storm/blob/fb951af7744dab086e34962e9bc6fe878e145f83/frontend/demo_light/storm.py | frontend/demo_light/storm.py | import os
script_dir = os.path.dirname(os.path.abspath(__file__))
wiki_root_dir = os.path.dirname(os.path.dirname(script_dir))
import demo_util
from pages_util import MyArticles, CreateNewArticle
from streamlit_float import *
from streamlit_option_menu import option_menu
def main():
global database
st.set_p... | python | MIT | fb951af7744dab086e34962e9bc6fe878e145f83 | 2026-01-04T14:44:02.494109Z | false |
stanford-oval/storm | https://github.com/stanford-oval/storm/blob/fb951af7744dab086e34962e9bc6fe878e145f83/frontend/demo_light/stoc.py | frontend/demo_light/stoc.py | """https://github.com/arnaudmiribel/stoc"""
import re
import streamlit as st
import unidecode
DISABLE_LINK_CSS = """
<style>
a.toc {
color: inherit;
text-decoration: none; /* no underline */
}
</style>"""
class stoc:
def __init__(self):
self.toc_items = list()
def h1(self, text: str, write... | python | MIT | fb951af7744dab086e34962e9bc6fe878e145f83 | 2026-01-04T14:44:02.494109Z | false |
stanford-oval/storm | https://github.com/stanford-oval/storm/blob/fb951af7744dab086e34962e9bc6fe878e145f83/frontend/demo_light/pages_util/MyArticles.py | frontend/demo_light/pages_util/MyArticles.py | import os
import demo_util
import streamlit as st
from demo_util import DemoFileIOHelper, DemoUIHelper
from streamlit_card import card
# set page config and display title
def my_articles_page():
with st.sidebar:
_, return_button_col = st.columns([2, 5])
with return_button_col:
if st.b... | python | MIT | fb951af7744dab086e34962e9bc6fe878e145f83 | 2026-01-04T14:44:02.494109Z | false |
stanford-oval/storm | https://github.com/stanford-oval/storm/blob/fb951af7744dab086e34962e9bc6fe878e145f83/frontend/demo_light/pages_util/CreateNewArticle.py | frontend/demo_light/pages_util/CreateNewArticle.py | import os
import time
import demo_util
import streamlit as st
from demo_util import (
DemoFileIOHelper,
DemoTextProcessingHelper,
DemoUIHelper,
truncate_filename,
)
def handle_not_started():
if st.session_state["page3_write_article_state"] == "not started":
_, search_form_column, _ = st.c... | python | MIT | fb951af7744dab086e34962e9bc6fe878e145f83 | 2026-01-04T14:44:02.494109Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/.github/workflows/build_utils/test_version.py | .github/workflows/build_utils/test_version.py | import sys
from datetime import datetime
import requests
import semver
from packaging.version import Version as PyPIVersion
def get_latest_version(package_name, tag_version):
# Returns latest version, and T/F as to whether it needs to be incremented
response = requests.get(f"https://test.pypi.org/pypi/{pac... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/__metadata__.py | dspy/__metadata__.py | #replace_package_name_marker
__name__="dspy"
#replace_package_version_marker
__version__="3.1.0b1"
__description__="DSPy"
__url__="https://github.com/stanfordnlp/dspy"
__author__="Omar Khattab"
__author_email__="okhattab@stanford.edu" | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/__init__.py | dspy/__init__.py | from dspy.predict import *
from dspy.primitives import *
from dspy.retrievers import *
from dspy.signatures import *
from dspy.teleprompt import *
from dspy.evaluate import Evaluate # isort: skip
from dspy.clients import * # isort: skip
from dspy.adapters import Adapter, ChatAdapter, JSONAdapter, XMLAdapter, TwoStep... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/multi_chain_comparison.py | dspy/predict/multi_chain_comparison.py | from dspy.predict.predict import Predict
from dspy.primitives.module import Module
from dspy.signatures import InputField, OutputField
from dspy.signatures.signature import ensure_signature
class MultiChainComparison(Module):
def __init__(self, signature, M=3, temperature=0.7, **config): # noqa: N803
sup... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/best_of_n.py | dspy/predict/best_of_n.py | from typing import Callable
import dspy
from dspy.predict.predict import Module, Prediction
class BestOfN(Module):
def __init__(
self,
module: Module,
N: int, # noqa: N803
reward_fn: Callable[[dict, Prediction], float],
threshold: float,
fail_count: int | None = N... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/chain_of_thought.py | dspy/predict/chain_of_thought.py | from typing import Any
from pydantic.fields import FieldInfo
import dspy
from dspy.primitives.module import Module
from dspy.signatures.signature import Signature, ensure_signature
class ChainOfThought(Module):
def __init__(
self,
signature: str | type[Signature],
rationale_field: FieldI... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/program_of_thought.py | dspy/predict/program_of_thought.py | import json
import logging
import re
import dspy
from dspy.primitives.module import Module
from dspy.primitives.python_interpreter import PythonInterpreter
from dspy.signatures.signature import Signature, ensure_signature
logger = logging.getLogger(__name__)
class ProgramOfThought(Module):
"""
A DSPy module... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/refine.py | dspy/predict/refine.py | import inspect
import textwrap
from typing import Callable
import orjson
import dspy
from dspy.adapters.utils import get_field_description_string
from dspy.predict.predict import Prediction
from dspy.signatures import InputField, OutputField, Signature
from .predict import Module
class OfferFeedback(Signature):
... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/knn.py | dspy/predict/knn.py | import numpy as np
from dspy.clients import Embedder
from dspy.primitives import Example
class KNN:
def __init__(self, k: int, trainset: list[Example], vectorizer: Embedder):
"""
A k-nearest neighbors retriever that finds similar examples from a training set.
Args:
k: Number ... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/parameter.py | dspy/predict/parameter.py | class Parameter:
pass
| python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/code_act.py | dspy/predict/code_act.py | import inspect
import logging
from typing import Callable
import dspy
from dspy.adapters.types.tool import Tool
from dspy.predict.program_of_thought import ProgramOfThought
from dspy.predict.react import ReAct
from dspy.primitives.python_interpreter import PythonInterpreter
from dspy.signatures.signature import Signat... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/react.py | dspy/predict/react.py | import logging
from typing import TYPE_CHECKING, Any, Callable, Literal
from litellm import ContextWindowExceededError
import dspy
from dspy.adapters.types.tool import Tool
from dspy.primitives.module import Module
from dspy.signatures.signature import ensure_signature
logger = logging.getLogger(__name__)
if TYPE_C... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/retry.py | dspy/predict/retry.py | # import copy
# import dspy
# from .predict import Predict
# class Retry(Predict):
# def __init__(self, module):
# super().__init__(module.signature)
# self.module = module
# self.original_signature = module.signature
# self.original_forward = module.forward
# self.new_si... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/__init__.py | dspy/predict/__init__.py | from dspy.predict.aggregation import majority
from dspy.predict.best_of_n import BestOfN
from dspy.predict.chain_of_thought import ChainOfThought
from dspy.predict.code_act import CodeAct
from dspy.predict.knn import KNN
from dspy.predict.multi_chain_comparison import MultiChainComparison
from dspy.predict.parallel imp... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/predict.py | dspy/predict/predict.py | import logging
import random
from pydantic import BaseModel
from dspy.adapters.chat_adapter import ChatAdapter
from dspy.clients.base_lm import BaseLM
from dspy.clients.lm import LM
from dspy.dsp.utils.settings import settings
from dspy.predict.parameter import Parameter
from dspy.primitives.module import Module
from... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/aggregation.py | dspy/predict/aggregation.py | from dspy.evaluate import normalize_text
from dspy.primitives.prediction import Completions, Prediction
def default_normalize(s):
return normalize_text(s) or None
def majority(prediction_or_completions, normalize=default_normalize, field=None):
"""
Returns the most common completion for the target field... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/parallel.py | dspy/predict/parallel.py | import threading
from typing import Any
from dspy.dsp.utils.settings import settings
from dspy.primitives.example import Example
from dspy.utils.parallelizer import ParallelExecutor
class Parallel:
def __init__(
self,
num_threads: int | None = None,
max_errors: int | None = None,
... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/avatar/models.py | dspy/predict/avatar/models.py | from typing import Any
from pydantic import BaseModel, Field
class Tool(BaseModel):
tool: Any
name: str
desc: str | None
input_type: str | None = None
def __str__(self) -> str:
return f"{self.name}{f'(valid_input: {self.input_type})' if self.input_type else ''}: {self.desc}"
def __r... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/avatar/signatures.py | dspy/predict/avatar/signatures.py | import dspy
from dspy.predict.avatar.models import Action
class Actor(dspy.Signature):
"""You will be given `Tools` which will be a list of tools to use to accomplish the `Goal`. Given the user query, your task is to decide which tool to use and what input values to provide.
You will output action needed to ... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/avatar/__init__.py | dspy/predict/avatar/__init__.py | from dspy.predict.avatar.avatar import *
from dspy.predict.avatar.models import *
from dspy.predict.avatar.signatures import *
| python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/predict/avatar/avatar.py | dspy/predict/avatar/avatar.py | from copy import deepcopy
from pydantic.fields import FieldInfo
import dspy
from dspy.predict.avatar.models import Action, ActionOutput, Tool
from dspy.predict.avatar.signatures import Actor
from dspy.signatures.signature import ensure_signature
def get_number_with_suffix(number: int) -> str:
if number == 1:
... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/signatures/signature.py | dspy/signatures/signature.py | """Signature class for DSPy.
You typically subclass the Signature class, like this:
class MySignature(dspy.Signature):
input: str = InputField(desc="...")
output: int = OutputField(desc="...")
You can call Signature("input1, input2 -> output1, output2") to create a new signature type.
You can also... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/signatures/utils.py | dspy/signatures/utils.py | from typing import Literal
from pydantic.fields import FieldInfo
def get_dspy_field_type(field: FieldInfo) -> Literal["input", "output"]:
field_type = field.json_schema_extra.get("__dspy_field_type")
if field_type is None:
raise ValueError(f"Field {field} does not have a __dspy_field_type")
retur... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/signatures/__init__.py | dspy/signatures/__init__.py | from dspy.signatures.field import InputField, OldField, OldInputField, OldOutputField, OutputField
from dspy.signatures.signature import (
Signature,
SignatureMeta,
ensure_signature,
infer_prefix,
make_signature,
)
__all__ = [
"InputField",
"OutputField",
"OldField",
"OldInputField"... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/signatures/field.py | dspy/signatures/field.py | import pydantic
# The following arguments can be used in DSPy InputField and OutputField in addition
# to the standard pydantic.Field arguments. We just hope pydanitc doesn't add these,
# as it would give a name clash.
DSPY_FIELD_ARG_NAMES = ["desc", "prefix", "format", "parser", "__dspy_field_type"]
PYDANTIC_CONSTRA... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/streaming/streamify.py | dspy/streaming/streamify.py | import asyncio
import contextvars
import logging
import threading
from asyncio import iscoroutinefunction
from queue import Queue
from typing import TYPE_CHECKING, Any, AsyncGenerator, Awaitable, Callable, Generator
import litellm
import orjson
from anyio import create_memory_object_stream, create_task_group
from anyi... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/streaming/streaming_listener.py | dspy/streaming/streaming_listener.py | import inspect
import re
from collections import defaultdict
from queue import Queue
from typing import TYPE_CHECKING, Any
import jiter
from litellm import ModelResponseStream
from dspy.adapters.chat_adapter import ChatAdapter
from dspy.adapters.json_adapter import JSONAdapter
from dspy.adapters.types import Type
fro... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/streaming/__init__.py | dspy/streaming/__init__.py | from dspy.streaming.messages import StatusMessage, StatusMessageProvider, StreamResponse
from dspy.streaming.streamify import apply_sync_streaming, streamify, streaming_response
from dspy.streaming.streaming_listener import StreamListener
__all__ = [
"StatusMessage",
"StatusMessageProvider",
"streamify",
... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/streaming/messages.py | dspy/streaming/messages.py | import asyncio
import concurrent.futures
from dataclasses import dataclass
from typing import Any
from asyncer import syncify
from dspy.dsp.utils.settings import settings
from dspy.utils.callback import BaseCallback
@dataclass
class StreamResponse:
predict_name: str
signature_field_name: str
chunk: str
... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/dsp/colbertv2.py | dspy/dsp/colbertv2.py | from typing import Any
import requests
from dspy.clients.cache import request_cache
from dspy.dsp.utils import dotdict
# TODO: Ideally, this takes the name of the index and looks up its port.
class ColBERTv2:
"""Wrapper for the ColBERTv2 Retrieval."""
def __init__(
self,
url: str = "http:/... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/dsp/__init__.py | dspy/dsp/__init__.py | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false | |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/dsp/utils/dpr.py | dspy/dsp/utils/dpr.py | """
Source: DPR Implementation from Facebook Research
https://github.com/facebookresearch/DPR/tree/master/dpr
Original license: https://github.com/facebookresearch/DPR/blob/main/LICENSE
"""
import copy
import logging
import unicodedata
import regex
logger = logging.getLogger(__name__)
class Tokens:
"""A class ... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/dsp/utils/utils.py | dspy/dsp/utils/utils.py | import copy
import datetime
import itertools
import os
from collections import defaultdict
import tqdm
def print_message(*s, condition=True, pad=False, sep=None):
s = " ".join([str(x) for x in s])
msg = "[{}] {}".format(datetime.datetime.now().strftime("%b %d, %H:%M:%S"), s)
if condition:
msg = ... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/dsp/utils/settings.py | dspy/dsp/utils/settings.py | import asyncio
import contextvars
import copy
import threading
from contextlib import contextmanager
from dspy.dsp.utils.utils import dotdict
DEFAULT_CONFIG = dotdict(
lm=None,
adapter=None,
rm=None,
branch_idx=0,
trace=[],
callbacks=[],
async_max_workers=8,
send_stream=None,
disab... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/dsp/utils/__init__.py | dspy/dsp/utils/__init__.py | from dspy.dsp.utils.dpr import *
from dspy.dsp.utils.settings import *
from dspy.dsp.utils.utils import *
| python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/bootstrap_trace.py | dspy/teleprompt/bootstrap_trace.py | import logging
from dataclasses import dataclass
from types import MethodType
from typing import Any, Callable, TypedDict
import dspy
from dspy.evaluate.evaluate import Evaluate
from dspy.primitives.example import Example
from dspy.primitives.module import Module
from dspy.primitives.prediction import Prediction
from ... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/signature_opt.py | dspy/teleprompt/signature_opt.py | from .copro_optimizer import COPRO
"""
===============================================================
DEPRECATED!!!
PLEASE USE COPRO INSTEAD.
===============================================================
USAGE SUGGESTIONS:
The following code can be used to compile a optimized signature teleprompter, and evaluate ... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/simba_utils.py | dspy/teleprompt/simba_utils.py | import inspect
import logging
import textwrap
from typing import Callable
import orjson
import dspy
from dspy.adapters.utils import get_field_description_string
from dspy.signatures import InputField, OutputField
logger = logging.getLogger(__name__)
def prepare_models_for_resampling(program: dspy.Module, n: int, te... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/teleprompt.py | dspy/teleprompt/teleprompt.py | from typing import Any
from dspy.primitives import Example, Module
class Teleprompter:
def __init__(self):
pass
def compile(self, student: Module, *, trainset: list[Example], teacher: Module | None = None, valset: list[Example] | None = None, **kwargs) -> Module:
"""
Optimize the stu... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/ensemble.py | dspy/teleprompt/ensemble.py | import random
from dspy.teleprompt.teleprompt import Teleprompter
"""
TODO: The EnsembledProgram should actually imitate the structure of the individual programs (IF they are all compatible). This allows compiling with an ensemble program as a (singular) teacher. Basically the top majority-compatible trace will end u... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/vanilla.py | dspy/teleprompt/vanilla.py | import random
from dspy.teleprompt.teleprompt import Teleprompter
class LabeledFewShot(Teleprompter):
def __init__(self, k=16):
self.k = k
def compile(self, student, *, trainset, sample=True):
self.student = student.reset_copy()
self.trainset = trainset
if len(self.trainset)... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/mipro_optimizer_v2.py | dspy/teleprompt/mipro_optimizer_v2.py | import logging
import random
from collections import defaultdict
from typing import TYPE_CHECKING, Any, Callable, Literal
import numpy as np
import dspy
from dspy.evaluate.evaluate import Evaluate
from dspy.propose import GroundedProposer
from dspy.teleprompt.teleprompt import Teleprompter
from dspy.teleprompt.utils ... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | true |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/teleprompt_optuna.py | dspy/teleprompt/teleprompt_optuna.py | from dspy.evaluate.evaluate import Evaluate
from dspy.teleprompt.teleprompt import Teleprompter
from .bootstrap import BootstrapFewShot
class BootstrapFewShotWithOptuna(Teleprompter):
def __init__(
self,
metric,
teacher_settings=None,
max_bootstrapped_demos=4,
max_labeled_... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/avatar_optimizer.py | dspy/teleprompt/avatar_optimizer.py | from concurrent.futures import ThreadPoolExecutor
from copy import deepcopy
from random import sample
from typing import Callable
from pydantic import BaseModel
from tqdm import tqdm
import dspy
from dspy.predict.avatar import ActionOutput
from dspy.teleprompt.teleprompt import Teleprompter
DEFAULT_MAX_EXAMPLES = 10... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/infer_rules.py | dspy/teleprompt/infer_rules.py | import logging
import random
import numpy as np
import dspy
from dspy.evaluate.evaluate import Evaluate
from dspy.teleprompt import BootstrapFewShot
logger = logging.getLogger(__name__)
class InferRules(BootstrapFewShot):
def __init__(self, num_candidates=10, num_rules=10, num_threads=None, teacher_settings=No... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/utils.py | dspy/teleprompt/utils.py | import inspect
import logging
import math
import os
import random
import shutil
import sys
import numpy as np
try:
from IPython.core.magics.code import extract_symbols
except ImportError:
# Won't be able to read code from jupyter notebooks
extract_symbols = None
import dspy
from dspy.teleprompt.bootstrap... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/__init__.py | dspy/teleprompt/__init__.py | from dspy.teleprompt.avatar_optimizer import AvatarOptimizer
from dspy.teleprompt.bettertogether import BetterTogether
from dspy.teleprompt.bootstrap import BootstrapFewShot
from dspy.teleprompt.bootstrap_finetune import BootstrapFinetune
from dspy.teleprompt.bootstrap_trace import bootstrap_trace_data
from dspy.telepr... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/grpo.py | dspy/teleprompt/grpo.py | import logging
import random
import time
from collections import Counter, deque
from typing import Any, Callable, Literal
from dspy.adapters.base import Adapter
from dspy.adapters.chat_adapter import ChatAdapter
from dspy.adapters.xml_adapter import XMLAdapter
from dspy.clients.lm import LM
from dspy.clients.utils_fin... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | true |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/copro_optimizer.py | dspy/teleprompt/copro_optimizer.py | import logging
from collections import defaultdict
import dspy
from dspy.evaluate.evaluate import Evaluate
from dspy.signatures import Signature
from dspy.teleprompt.teleprompt import Teleprompter
logger = logging.getLogger(__name__)
"""
USAGE SUGGESTIONS:
The following code can be used to compile a optimized signa... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/bootstrap.py | dspy/teleprompt/bootstrap.py | import logging
import random
import threading
import tqdm
import dspy
from dspy.teleprompt.teleprompt import Teleprompter
from .vanilla import LabeledFewShot
# TODO: metrics should return an object with __bool__ basically, but fine if they're more complex.
# They can also be sortable.
# TODO: Switch here from dspy... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/random_search.py | dspy/teleprompt/random_search.py | import random
import dspy
from dspy.evaluate.evaluate import Evaluate
from dspy.teleprompt.teleprompt import Teleprompter
from .bootstrap import BootstrapFewShot
from .vanilla import LabeledFewShot
# TODO: Don't forget dealing with the raw demos.
# TODO: Deal with the (pretty common) case of having a metric for filt... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/knn_fewshot.py | dspy/teleprompt/knn_fewshot.py | import types
from typing import Any
from dspy.clients import Embedder
from dspy.predict.knn import KNN
from dspy.primitives import Example
from dspy.teleprompt import BootstrapFewShot
from dspy.teleprompt.teleprompt import Teleprompter
class KNNFewShot(Teleprompter):
def __init__(self, k: int, trainset: list[Exa... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/bootstrap_finetune.py | dspy/teleprompt/bootstrap_finetune.py | import logging
from collections import defaultdict
from typing import Any, Callable
import dspy
from dspy.adapters.base import Adapter
from dspy.adapters.chat_adapter import ChatAdapter
from dspy.clients.lm import LM
from dspy.clients.utils_finetune import infer_data_format
from dspy.dsp.utils.settings import settings... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/simba.py | dspy/teleprompt/simba.py | from __future__ import annotations
import logging
import random
from typing import Any, Callable
import numpy as np
import dspy
from dspy.teleprompt.simba_utils import append_a_demo, append_a_rule, prepare_models_for_resampling, wrap_program
from dspy.teleprompt.teleprompt import Teleprompter
logger = logging.getLo... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/bettertogether.py | dspy/teleprompt/bettertogether.py | import logging
import random
from typing import Callable
import dspy
from dspy.primitives.example import Example
from dspy.primitives.module import Module
from dspy.teleprompt.bootstrap_finetune import (
BootstrapFinetune,
all_predictors_have_lms,
kill_lms,
launch_lms,
prepare_student,
)
from dspy.... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/gepa/instruction_proposal.py | dspy/teleprompt/gepa/instruction_proposal.py | import json
import logging
from typing import Any
from gepa.core.adapter import ProposalFn
import dspy
from dspy.adapters.types.base_type import Type
from dspy.teleprompt.gepa.gepa_utils import ReflectiveExample
logger = logging.getLogger(__name__)
class GenerateEnhancedMultimodalInstructionFromFeedback(dspy.Signa... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/gepa/gepa.py | dspy/teleprompt/gepa/gepa.py | import inspect
import json
import logging
import random
from dataclasses import dataclass
from typing import Any, Literal, Optional, Protocol, Union
from gepa import GEPAResult
from gepa.core.adapter import ProposalFn
from gepa.proposer.reflective_mutation.base import ReflectionComponentSelector
from dspy.clients.lm ... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | true |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/gepa/gepa_utils.py | dspy/teleprompt/gepa/gepa_utils.py | import json
import logging
import random
from typing import Any, Callable, Protocol, TypedDict
from gepa import EvaluationBatch, GEPAAdapter
from gepa.core.adapter import ProposalFn
from gepa.strategies.instruction_proposal import InstructionProposalSignature
import dspy
from dspy.adapters.chat_adapter import ChatAda... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/teleprompt/gepa/__init__.py | dspy/teleprompt/gepa/__init__.py | from dspy.teleprompt.gepa.gepa import GEPA
__all__ = ["GEPA"]
| python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/datasets/gsm8k.py | dspy/datasets/gsm8k.py | import random
import tqdm
class GSM8K:
def __init__(self):
self.do_shuffle = False
from datasets import load_dataset
dataset = load_dataset("gsm8k", "main")
hf_official_train = dataset["train"]
hf_official_test = dataset["test"]
official_train = []
offic... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/datasets/hotpotqa.py | dspy/datasets/hotpotqa.py | import random
from dspy.datasets.dataset import Dataset
class HotPotQA(Dataset):
def __init__(
self,
*args,
only_hard_examples=True,
keep_details="dev_titles",
unofficial_dev=True,
**kwargs,
) -> None:
super().__init__(*args, **kwargs)
assert on... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/datasets/dataset.py | dspy/datasets/dataset.py | from __future__ import annotations
import random
import uuid
from collections.abc import Iterable
from typing import Any
from dspy import Example
from dspy.dsp.utils import dotdict
class Dataset:
def __init__(
self,
train_seed: int = 0,
train_size: int | None = None,
eval_seed: i... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/datasets/__init__.py | dspy/datasets/__init__.py | from dspy.datasets.alfworld import AlfWorld
from dspy.datasets.colors import Colors
from dspy.datasets.dataloader import DataLoader
from dspy.datasets.dataset import Dataset
from dspy.datasets.hotpotqa import HotPotQA
from dspy.datasets.math import MATH
__all__ = [
"Colors",
"DataLoader",
"Dataset",
"H... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/datasets/dataloader.py | dspy/datasets/dataloader.py | import random
from collections.abc import Mapping
from typing import TYPE_CHECKING
import dspy
from dspy.datasets.dataset import Dataset
if TYPE_CHECKING:
import pandas as pd
class DataLoader(Dataset):
def __init__(self):
pass
def from_huggingface(
self,
dataset_name: str,
... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/datasets/math.py | dspy/datasets/math.py | import random
import re
class MATH:
def __init__(self, subset):
from datasets import load_dataset
import dspy
ds = load_dataset("DigitalLearningGmbH/MATH-lighteval", subset)
# NOTE: Defaults to sub-splitting MATH's 'test' split into train/dev/test, presuming that current
... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/datasets/colors.py | dspy/datasets/colors.py | import random
from dspy.datasets.dataset import Dataset
### A bunch of colors, originally from matplotlib
all_colors = [
"alice blue",
"dodger blue",
"light sky blue",
"deep sky blue",
"sky blue",
"steel blue",
"light steel blue",
"medium blue",
"navy blue",
"blue",
"royal ... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/datasets/alfworld/alfworld.py | dspy/datasets/alfworld/alfworld.py | import os
import queue
import random
def env_worker(inq, outq):
"""
Worker process: creates a single AlfredTWEnv instance,
handles 'init' (with task idx) and 'step' (with action).
"""
try:
import io
from contextlib import redirect_stderr, redirect_stdout
import alfworld.a... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/datasets/alfworld/__init__.py | dspy/datasets/alfworld/__init__.py | from dspy.datasets.alfworld.alfworld import AlfWorld
| python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/logging_utils.py | dspy/utils/logging_utils.py | import logging
import logging.config
import sys
LOGGING_LINE_FORMAT = "%(asctime)s %(levelname)s %(name)s: %(message)s"
LOGGING_DATETIME_FORMAT = "%Y/%m/%d %H:%M:%S"
class DSPyLoggingStream:
"""
A Python stream for use with event logging APIs throughout DSPy (`eprint()`,
`logger.info()`, etc.). This stre... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/syncify.py | dspy/utils/syncify.py | import asyncio
from types import MethodType
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from dspy.primitives.module import Module
def run_async(coro):
"""Run an async coroutine from a synchronous context."""
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = Non... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/parallelizer.py | dspy/utils/parallelizer.py | import contextlib
import copy
import logging
import signal
import sys
import threading
import time
import traceback
from concurrent.futures import FIRST_COMPLETED, ThreadPoolExecutor, wait
import tqdm
logger = logging.getLogger(__name__)
class ParallelExecutor:
def __init__(
self,
num_threads=No... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/magicattr.py | dspy/utils/magicattr.py | """
Compatibility layer for magicattr that works with Python 3.14+
This module provides a patched version of magicattr's functionality
that is compatible with Python 3.14's removal of ast.Num and ast.Str.
Based on magicattr 0.1.6 by Jairus Martin (MIT License)
https://github.com/frmdstryr/magicattr
"""
import ast
imp... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/callback.py | dspy/utils/callback.py | import functools
import inspect
import logging
import uuid
from contextvars import ContextVar
from typing import Any, Callable
import dspy
ACTIVE_CALL_ID = ContextVar("active_call_id", default=None)
logger = logging.getLogger(__name__)
class BaseCallback:
"""A base class for defining callback handlers for DSPy... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/hasher.py | dspy/utils/hasher.py | from pickle import dumps
from typing import Any
import xxhash
"""
The following class was pulled from the `datasets` package from Hugging Face.
The reason for vendoring this code is to avoid a hard dependency on `datasets`,
which is a large package that is not needed for the majority of use cases.
License: Apache Li... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/exceptions.py | dspy/utils/exceptions.py |
from dspy.signatures.signature import Signature
class AdapterParseError(Exception):
"""Exception raised when adapter cannot parse the LM response."""
def __init__(
self,
adapter_name: str,
signature: Signature,
lm_response: str,
message: str | None = None,
par... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/mcp.py | dspy/utils/mcp.py | from typing import TYPE_CHECKING, Any
from dspy.adapters.types.tool import Tool, convert_input_schema_to_tool_args
if TYPE_CHECKING:
import mcp
def _convert_mcp_tool_result(call_tool_result: "mcp.types.CallToolResult") -> str | list[Any]:
from mcp.types import TextContent
text_contents: list[TextConten... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/dummies.py | dspy/utils/dummies.py | import random
from collections import defaultdict
from typing import Any
import numpy as np
from dspy.adapters.chat_adapter import FieldInfoWithName, field_header_pattern
from dspy.clients.lm import LM
from dspy.dsp.utils.utils import dotdict
from dspy.signatures.field import OutputField
from dspy.utils.callback impo... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/inspect_history.py | dspy/utils/inspect_history.py | def _green(text: str, end: str = "\n"):
return "\x1b[32m" + str(text).lstrip() + "\x1b[0m" + end
def _red(text: str, end: str = "\n"):
return "\x1b[31m" + str(text) + "\x1b[0m" + end
def _blue(text: str, end: str = "\n"):
return "\x1b[34m" + str(text) + "\x1b[0m" + end
def pretty_print_history(history... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/__init__.py | dspy/utils/__init__.py | import os
import requests
from dspy.streaming.messages import StatusMessage, StatusMessageProvider
from dspy.utils import exceptions
from dspy.utils.annotation import experimental
from dspy.utils.callback import BaseCallback, with_callbacks
from dspy.utils.dummies import DummyLM, DummyVectorizer, dummy_rm
from dspy.u... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/annotation.py | dspy/utils/annotation.py | import inspect
import re
import types
from typing import Callable, ParamSpec, TypeVar, overload
P = ParamSpec("P")
R = TypeVar("R")
@overload
def experimental(f: Callable[P, R], version: str | None = None) -> Callable[P, R]: ...
@overload
def experimental(f: None = None, version: str | None = None) -> Callable[[Call... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/unbatchify.py | dspy/utils/unbatchify.py | import queue
import threading
import time
from concurrent.futures import Future
from typing import Any, Callable
class Unbatchify:
def __init__(
self,
batch_fn: Callable[[list[Any]], list[Any]],
max_batch_size: int = 32,
max_wait_time: float = 0.1
):
"""
Initial... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/asyncify.py | dspy/utils/asyncify.py | from typing import TYPE_CHECKING, Any, Awaitable, Callable
import asyncer
from anyio import CapacityLimiter
if TYPE_CHECKING:
from dspy.primitives.module import Module
_limiter = None
def get_async_max_workers():
import dspy
return dspy.settings.async_max_workers
def get_limiter():
async_max_wor... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/langchain_tool.py | dspy/utils/langchain_tool.py | from typing import TYPE_CHECKING, Any
from dspy.adapters.types.tool import Tool, convert_input_schema_to_tool_args
if TYPE_CHECKING:
from langchain.tools import BaseTool
def convert_langchain_tool(tool: "BaseTool") -> Tool:
"""Build a DSPy tool from a LangChain tool.
This function converts a LangC... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/caching.py | dspy/utils/caching.py | import os
from pathlib import Path
_DEFAULT_CACHE_DIR = os.path.join(Path.home(), ".dspy_cache")
DSPY_CACHEDIR = os.environ.get("DSPY_CACHEDIR") or _DEFAULT_CACHE_DIR
def create_subdir_in_cachedir(subdir: str) -> str:
"""Create a subdirectory in the DSPy cache directory."""
subdir = os.path.join(DSPY_CACHEDI... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/usage_tracker.py | dspy/utils/usage_tracker.py | """Usage tracking utilities for DSPy."""
from collections import defaultdict
from contextlib import contextmanager
from typing import Any, Generator
from pydantic import BaseModel
from dspy.dsp.utils.settings import settings
class UsageTracker:
"""Tracks LM usage data within a context."""
def __init__(sel... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/utils/saving.py | dspy/utils/saving.py | import logging
import sys
from pathlib import Path
from typing import TYPE_CHECKING
import cloudpickle
import orjson
if TYPE_CHECKING:
from dspy.primitives.module import Module
logger = logging.getLogger(__name__)
def get_dependency_versions():
import dspy
cloudpickle_version = ".".join(cloudpickle.__... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/primitives/module.py | dspy/primitives/module.py | import inspect
import logging
from typing import Any
from dspy.dsp.utils.settings import settings
from dspy.predict.parallel import Parallel
from dspy.primitives.base_module import BaseModule
from dspy.primitives.example import Example
from dspy.primitives.prediction import Prediction
from dspy.utils import magicattr
... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/primitives/prediction.py | dspy/primitives/prediction.py | from dspy.primitives.example import Example
class Prediction(Example):
"""A prediction object that contains the output of a DSPy module.
Prediction inherits from Example.
To allow feedback-augmented scores, Prediction supports comparison operations
(<, >, <=, >=) for Predictions with a `scor... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/primitives/python_interpreter.py | dspy/primitives/python_interpreter.py | import json
import logging
import os
import subprocess
from os import PathLike
from types import TracebackType
from typing import Any
logger = logging.getLogger(__name__)
class InterpreterError(RuntimeError):
pass
class PythonInterpreter:
r"""
PythonInterpreter that runs code in a sandboxed environment ... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/primitives/example.py | dspy/primitives/example.py | from pydantic import BaseModel
class Example:
"""A flexible data container for DSPy examples and training data.
The `Example` class is the standard data format used in DSPy evaluation and optimization.
Key features:
- Dictionary-like access patterns (item access, iteration, etc.)
- Flexi... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/primitives/__init__.py | dspy/primitives/__init__.py | from dspy.primitives.base_module import BaseModule
from dspy.primitives.example import Example
from dspy.primitives.module import Module
from dspy.primitives.prediction import Completions, Prediction
from dspy.primitives.python_interpreter import PythonInterpreter
__all__ = [
"Example",
"BaseModule",
"Pred... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/primitives/base_module.py | dspy/primitives/base_module.py | import copy
import logging
from collections import deque
from collections.abc import Generator
from pathlib import Path
import cloudpickle
import orjson
from dspy.utils.saving import get_dependency_versions
# NOTE: Note: It's important (temporary decision) to maintain named_parameters that's different in behavior fr... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
stanfordnlp/dspy | https://github.com/stanfordnlp/dspy/blob/becb4c9e849a292f71a1f1623acd375aaa32edef/dspy/retrievers/databricks_rm.py | dspy/retrievers/databricks_rm.py | import json
import os
from dataclasses import dataclass
from importlib.util import find_spec
from typing import Any
import requests
import dspy
from dspy.primitives.prediction import Prediction
_databricks_sdk_installed = find_spec("databricks.sdk") is not None
@dataclass
class Document:
page_content: str
... | python | MIT | becb4c9e849a292f71a1f1623acd375aaa32edef | 2026-01-04T14:43:07.742507Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.