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

Simplify creation of few-shot chatprompts with function calls #354

Open
jackmpcollins opened this issue Oct 20, 2024 · 0 comments
Open

Simplify creation of few-shot chatprompts with function calls #354

jackmpcollins opened this issue Oct 20, 2024 · 0 comments

Comments

@jackmpcollins
Copy link
Owner

The same FunctionCall must be used in AssistantMessage and FunctionResultMessage for them to have the same tool_call_id. The current syntax for doing this could be cleaned up to avoid creating the awkward FunctionCall instance(s) above the chatprompt-function.

Example from the docs https://magentic.dev/chat-prompting/#functionresultmessage

def plus(a: int, b: int) -> int:
    return a + b


plus_1_2 = FunctionCall(plus, 1, 2)


@chatprompt(
    UserMessage("Use the plus function to add 1 and 2."),
    AssistantMessage(plus_1_2),
    FunctionResultMessage(3, plus_1_2),
    UserMessage("Now add 4 to the result."),
    functions=[plus],
)
def do_math() -> FunctionCall[int]: ...

ideally could more like (moving the creation of the FunctionCall inside)

def plus(a: int, b: int) -> int:
    return a + b


@chatprompt(
    UserMessage("Use the plus function to add 1 and 2."),
    *assistant_function_call_and_result(3, plus, 1, 2),
    UserMessage("Now add 4 to the result."),
    functions=[plus],
)
def do_math() -> FunctionCall[int]: ...

Also need to consider ParallelFunctionCall, and possibly future tools too.

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

No branches or pull requests

1 participant