dspy.ToolCalls¶
dspy.ToolCalls
¶
Bases: Type
Functions¶
description() -> str
classmethod
¶
extract_custom_type_from_annotation(annotation)
classmethod
¶
Extract all custom types from the annotation.
This is used to extract all custom types from the annotation of a field, while the annotation can
have arbitrary level of nesting. For example, we detect Tool
is in list[dict[str, Tool]]
.
Source code in dspy/adapters/types/base_type.py
format() -> list[dict[str, Any]]
¶
from_dict_list(tool_calls_dicts: list[dict[str, Any]]) -> ToolCalls
classmethod
¶
Convert a list of dictionaries to a ToolCalls instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dict_list
|
A list of dictionaries, where each dictionary should have 'name' and 'args' keys. |
required |
Returns:
Type | Description |
---|---|
ToolCalls
|
A ToolCalls instance. |
Example:
```python
tool_calls_dict = [
{"name": "search", "args": {"query": "hello"}},
{"name": "translate", "args": {"text": "world"}}
]
tool_calls = ToolCalls.from_dict_list(tool_calls_dict)
```
Source code in dspy/adapters/types/tool.py
is_streamable() -> bool
classmethod
¶
parse_lm_response(response: str | dict[str, Any]) -> Optional[Type]
classmethod
¶
Parse a LM response into the custom type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response
|
str | dict[str, Any]
|
A LM response. |
required |
Returns:
Type | Description |
---|---|
Optional[Type]
|
A custom type object. |
parse_stream_chunk(chunk: ModelResponseStream) -> Optional[Type]
classmethod
¶
Parse a stream chunk into the custom type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chunk
|
ModelResponseStream
|
A stream chunk. |
required |
Returns:
Type | Description |
---|---|
Optional[Type]
|
A custom type object or None if the chunk is not for this custom type. |
Source code in dspy/adapters/types/base_type.py
serialize_model()
¶
Source code in dspy/adapters/types/base_type.py
validate_input(data: Any)
classmethod
¶
Source code in dspy/adapters/types/tool.py
:::