Mirascope 빠른 시작 — Model·Prompt·Call·Tools

Mirascope 빠른 시작

설치부터 모델 호출, 프롬프트, 도구까지 한 번에 훑어볼게요. 모델 ID는 "프로바이더/모델명" 형식으로 지정해요.

설치

pip install "mirascope[all]"
# or with uv
uv add "mirascope[all]"

LLM 예제를 돌리려면 선택한 프로바이더의 API 키를 설정해야 해요. 지원 프로바이더 전체 목록과 설정은 Providers에서 확인할 수 있어요.

모델 호출

제일 간단한 방법은 llm.Model이에요. 모델 ID를 "provider/model-name" 형식으로 지정하고 콘텐츠로 호출해요.

from mirascope import llm

model = llm.Model("openai/gpt-4o")
response = model.call("What is the capital of France?")
print(response.text())

프롬프트

@llm.prompt 데코레이터로 재사용 가능한 프롬프트 함수를 만들어요.

from mirascope import llm

@llm.prompt
def recommend_book(genre: str):
    return f"Please recommend a book in {genre}."

response = recommend_book("anthropic/claude-haiku-4-5", "fantasy")
print(response.text())

Call

@llm.call 데코레이터로 모델과 프롬프트 함수를 묶어 편리하게 호출해요.

from mirascope import llm

@llm.call("openai/gpt-4o-mini")
def recommend_book(genre: str) -> str:
    return f"Recommend a {genre} book"

response = recommend_book("fantasy")
print(response.text())

도구 (Tools)

@llm.tool로 도구를 정의하고 call에 넘긴 뒤, 완료될 때까지 루프를 돌며 도구를 실행해요.

import math
from mirascope import llm

@llm.tool
def sqrt_tool(number: float) -> float:
    """Computes the square root of a number"""
    return math.sqrt(number)

@llm.call("openai/gpt-5-mini", tools=[sqrt_tool])
def math_assistant(query: str):
    return query

response = math_assistant("What's the square root of 4242?")
while response.tool_calls:
    tool_outputs = response.execute_tools()
    response = response.resume(tool_outputs)
print(response.text())

더 알아보기