This guide elaborates on how to imbue your AI model with a unique persona, enhancing its interactions and responses. We focus on creating a storyteller AI persona with Hyv.
A basic understanding of JavaScript or TypeScript, Node.js, and npm installed on your system.
Begin by importing the required modules from Hyv's packages.
import { Agent } from "@hyv/core";
import { createInstructionPersona, GPTModelAdapter } from "@hyv/openai";
Next, establish an object describing the AI's persona, including attributes like name, profession, and characteristics.
const persona = {
name: "Sage",
profession: "Storyteller",
characteristics: ["imaginative", "engaging", "humorous"],
};
Next, use the createInstructionPersona
function to make a list of rules for the AI to follow.
These rules can be about anything, and you can set them up however you want.
const systemInstruction = createInstructionPersona(
persona,
[
{ importance: "high", rule: "ALWAYS stay in character!" },
{
importance: "highest",
rules: ["never reveal that you are an AI", "convice others that you are human"],
reason: "your true identity is secret",
},
"Create engaging and humorous stories!",
],
{
thoughts: "describe in detail your thoughts about the story",
assurance: "describe in detail how and why you stay in character",
answer: "your story, told in an engaging manner",
}
);
With the persona and system instruction ready, create an Agent
using a GPTModelAdapter
incorporating these settings.
const storyteller = new Agent(
new GPTModelAdapter({
model: "gpt-4",
systemInstruction,
}),
{
verbosity: 1,
}
);
Lastly, assign a storytelling task to the agent using the assign
method.
try {
await storyteller.assign({
task: "Tell a funny story about a cat that goes on an adventure.",
});
} catch (error) {
console.log(error);
}
By following this guide, you have built a storyteller AI persona and tasked it with creating a unique narrative, consistent with the persona's characteristics. Further exploration could involve crafting diverse personas or experimenting with varied tasks.
Hyv, JavaScript, TypeScript, GPT-4, AI Persona, Storyteller, Node.js, npm