jackmpcollins / magentic

Seamlessly integrate LLMs as Python functions
https://magentic.dev/
MIT License
2k stars 96 forks source link

logfire not logging the response #359

Open rawwerks opened 3 days ago

rawwerks commented 3 days ago

i'm following along with https://magentic.dev/logging-and-tracing/ , but i don't think logfire.instrument_openai() is fully implemented correctly, because i cannot see the response in logfire.

example:

import os
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()

import logfire

logfire.configure()
logfire.instrument_openai()  # optional, to trace OpenAI API calls  
logfire.info('Hello, {name}!', name='world')

from magentic import prompt
from pydantic import BaseModel

class Superhero(BaseModel):
    name: str
    age: int
    power: str
    enemies: list[str]

@prompt("Create a Superhero named {name}.")
def create_superhero(name: str) -> Superhero: ...

create_superhero("Monkey Boy")

result: CleanShot 2024-10-22 at 07 27 34@2x

jackmpcollins commented 7 hours ago

@rawwerks You're right! Tool call responses (used for structure outputs in magentic) show correctly in logfire for non-streamed responses, but not when stream=True. I've opened an issue with logfire now https://github.com/pydantic/logfire/issues/542