Skip to content

Commit 254b3c6

Browse files
KludexWilliam Bakst
andauthored
Add third party Mirascope integration docs page (#133)
Co-authored-by: William Bakst <william@mirascope.io>
1 parent 87e8a2a commit 254b3c6

File tree

5 files changed

+117
-2
lines changed

5 files changed

+117
-2
lines changed
651 KB
Loading
540 KB
Loading
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
[Mirascope](https://github.com/Mirascope/mirascope) is an intuitive approach to building AI-powered applications using LLMs. Their library integrates with Logfire to make observability and monitoring for LLMs easy and seamless.
2+
3+
You can enable it using their [`@with_logire`][mirascope-logfire] decorator, which will work with all of the [model providers that they support][mirascope-supported-providers] (e.g. OpenAI, Anthropic, Groq, and more).
4+
5+
```py hl_lines="1 2 5 8"
6+
import logfire
7+
from mirascope.logfire import with_logfire
8+
from mirascope.anthropic import AnthropicCall
9+
10+
logfire.configure()
11+
12+
13+
@with_logfire
14+
class BookRecommender(AnthropicCall):
15+
prompt_template = "Please recommend some {genre} books"
16+
17+
genre: str
18+
19+
20+
recommender = BookRecommender(genre="fantasy")
21+
response = recommender.call() # this will automatically get logged with logfire
22+
print(response.content)
23+
#> Here are some recommendations for great fantasy book series: ...
24+
```
25+
26+
This will give you:
27+
28+
* A span around the `AnthropicCall.call()` that captures items like the prompt template, templating properties and fields, and input/output attributes.
29+
* Human-readable display of the conversation with the agent
30+
* Details of the response, including the number of tokens used
31+
32+
<figure markdown="span">
33+
![Logfire Mirascope Anthropic call](../../images/logfire-screenshot-mirascope-anthropic-call.png){ width="500" }
34+
<figcaption>Mirascope Anthropic Call span and Anthropic span and conversation</figcaption>
35+
</figure>
36+
37+
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.
38+
39+
This can be particularly useful when [extracting structured information][mirascope-extracting-structured-information] using LLMs:
40+
41+
```py hl_lines="3 4 8 17"
42+
from typing import Literal, Type
43+
44+
import logfire
45+
from mirascope.logfire import with_logfire
46+
from mirascope.openai import OpenAIExtractor
47+
from pydantic import BaseModel
48+
49+
logfire.configure(pydantic_plugin=logfire.PydanticPlugin(record="all"))
50+
51+
52+
class TaskDetails(BaseModel):
53+
description: str
54+
due_date: str
55+
priority: Literal["low", "normal", "high"]
56+
57+
58+
@with_logfire
59+
class TaskExtractor(OpenAIExtractor[TaskDetails]):
60+
extract_schema: Type[TaskDetails] = TaskDetails
61+
prompt_template = """
62+
Extract the task details from the following task:
63+
{task}
64+
"""
65+
66+
task: str
67+
68+
69+
task = "Submit quarterly report by next Friday. Task is high priority."
70+
task_details = TaskExtractor(
71+
task=task
72+
).extract() # this will be logged automatically with logfire
73+
assert isinstance(task_details, TaskDetails)
74+
print(task_details)
75+
#> description='Submit quarterly report' due_date='next Friday' priority='high'
76+
```
77+
78+
This will give you:
79+
80+
* Tracking for validation of Pydantic models.
81+
* A span around the `OpenAIExtractor.extract()` that captures items like the prompt template, templating properties and fields, and input/output attributes.
82+
* Human-readable display of the conversation with the agent including the function call
83+
* Details of the response, including the number of tokens used
84+
85+
<figure markdown="span">
86+
![Logfire Mirascope Anthropic call](../../images/logfire-screenshot-mirascope-openai-extractor.png){ width="500" }
87+
<figcaption>Mirascope OpenAI Extractor span and OpenAI span and function call</figcaption>
88+
</figure>
89+
90+
For more information on Mirascope and what you can do with it, check out their [documentation](https://docs.mirascope.io)
91+
92+
[mirascope-logfire]: https://docs.mirascope.io/latest/integrations/logfire/#how-to-use-logfire-with-mirascope
93+
[mirascope-supported-providers]: https://docs.mirascope.io/latest/concepts/supported_llm_providers/
94+
[mirascope-extracting-structured-information]: https://docs.mirascope.io/latest/concepts/extracting_structured_information_using_llms/
95+
[pydantic]: https://docs.pydantic.dev/latest/
96+
[pydantic-plugin]: https://docs.pydantic.dev/latest/concepts/plugins/

docs/plugins/main.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def on_page_markdown(markdown: str, page: Page, config: Config, files: Files) ->
2020
markdown = build_environment_variables_table(markdown, page)
2121
markdown = logfire_print_help(markdown, page)
2222
markdown = install_logfire(markdown, page)
23-
if page.file.src_uri == 'guides/onboarding_checklist/06_add_metrics.md':
24-
check_documented_system_metrics(markdown, page)
23+
markdown = check_documented_system_metrics(markdown, page)
24+
markdown = warning_on_third_party(markdown, page)
2525
return markdown
2626

2727

@@ -36,6 +36,9 @@ def check_documented_system_metrics(markdown: str, page: Page) -> str:
3636
3737
This function checks that all the metrics in `DEFAULT_CONFIG` are documented.
3838
"""
39+
if page.file.src_uri != 'guides/onboarding_checklist/06_add_metrics.md':
40+
return markdown
41+
3942
metrics_documented: set[str] = set()
4043
for line in markdown.splitlines():
4144
match = re.search(r'\* `(.*)`: ', line)
@@ -134,3 +137,17 @@ def install_logfire(markdown: str, page: Page) -> str:
134137
```
135138
"""
136139
return re.sub(r'{{ *install_logfire\(.*\) *}}', instructions, markdown)
140+
141+
142+
def warning_on_third_party(markdown: str, page: Page) -> str:
143+
if not page.file.src_uri.startswith('integrations/third_party/'):
144+
return markdown
145+
146+
note = """
147+
!!! note "Third-party integrations"
148+
Third-party integrations are not officially supported by **Logfire**.
149+
150+
They are maintained by the community and may not be as reliable as the integrations developed by **Logfire**.
151+
"""
152+
153+
return note + markdown

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ nav:
117117
- Logging: integrations/logging.md
118118
- Structlog: integrations/structlog.md
119119
- Loguru: integrations/loguru.md
120+
- Third Party:
121+
- Mirascope: integrations/third_party/mirascope.md
120122
- Use Cases:
121123
- Web Frameworks: integrations/use_cases/web_frameworks.md
122124
- Reference:

0 commit comments

Comments
 (0)