1515)
1616from dspy .clients .lm import LM
1717from dspy .signatures .signature import Signature
18+ from dspy .utils .callback import BaseCallback
1819from dspy .utils .exceptions import AdapterParseError
1920
2021field_header_pattern = re .compile (r"\[\[ ## (\w+) ## \]\]" )
@@ -26,13 +27,33 @@ class FieldInfoWithName(NamedTuple):
2627
2728
2829class 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