from typing import List
from agno.agent import Agent, RunResponse # noqa
from agno.models.azure import AzureAIFoundry
from pydantic import BaseModel, Field
from rich.pretty import pprint # noqa
class MovieScript(BaseModel):
setting: str = Field(
..., description="为一部大片提供一个不错的场景。"
)
ending: str = Field(
...,
description="电影的结局。如果不可用,请提供一个快乐的结局。",
)
genre: str = Field(
...,
description="电影的类型。如果不可用,请选择动作片、惊悚片或浪漫喜剧。",
)
name: str = Field(..., description="给这部电影起个名字")
characters: List[str] = Field(..., description="这部电影的角色名称。")
storyline: str = Field(
..., description="电影的 3 句话剧情简介。要精彩!"
)
agent = Agent(
model=AzureAIFoundry(id="Phi-4"),
description="你帮助人们编写电影剧本。",
response_model=MovieScript,
# debug_mode=True,
)
# 在变量中获取响应
# run: RunResponse = agent.run("New York")
# pprint(run.content)
agent.print_response("New York")
创建虚拟环境
打开 Terminal
并创建一个 python 虚拟环境。
python3 -m venv .venv
source .venv/bin/activate
设置你的 API 密钥
export AZURE_API_KEY=xxx
export AZURE_ENDPOINT=xxx
安装库
pip install -U azure-ai-inference agno
运行代理
python cookbook/models/azure/ai_foundry/structured_output.py