1from typing import List
2
3from kern.agent import Agent
4from kern.models.dashscope import DashScope
5from pydantic import BaseModel, Field
6
7class MovieScript(BaseModel):
8 name: str = Field(..., description="Give a name to this movie")
9 setting: str = Field(
10 ..., description="Provide a nice setting for a blockbuster movie."
11 )
12 ending: str = Field(
13 ...,
14 description="Ending of the movie. If not available, provide a happy ending.",
15 )
16 genre: str = Field(
17 ...,
18 description="Genre of the movie. If not available, select action, thriller or romantic comedy.",
19 )
20 characters: List[str] = Field(..., description="Name of characters for this movie.")
21 storyline: str = Field(
22 ..., description="3 sentence storyline for the movie. Make it exciting!"
23 )
24
25# Agent that returns a structured output
26structured_output_agent = Agent(
27 model=DashScope(id="qwen-plus"),
28 description="You write movie scripts and return them as structured JSON data.",
29 output_schema=MovieScript,
30)
31
32structured_output_agent.print_response(
33 "Create a movie script about llamas ruling the world. "
34 "Return a JSON object with: name (movie title), setting, ending, genre, "
35 "characters (list of character names), and storyline (3 sentences)."
36)