Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can we switch between prompts (a.k.a personalities)? #22

Open
pooriaarab opened this issue Jul 1, 2023 · 0 comments
Open

How can we switch between prompts (a.k.a personalities)? #22

pooriaarab opened this issue Jul 1, 2023 · 0 comments

Comments

@pooriaarab
Copy link

For example how can we switch between the prompt based on the personality the user wants to select. I used ChatGPT to whip something up - let me know if it's in the right direction or how I can improve it:

Step 1: Define the personalities

// Add the following code snippet inside your index.ts file

const personalities = [
  { name: 'Family', prompt: 'Conversation prompt for family personality' },
  { name: 'Job Interview', prompt: 'Conversation prompt for job interview personality' },
  { name: 'Friend', prompt: 'Conversation prompt for friend personality' },
  { name: 'Travel', prompt: 'Conversation prompt for travel personality' },
];

Step 2: Modify the /start command

// Modify the existing /start command handler in your index.ts file

bot.start((ctx) => {
  const personalityButtons = personalities.map((personality) => ({
    text: personality.name,
    callback_data: `personality:${personality.name}`,
  }));

  ctx.reply("Welcome to my Telegram bot! Please choose a personality:", {
    reply_markup: {
      inline_keyboard: [personalityButtons],
    },
  });
});

Step 3: Handle the /personality command

bot.command("personality", (ctx) => {
  const personalityButtons = personalities.map((personality) => ({
    text: personality.name,
    callback_data: `personality:${personality.name}`,
  }));

  ctx.reply("Choose a new personality:", {
    reply_markup: {
      inline_keyboard: [personalityButtons],
    },
  });
});

Step 4: Modify the message handling logic

// Modify the existing message handler in your index.ts file

bot.on("message", async (ctx) => {
  const text = (ctx.message as any).text;
  const selectedPersonality = getUserSelectedPersonality(ctx.message.chat.id);

  let prompt = '';

  if (selectedPersonality) {
    const selectedPersonalityData = personalities.find(
      (personality) => personality.name === selectedPersonality
    );
    prompt = selectedPersonalityData.prompt;
  }

  // Use the selected personality prompt as part of the input to the AI model
  const input = `${prompt} ${text}`;

  // Call the AI model with the updated input
  const response = await model.call(input);

  // Handle the response based on the selected personality or other conditions
  if (selectedPersonality === 'Family') {
    // Handle family personality-specific behavior
    // ...
  } else if (selectedPersonality === 'Job Interview') {
    // Handle job interview personality-specific behavior
    // ...
  } else {
    // Default behavior for other personalities
    // ...
  }

  // Send the response back to the user
  await ctx.reply(response);
});

Step 5: Implement personality-specific behaviors

// Inside the message handling logic, add conditional statements based on the selected personality

if (selectedPersonality === 'Family') {
  // Handle family personality-specific behavior
  // ...
} else if (selectedPersonality === 'Job Interview') {
  // Handle job interview personality-specific behavior
  // ...
} else {
  // Default behavior for other personalities
  // ...
}

Step 6: Test and iterate
Test your bot and gather user feedback. Based on the feedback, make any necessary adjustments or improvements to the code or behavior of each personality.

Note: You'll need to implement the getUserSelectedPersonality function to retrieve the selected personality for a user from a session or a database.

Please adapt the code to fit your specific implementation, and make sure to handle error cases and edge cases appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant