Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/api/primitives/Tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- description
- extract_custom_type_from_annotation
- format
- format_as_litellm_function_call
- format_as_litellm_tool_definition
- from_langchain
- from_mcp_tool
- is_streamable
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/primitives/ToolCalls.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
- description
- extract_custom_type_from_annotation
- format
- from_dict_list
- is_streamable
- parse_lm_response
- parse_stream_chunk
Expand Down
13 changes: 2 additions & 11 deletions dspy/adapters/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import logging
from typing import Any, get_origin

import json_repair

from dspy.adapters.types import History, Type
from dspy.adapters.types.base_type import split_message_content_for_custom_types
from dspy.adapters.types.reasoning import Reasoning
Expand Down Expand Up @@ -85,7 +83,7 @@ def _call_preprocess(
tools = inputs[tool_call_input_field_name]
tools = tools if isinstance(tools, list) else [tools]

lm_tools = [tool.format_as_litellm_function_call() for tool in tools]
lm_tools = [tool.format_as_litellm_tool_definition(model_type=lm.model_type) for tool in tools]

lm_kwargs["tools"] = lm_tools

Expand Down Expand Up @@ -148,14 +146,7 @@ def _call_postprocess(
)

if tool_calls and tool_call_output_field_name:
tool_calls = [
{
"name": v["function"]["name"],
"args": json_repair.loads(v["function"]["arguments"]),
}
for v in tool_calls
]
value[tool_call_output_field_name] = ToolCalls.from_dict_list(tool_calls)
value[tool_call_output_field_name] = ToolCalls(tool_calls=list(tool_calls))

# Parse custom types that does not rely on the `Adapter.parse()` method
for name, field in original_signature.output_fields.items():
Expand Down
11 changes: 1 addition & 10 deletions dspy/adapters/two_step_adapter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Any

import json_repair

from dspy.adapters.base import Adapter
from dspy.adapters.chat_adapter import ChatAdapter
from dspy.adapters.types import ToolCalls
Expand Down Expand Up @@ -145,14 +143,7 @@ async def acall(
raise ValueError(f"Failed to parse response from the original completion: {output}") from e

if tool_calls and tool_call_output_field_name:
tool_calls = [
{
"name": v["function"]["name"],
"args": json_repair.loads(v["function"]["arguments"]),
}
for v in tool_calls
]
value[tool_call_output_field_name] = ToolCalls.from_dict_list(tool_calls)
value[tool_call_output_field_name] = ToolCalls(tool_calls=list(tool_calls))

if output_logprobs is not None:
value["logprobs"] = output_logprobs
Expand Down
5 changes: 2 additions & 3 deletions dspy/adapters/types/base_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import json_repair
import pydantic

from dspy.clients.base_lm import BaseLM

if TYPE_CHECKING:
from litellm import ModelResponseStream

from dspy.clients.base_lm import BaseLM
from dspy.signatures.signature import Signature

CUSTOM_TYPE_START_IDENTIFIER = "<<CUSTOM-TYPE-START-IDENTIFIER>>"
Expand Down Expand Up @@ -81,7 +80,7 @@ def adapt_to_native_lm_feature(
cls,
signature: type["Signature"],
field_name: str,
lm: BaseLM,
lm: "BaseLM",
lm_kwargs: dict[str, Any],
) -> type["Signature"]:
"""Adapt the custom type to the native LM feature if possible.
Expand Down
Loading