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

Feature Request: Handle Tool Call Assistant Messages For OpenAI (and other providers) #54

Closed
willbakst opened this issue Apr 30, 2024 · 2 comments
Assignees
Labels
OpenAI OpenAI instrumentation related

Comments

@willbakst
Copy link
Contributor

Hi! I noticed when using tool calls (function calling) that I get an empty assistant message in the UI (because there's no content, just tool calls). See below:

April 30 Screenshot from Pydantic Logfire

Would be awesome if this rendered something like a pretty JSON object so it's not empty and I don't have to scroll down to the original response to find the data.

@Kludex
Copy link
Member

Kludex commented May 6, 2024

@willbakst Do you have a code snippet for me to reproduce this?

@Kludex Kludex self-assigned this May 6, 2024
@willbakst
Copy link
Contributor Author

I've confirmed this is working with OpenAI (as well as other providers through Mirascope).

Here is a Mirascope snippet that works with Logfire and the new function calling UI:

from typing import Literal, Type

import logfire
from pydantic import BaseModel

from mirascope.logfire import with_logfire
from mirascope.openai import OpenAIExtractor

logfire.configure()


class TaskDetails(BaseModel):
    description: str
    due_date: str
    priority: Literal["low", "normal", "high"]


@with_logfire
class TaskExtractor(OpenAIExtractor[TaskDetails]):
    extract_schema: Type[TaskDetails] = TaskDetails
    prompt_template = """
    Extract the task details from the following task:
    {task}
    """

    task: str


task = "Submit quarterly report by next Friday. Task is high priority."
task_details = TaskExtractor(
    task=task
).extract()  # this will be logged automatically with logfire
assert isinstance(task_details, TaskDetails)
print(task_details)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OpenAI OpenAI instrumentation related
Projects
None yet
Development

No branches or pull requests

2 participants