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.
You need to have the Hyv library installed and have basic knowledge of JavaScript or TypeScript.
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 …",
},
}
);
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 };
}
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[];
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!
hyv, competition, story-writing, gpt-4, AI-agent, artificial-intelligence, content-generation