> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 结构化输出

## 代码

```python cookbook/models/vllm/structured_output.py theme={null}
from typing import List

from agno.agent import Agent
from agno.models.vllm import vLLM
from pydantic import BaseModel, Field


class MovieScript(BaseModel):
    name: str = Field(..., description="为这部电影起个名字")
    setting: str = Field(
        ..., description="为一部大片提供一个精彩的场景。"
    )
    ending: str = Field(
        ...,
        description="电影结局。如果不可用，请提供一个圆满的结局。",
    )
    genre: str = Field(
        ...,
        description="电影类型。如果不可用，请选择动作、惊悚或浪漫喜剧。",
    )
    characters: List[str] = Field(..., description="这部电影的角色名字。")
    storyline: str = Field(
        ..., description="电影的3句话故事梗概。要令人兴奋！"
    )


agent = Agent(
    model=vLLM(
        id="NousResearch/Nous-Hermes-2-Mistral-7B-DPO", top_k=20, enable_thinking=False
    ),
    description="你负责写电影剧本。",
    response_model=MovieScript,
)

agent.print_response("Llamas ruling the world")
```

## 用法

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="安装库">
    ```bash theme={null}
    pip install -U agno pydantic vllm openai
    ```
  </Step>

  <Step title="启动 vLLM 服务器">
    ```bash theme={null}
    vllm serve NousResearch/Nous-Hermes-2-Mistral-7B-DPO \
        --enable-auto-tool-choice \
        --tool-call-parser hermes \
        --dtype float16 \
        --max-model-len 8192 \
        --gpu-memory-utilization 0.9
    ```
  </Step>

  <Step title="运行 Agent">
    ```bash theme={null}
    python cookbook/models/vllm/structured_output.py
    ```
  </Step>
</Steps>
