Skip to content

Commit 02b148e

Browse files
azai91Alex Zaichenmoneygithub
authored
[docs] Add Google-style docstrings for dspy/adapters/chat_adapter.py ChatAdapter class #9063 (#9072)
* add chat adapter docs * udpate chat adapter docs to not be overly specfic to chat * inherit docs from parent class * update fallback docs * move docs to bottom, add extra args * fix mkdocs issue --------- Co-authored-by: Alex Zai <[email protected]> Co-authored-by: chenmoneygithub <[email protected]>
1 parent f32edbd commit 02b148e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

dspy/adapters/chat_adapter.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616
from dspy.clients.lm import LM
1717
from dspy.signatures.signature import Signature
18+
from dspy.utils.callback import BaseCallback
1819
from dspy.utils.exceptions import AdapterParseError
1920

2021
field_header_pattern = re.compile(r"\[\[ ## (\w+) ## \]\]")
@@ -26,13 +27,33 @@ class FieldInfoWithName(NamedTuple):
2627

2728

2829
class ChatAdapter(Adapter):
30+
"""Default Adapter for most language models.
31+
32+
The ChatAdapter formats DSPy signatures into a format compatible with most language models.
33+
It uses delimiter patterns like `[[ ## field_name ## ]]` to clearly separate input and output fields in
34+
the message content.
35+
36+
Key features:
37+
- Structures inputs and outputs using field header markers for clear field delineation.
38+
- Provides automatic fallback to JSONAdapter if the chat format fails.
39+
"""
40+
2941
def __init__(
3042
self,
31-
callbacks=None,
43+
callbacks: list[BaseCallback] | None = None,
3244
use_native_function_calling: bool = False,
33-
native_response_types=None,
45+
native_response_types: list[type[type]] | None = None,
3446
use_json_adapter_fallback: bool = True,
3547
):
48+
"""
49+
Args:
50+
callbacks: List of callback functions to execute during adapter methods.
51+
use_native_function_calling: Whether to enable native function calling capabilities.
52+
native_response_types: List of output field types handled by native LM features.
53+
use_json_adapter_fallback: Whether to automatically fallback to JSONAdapter if the ChatAdapter fails.
54+
If True, when an error occurs (except ContextWindowExceededError), the adapter will retry using
55+
JSONAdapter. Defaults to True.
56+
"""
3657
super().__init__(
3758
callbacks=callbacks,
3859
use_native_function_calling=use_native_function_calling,

0 commit comments

Comments
 (0)