From fdc00e8d9f96324596898a0068f37a79c4470cd7 Mon Sep 17 00:00:00 2001 From: geekan Date: Tue, 20 Feb 2024 15:34:47 +0800 Subject: [PATCH] fix example --- examples/write_novel.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/write_novel.py b/examples/write_novel.py index b272a56e6..03daf1f0c 100644 --- a/examples/write_novel.py +++ b/examples/write_novel.py @@ -33,14 +33,25 @@ class Chapter(BaseModel): content: str = Field(default="...", description="The content of the chapter. No more than 1000 words.") +class Chapters(BaseModel): + chapters: List[Chapter] = Field( + default=[ + {"name": "Chapter 1", "content": "..."}, + {"name": "Chapter 2", "content": "..."}, + {"name": "Chapter 3", "content": "..."}, + ], + description="The chapters of the novel.", + ) + + async def generate_novel(): instruction = ( - "Write a novel named 'Harry Potter in The Lord of the Rings'. " + "Write a novel named 'Reborn in Skyrim'. " "Fill the empty nodes with your own ideas. Be creative! Use your own words!" "I will tip you $100,000 if you write a good novel." ) novel_node = await ActionNode.from_pydantic(Novel).fill(context=instruction, llm=LLM()) - chap_node = await ActionNode.from_pydantic(Chapter).fill( + chap_node = await ActionNode.from_pydantic(Chapters).fill( context=f"### instruction\n{instruction}\n### novel\n{novel_node.content}", llm=LLM() ) print(chap_node.content)