API Reference¶
This section provides a detailed reference for the dspy-profiles
Python API.
dspy_profiles
¶
dspy-profiles package.
current_profile()
¶
Returns the currently active dspy-profiles
profile.
This utility function provides introspection to see the fully resolved settings
of the profile that is currently active via the profile
context manager
or @with_profile
decorator.
Returns:
Type | Description |
---|---|
ResolvedProfile | None
|
ResolvedProfile | None: The active ResolvedProfile, or None if no profile is active. |
Source code in dspy_profiles/core.py
profile(profile_name=None, *, force=False, config_path=None, **overrides)
¶
A context manager to temporarily apply a dspy-profiles configuration.
This context manager activates a specified profile, configuring dspy.settings
with the language model (LM), retrieval model (RM), and other settings defined
in the profile. It also handles profile precedence and allows for inline overrides.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
profile_name
|
str | None
|
The name of the profile to activate. If not
provided, it falls back to the |
None
|
force
|
bool
|
If True, this profile will override any profile set via
the |
False
|
config_path
|
str | None
|
Path to the |
None
|
**overrides
|
Any
|
Keyword arguments to override profile settings (e.g., |
{}
|
Yields:
Name | Type | Description |
---|---|---|
None |
None
|
The context manager does not yield a value. |
Example
Source code in dspy_profiles/core.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
with_profile(profile_name, *, force=False, config_path=None, **overrides)
¶
A decorator to apply a dspy-profiles configuration to a function or dspy.Module.
This decorator wraps a function or a dspy.Module
class, activating the
specified profile before the decorated object is called.
When applied to a function, it wraps the function directly. When applied to a
class (like a dspy.Module
), it wraps the __call__
method, ensuring the
profile is active during its execution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
profile_name
|
str
|
The name of the profile to activate. |
required |
force
|
bool
|
If True, this profile will override any profile set via
the |
False
|
config_path
|
str | None
|
Path to the |
None
|
**overrides
|
Any
|
Keyword arguments to override profile settings. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Callable |
Callable
|
The decorated function or class. |
Example (Function):
@dspy_profiles.with_profile("testing", temperature=0)
def my_dspy_program(question):
return dspy.Predict("question -> answer")(question=question)
Example (dspy.Module):
@dspy_profiles.with_profile("agent-profile")
class MyAgent(dspy.Module):
def __init__(self):
super().__init__()
self.predict = dspy.Predict("question -> answer")
def __call__(self, question):
return self.predict(question=question)