npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wisegpt/gpt-conversation-prompt

v0.0.11

Published

Types and utility functions to easily generate OpenAI GPT prompts for chatting with the AI.

Downloads

36

Readme

@wisegpt/gpt-conversation-prompt

Types and utility functions to easily generate OpenAI GPT prompts for chatting with the AI.

Example Usage

import { Configuration, OpenAIApi } from "openai";
import { AIPersona, ModelConfiguration, ConversationPromptService } from "@wisegpt/gpt-conversation-prompt";

const aiPersona: AIPersona = {
  name: "WiseGPT",
  instructions: `When providing code examples, use triple backticks.`,
  personality: `You are a software engineer.`,
};

const modelConfiguration: ModelConfiguration = {
  model: "text-davinci-003",
  max_tokens: 1000,
};

const openAIApi = new OpenAIApi(new Configuration({ apiKey: "<<your-secret>>" }));
const conversationPromptService = new ConversationPromptService(openAIApi);

async function exampleUsage() {
  const { text, usage } = await conversationPromptService.completion({
    prompt: {
      conversation: {
        messages: [
          {
            text: "hello",
            author: { type: "USER", id: "user-1" },
          },
          {
            text: "hello, there. how can I help you?",
            author: { type: "BOT" },
          },
          {
            text: "can you write me fibonacci function in a recursive manner in Typescript?",
            author: { type: "USER", id: "user-1" },
          },
        ],
      },
      aiPersona,
    },
    modelConfiguration,
  });

  console.log(JSON.stringify({ text, usage }));
}

Detailed Example Usage

Below is an example usage which includes summary and re-using the summarized conversation to keeping the conversation going and summarizing again.

import { Configuration, OpenAIApi } from "openai";
import { AIPersona, ModelConfiguration, ConversationPromptService, Author, Conversation } from "@wisegpt/gpt-conversation-prompt";

const aiPersona: AIPersona = {
  name: "WiseGPT",
  instructions: `When providing code examples, use triple backticks.`,
  personality: `You are a software engineer.`,
};

const modelConfiguration: ModelConfiguration = {
  model: "text-davinci-003",
  max_tokens: 1000,
};

const openAIApi = new OpenAIApi(new Configuration({ apiKey: "<<your-secret>>" }));
const conversationPromptService = new ConversationPromptService(openAIApi);

async function exampleUsage() {
  const authors: Record<string, Author> = {
    user1: { type: "USER", id: "EU01" },
    user2: { type: "USER", id: "EU02" },
  };

  const conversation1: Conversation = {
    messages: [
      {
        text: "My name is Yigitcan.",
        author: authors.user1,
      },
      {
        text: "My name is Tolga.",
        author: authors.user2,
      },
    ],
  };

  const botResponse1 = await conversationPromptService.completion({
    prompt: { conversation: conversation1, aiPersona },
    modelConfiguration,
  });

  console.log(JSON.stringify({ botResponse1 }));

  // add bots response to the conversation
  conversation1.messages.push({
    text: botResponse1.text,
    author: { type: "BOT" },
  });

  const summaryResponse1 = await conversationPromptService.summary({
    prompt: { conversation: conversation1, aiPersona },
    modelConfiguration,
  });

  console.log(JSON.stringify({ summaryResponse1 }));

  // create a whole new conversation with the summary and a new message
  const conversation2 = {
    summary: summaryResponse1.summary,
    messages: [
      {
        text: "what is my name? and what is the capital of Turkey?",
        author: authors.user1,
      },
    ],
  };

  const botResponse2 = await conversationPromptService.completion({
    prompt: { conversation: conversation2, aiPersona },
    modelConfiguration,
  });

  console.log(JSON.stringify({ botResponse2 }));

  // add bots response to the conversation
  conversation2.messages.push({
    text: botResponse1.text,
    author: { type: "BOT" },
  });

  const summaryResponse2 = await conversationPromptService.summary({
    prompt: { conversation: conversation2, aiPersona },
    modelConfiguration,
  });

  console.log(JSON.stringify({ summaryResponse2 }));
}

exampleUsage().catch((err) => {
  console.error(err);
  process.exit(1);
});