From a6afc123480320538017d4e9b0b7e3387d222fbe Mon Sep 17 00:00:00 2001 From: Shroominic Date: Fri, 10 Nov 2023 14:01:00 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20startup=20generator=20feature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/async.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/examples/async.py b/examples/async.py index 9237932..9db0c45 100644 --- a/examples/async.py +++ b/examples/async.py @@ -1,23 +1,35 @@ -from funcchain import chain +import asyncio +from funcchain import achain, settings +from langchain.pydantic_v1 import BaseModel +settings.MODEL_TEMPERATURE = 1 -def random_city() -> str: - """ - Tell me a random city, i need this for a game. - """ - return chain() +class StartupConcept(BaseModel): + name: str + description: str + -async def random_city_async() -> str: +async def startup_generator(topic: str) -> StartupConcept: """ - Tell me a random city, i need this for a game. + Generate a random startup for the given topic. """ - return await chain() + return await achain() -if __name__ == "__main__": - print(random_city()) +async def generate_random_startups(topic: str, amount: int = 3) -> list[StartupConcept]: + return await asyncio.gather( + *[ + startup_generator(topic) + for _ in range(amount) + ] + ) - from asyncio import run +if __name__ == "__main__": + topic = "AI generated Vegan Recipes" + + startups = asyncio.run(generate_random_startups(topic)) - print(run(random_city_async())) + for startup in startups: + print("name:", startup.name) + print("concept:", startup.description)