The run function is the simplest way to execute AI tasks in Marvin. It provides a clean, one-line interface for running tasks while handling all the complexity of task creation and execution under the hood.
While Marvin provides powerful tools for complex AI workflows, many use cases are simple and don’t need all that complexity. The run function provides:
import marvin# Simple text generationpoem = marvin.run( "Write a haiku about coding", result_type=str)print(poem)# Structured outputfrom pydantic import BaseModelclass Recipe(BaseModel): name: str ingredients: list[str] steps: list[str]recipe = marvin.run( "Create a recipe for chocolate chip cookies", result_type=Recipe)print(recipe.name)print(recipe.ingredients)
Copy
Ask AI
Keys tap in silence,Ideas flow through the night air,Code becomes my art.Chocolate Chip Cookies['1 cup unsalted butter, softened', '1 cup white sugar', '1 cup packed brown sugar', '2 large eggs', '2 teaspoons vanilla extract', '3 cups all-purpose flour', '1 teaspoon baking soda', '1/2 teaspoon baking powder', '1/2 teaspoon salt', '2 cups semisweet chocolate chips']
import marvin# Generate textstory = marvin.run( "Write a short story about a robot learning to paint")print(story)# Answer questionsanswer = marvin.run( "What is the capital of France?", result_type=str)print(answer) # "Paris"
import marvinimport randomdef roll_die() -> int: return random.randint(1, 6)# Let the AI use toolsresult = marvin.run( "Roll a die and tell me if it's higher than 3", result_type=bool, tools=[roll_die])print(result) # True or False depending on the roll
import marvin# Provide additional contextsummary = marvin.run( "Summarize this data in 2-3 sentences", context={ "data": "Long text to summarize...", "style": "technical" })print(summary)