Mirascope
Mirascopeは、LLMsを使用してAIドライバーアプリケーションを構築するための直感的な方法です。彼らのライブラリはLogfireと統合されており、LLMsの観測可能性と監視を簡単かつシームレスにします。
@with_logire デコレータを使用して有効にすることができます。これは、サポートされているすべてのモデルプロバイダー(Open AI、Anthropic、Groqなど)で機能します。
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: ...
これは与える:
- は、
AnthropicCall.call()のスパンを中心に、ヒントテンプレート、テンプレート属性とフィールド、入出力属性などのアイテムをキャプチャします - エージェントとの会話の人間の読み取り可能な表示
- 使用されたトークンの数を含む応答の詳細
MirascopeはPydantic上に構築されているため、Pydanticプラグインを使用して、モデル検証に関する追加のログとメトリックを追跡できます。[pydantic_plugin ][logfire.configure(pydantic_plugin)]構成を使用して有効にできます。
これは、LLMsを使用して構造化情報を抽出する場合に特に役立ちます。
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'
これは与える:
- Pydanticモデル検証の追跡
- 周りに
OpenAIExtractor.extract()のスパンで、ヒントテンプレート、テンプレートの属性とフィールド、入力/出力属性などのアイテムをキャプチャします - 関数呼び出しを含むエージェントとの対話の人間が読み取り可能な表示
- 使用されたトークンの数を含む応答の詳細
Mirascope Open AI抽出器スパンとOpen AIスパンおよび関数呼び出し
Mirascopeとそれを使用してできることの詳細については、そのドキュメントを参照してください。
本文总阅读量次