Mirascope / mirascope

LLM abstractions that aren't obstructions
https://docs.mirascope.io/
MIT License
665 stars 36 forks source link

[BUG] Not seeing OpenAI-related logs populating in logfire UI #199

Closed barapa closed 4 months ago

barapa commented 4 months ago

In my terminal logs, I see

legaide_api  | 17:34:18.571     Generating extractor
legaide_api  | 17:34:18.576     Calling LLM
legaide_api  | 17:34:18.577     LLMHearingExtractor.extract_async
legaide_api  | 17:34:18.586     Pydantic TempCall validate_python
legaide_api  | 17:34:18.739     Chat Completion with 'gpt-4-turbo'
legaide_api  | 17:34:49.404     Pydantic HearingOverviewExtraction validate_python

So it looks like that I coming from Mirascope. But in the logfire UI, I don't see anything re: OpenAI calls in the span:

Screenshot 2024-04-30 at 1 36 27 PM

Have you seen the OpenAI call details populate in the logfire UI? Not sure if this is a logfire issue or Mirascope yet.

willbakst commented 4 months ago

Hi @barapa! We have seen OpenAI (and other provider calls) populate in the UI (there is a + icon for nested spans, and inside the nested structure is where the OpenAI call is).

Screenshot 2024-04-30 at 10 57 01 AM

I just tested this with the following FastAPI example:

import os
from typing import Type

import logfire
from fastapi import FastAPI
from pydantic import BaseModel

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

os.environ["OPENAI_API_KEY"] = "YOUR_OPENAI_API_KEY"

app = FastAPI()
logfire.configure()
logfire.instrument_fastapi(app)

class Book(BaseModel):
    title: str
    author: str

@with_logfire
class BookRecommender(OpenAIExtractor[Book]):
    extract_schema: Type[Book] = Book
    prompt_template = "Please recommend a {genre} book."

    genre: str

@app.post("/")
async def root(book_recommender: BookRecommender) -> Book:
    """Generates a book based on provided `genre`."""
    return await book_recommender.extract_async()
barapa commented 4 months ago

Ha yes, I didn't see the nested traces! Thank you.

In running an extraction, I don't see the assistant box filled out: Screenshot 2024-04-30 at 2 02 10 PM

Is that your experience when using an extractor as well?

barapa commented 4 months ago

I think this may be because the response is a function call.

barapa commented 4 months ago

OK, this is not a bug. Closing.

willbakst commented 4 months ago

Oh yeah you're totally right, it's due to function calling.

I will look into how we might be able to better support this (although will likely require additional handling with logfire).

I believe they are releasing a customizable UI kit that we could use here, so will circle back when that is released.

For now the function calls should be present in the response data (just not pretty like the messages UI)

willbakst commented 4 months ago

They are officially working on this now :)