Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add arg parsing for dspy.ReAct #2039

Merged
merged 2 commits into from
Jan 12, 2025
Merged

Conversation

chenmoneygithub
Copy link
Collaborator

Currently we are not parsing the pydantic arg in dspy.ReAct, instead we are just feeding the dict as pydantic arg. This is problematic, see below for a simple reproduce:

from pydantic import BaseModel

import dspy

dspy.settings.configure(lm=dspy.LM("openai/gpt-4o-mini"))


class CalendarEvent(BaseModel):
    name: str
    date: str
    participants: dict[str, str]


def write_invitation_letter(participant_name: str, event_info: CalendarEvent):
    # if isinstance(event_info, dict):
    #     event_info = CalendarEvent.model_validate(event_info)
    if participant_name not in event_info.participants:
        return None
    return f"It's my honor to invite {participant_name} to event {event_info.name} on {event_info.date}"


class InvitationSignature(dspy.Signature):
    participant_name: str = dspy.InputField(desc="The name of the participant to invite")
    event_info: CalendarEvent = dspy.InputField(desc="The information about the event")
    invitation_letter: str = dspy.OutputField(desc="The invitation letter to be sent to the participant")


react = dspy.ReAct(InvitationSignature, tools=[write_invitation_letter])

outputs = react(
    participant_name="Alice",
    event_info=CalendarEvent(
        name="Science Fair",
        date="Friday",
        participants={"Alice": "female", "Bob": "male"},
    ),
)
print(outputs)

It doesn't directly error out because we wrap tool calling by try-except block. But if you look into the outputs.trajectory, it will tell that errors are thrown.

@chenmoneygithub chenmoneygithub requested a review from okhat January 11, 2025 08:14
@okhat okhat merged commit b1ae7af into stanfordnlp:main Jan 12, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants