You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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.
1
+
[Mirascope][mirascope-repo] is a developer tool for building with LLMs. Their library focuses on abstractions that aren't obstructions and integrates with Logfire to make observability and monitoring for LLMs easy and seamless.
2
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).
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, Gemini, Mistral, Groq, and more).
4
4
5
-
```py hl_lines="1 2 5 8"
5
+
```py hl_lines="1 3 5 8"
6
6
import logfire
7
-
from mirascope.logfireimportwith_logfire
8
-
from mirascope.anthropicimportAnthropicCall
7
+
from mirascope.coreimportanthropic, prompt_template
8
+
from mirascope.integrations.logfireimportwith_logfire
9
9
10
10
logfire.configure()
11
11
12
12
13
-
@with_logfire
14
-
classBookRecommender(AnthropicCall):
15
-
prompt_template ="Please recommend some {genre} books"
13
+
@with_logfire()
14
+
@anthropic.call("claude-3-5-sonnet-20240620")
15
+
@prompt_template("Please recommend some {genre} books")
16
+
defrecommend_books(genre: str): ...
16
17
17
-
genre: str
18
18
19
-
20
-
recommender = BookRecommender(genre="fantasy")
21
-
response = recommender.call() # this will automatically get logged with logfire
19
+
response = recommend_books("fantasy") # this will automatically get logged with logfire
22
20
print(response.content)
23
-
#> Here are some recommendations for great fantasy book series: ...
21
+
# > Certainly! Here are some popular and well-regarded fantasy books and series: ...
24
22
```
25
23
26
24
This will give you:
27
25
28
-
* A span around the `AnthropicCall.call()` that captures items like the prompt template, templating properties and fields, and input/output attributes
26
+
* A span around the `recommend_books` that captures items like the prompt template, templating properties and fields, and input/output attributes
29
27
* Human-readable display of the conversation with the agent
30
28
* Details of the response, including the number of tokens used
<figcaption>Mirascope Anthropic Call span and Anthropic span and conversation</figcaption>
32
+
<figcaption>Mirascope Anthropic call span and Anthropic span and conversation</figcaption>
35
33
</figure>
36
34
37
35
Since Mirascope is built 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
36
39
37
This can be particularly useful when [extracting structured information][mirascope-extracting-structured-information] using LLMs:
40
38
41
-
```py hl_lines="3 4 8 17"
39
+
```py hl_lines="3 5 8 17"
42
40
from typing import Literal, Type
43
41
44
42
import logfire
45
-
from mirascope.logfireimportwith_logfire
46
-
from mirascope.openaiimportOpenAIExtractor
43
+
from mirascope.coreimportopenai, prompt_template
44
+
from mirascope.integrations.logfireimportwith_logfire
* A span around the `OpenAIExtractor.extract()` that captures items like the prompt template, templating properties and fields, and input/output attributes
72
+
* A span around the `extract_task_details` that captures items like the prompt template, templating properties and fields, and input/output attributes
82
73
* Human-readable display of the conversation with the agent including the function call
83
74
* Details of the response, including the number of tokens used
84
75
@@ -87,10 +78,12 @@ This will give you:
87
78
<figcaption>Mirascope OpenAI Extractor span and OpenAI span and function call</figcaption>
88
79
</figure>
89
80
90
-
For more information on Mirascope and what you can do with it, check out their [documentation](https://docs.mirascope.io).
81
+
For more information on Mirascope and what you can do with it, check out their [documentation][mirascope-documentation].
0 commit comments