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

Adding Mirascope Third Party Integration Docs Page #98

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions docs/integrations/third_party/mirascope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Mirascope

[Mirascope](https://github.com/Mirascope/mirascope) is an intuitive approach to building AI-powered applications using LLMs. Their library is the first third party integration with Logfire to make observability and monitoring for LLMs easy and seamless.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the "first third party integration" part.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


You can enable it using their [`@with_logire`](https://docs.mirascope.io/latest/integrations/logfire/#how-to-use-logfire-with-mirascope) decorator, which will work with all of the [model providers that they support](https://docs.mirascope.io/latest/concepts/supported_llm_providers/) (e.g. OpenAI, Anthropic, Groq, and more).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We link third party dependencies with mkdocstrings - Do you want to do that, or do you prefer like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this out of habit. Updated to use mkdocstrings instead (like I did for the pydantic links already)


```py hl_lines="1 2 5 8"
import logfire
from mirascope.logfire import with_logfire
from mirascope.anthropic import AnthropicCall

logfire.configure()


@with_logfire
class BookRecommender(AnthropicCall):
prompt_template = "Please recommend some {genre} books"

genre: str


recommender = BookRecommender(genre="fantasy")
response = recommender.call() # this will automatically get logged with logfire
print(response.content)
#> Here are some recommendations for great fantasy book series: ...
```

This will give you:

* A span around the `AnthropicCall.call()` that captures items like the prompt template, templating properties and fields, and input/output attributes.
* Human-readable display of the conversation with the agent
* Details of the response, including the number of tokens used

<figure markdown="span">
![Logfire Mirascope Anthropic call](../../images/logfire-screenshot-mirascope-anthropic-call.png){ width="500" }
<figcaption>Mirascope Anthropic Call span and Anthropic span and conversation</figcaption>
</figure>

Since Mirascope is build on top of [Pydantic][pydantic], you can use the [Pydantic plugin][pydantic-plugin] to track additional logs and metrics about model validation, which you can enable using the [`pydantic_plugin`][logfire.configure(pydantic_plugin)] configuration.

This can be particularly useful when [extracting structured information](https://docs.mirascope.io/latest/concepts/extracting_structured_information_using_llms/) using LLMs:

```py hl_lines="3 4 8 17"
from typing import Literal, Type

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

logfire.configure(pydantic_plugin=logfire.PydanticPlugin(record="all"))


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)
#> description='Submit quarterly report' due_date='next Friday' priority='high'
```

For more information on Mirascope and what you can do with it, check out their [documentation](https://docs.mirascope.io)

[pydantic]: https://docs.pydantic.dev/latest/
[pydantic-plugin]: https://docs.pydantic.dev/latest/concepts/plugins/
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ nav:
- Logging: integrations/logging.md
- Structlog: integrations/structlog.md
- Loguru: integrations/loguru.md
- Third Party:
- Mirascope: integrations/third_party/mirascope.md
- Use Cases:
- Web Frameworks: integrations/use_cases/web_frameworks.md
- Reference:
Expand Down