Skip to content

Latest commit

 

History

History
107 lines (89 loc) · 3.4 KB

07_a_LET_AI_AGENTS_COMPETE_GENERATED_CONTENT.md

File metadata and controls

107 lines (89 loc) · 3.4 KB

Implementing a Hyv-based Story Writing Competition

Overview

This guide outlines the steps to set up a story writing competition using Hyv, where each entry is generated by a unique author AI agent. We'll show you how to create instructions for the competitors, a helper function to produce entries, and a method to generate competition entries.

Prerequisites

You need to have the Hyv library installed and have basic knowledge of JavaScript or TypeScript.

Guide

Setting Competition Instructions

The initial step is to outline the instructions for the authors (competitors) utilizing the createInstruction function. These instructions set the expectations for each author's task.

const authorInstruction = createInstruction(
    "Author, Competitor",
    minify`
    Do tasks. Respect rules and rating criteria.
    Think deeply, reason your thoughts, decide based on your reasoning.
    `,
    {
        thoughts: "deep thoughts",
        reason: "critical reasoning",
        decision: "detailed decision",
        story: {
            name: "name of story",
            content: "the story …",
        },
    }
);

Creating a Helper Function

Next, we need to prepare a helper function that creates agents and assigns a task. This function will come in handy later when generating multiple entries for the competition.

async function createAndAssign<T>(
    task: ModelMessage,
    systemInstruction: string,
    options: AgentOptions = {}
) {
    return (await new Agent(
        new GPTModelAdapter({
            model: "gpt-4",
            maxTokens: 1024,
            temperature: 0.9,
            systemInstruction,
        }),
        {
            verbosity: 1,
            ...options,
        }
    ).assign(task)) as { id: string; message: ModelMessage & T };
}

Generating Competition Entries

The final step is to use the createAndAssign function to create multiple entries for the competition. Each entry is generated by an author AI agent that follows the authorInstruction to write a unique story. The after method is used to add a word count to each story, aiding jurors in the next steps.

const stories = (await Promise.all(
    Array.from(
        { length: 3 },
        async () =>
            (
                await createAndAssign(
                    { task: "Write a UNIQUE story for a competition", rules, ratingCriteria },
                    authorInstruction,
                    {
                        async after(message) {
                            return {
                                ...message,
                                story: {
                                    ...message.story,
                                    wordCount: getWordCount(message.story.content),
                                },
                            };
                        },
                    }
                )
            ).message.story
    )
)) as FileContentWithPath[];

Summary

In this guide, we walked you through the process of setting up a story writing competition using the Hyv library. We discussed how to establish instructions for competitors, create a helper function for agent creation, and generate competition entries. By following this guide, you should now be able to host your own AI-powered writing competition!

Tags

hyv, competition, story-writing, gpt-4, AI-agent, artificial-intelligence, content-generation