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

@focus-reactive/content-ai-sdk

v0.0.4

Published

An easy way to enchance your project with ready to use GPT functions

Downloads

148

Readme

Content AI SDK

🚀 Usage

Install

yarn add @focus-reactive/content-ai-sdk

How to use it

Initialisation

// 1. Import the configration function
import { initSDK } from "@focus-reactive/content-ai-sdk";

// 2. Initialize the SDK with the OpenAI token
initSDK({ openAiToken: OPEN_AI_TOKEN });

Documentation

Translations

We implemented several features that you can use in your projects to work with localisations.

Function translate

Parameters

interface TranslateOptions {
  targetLanguage: string;
  content: string;
  currentLanguage?: string;
  promptModifier?: string;
}
  • targetLanguage string - Result language
  • content string - Text content that should be translated to the target language.
  • currentLanguage string - Current language of the content. If not provided, the language will be detected automatically.
  • promptModifier string - Can be used to modify prompt.

Usage

// 1. Import the function
import { translate } from "@focus-reactive/content-ai-sdk";

// 2. Call the function
const deContent = await translate({
  content: "Hey! Now I can manage german content",
  targetLanguage: "german",
});

Function translateJSON

This function is created to translate JSON objects to a different language without changing it's structure.

Parameters

interface TranslateOptions {
  targetLanguage: string;
  content: object;
  promptModifier?: string;
  currentLanguage?: string;
}
  • targetLanguage - Result language
  • content - Text content that should be translated to the target language (JSON).
  • promptModifier - Can be used to modify prompt. In some cases you may need to not translate some values or exlude some fields.
  • currentLanguage - Current language of the content. If not provided, the language will be detected automatically.

Usage

// 1. Import the function
import { translateJSON } from "@focus-reactive/content-ai-sdk";

// 2. Call the function
const deContent = await translateJSON({
  content: JSON.stringify({
    title: "Batman 2",
    description: "Superhero movie",
  }),
  targetLanguage: "german",
  promptModifier:
    "Do not translate technical fields, they starts with a _ symbol. Translate only values with more than 1 word.",
});

Summarisation

Function summariseContent

This function is created to be able to create a sammury of a content. Works with string and JSON objects.

Parameters

interface SummariseContentProps {
  content: unknown;
  contentTitle: string;
  promptModifier?: string;
}
  • contentTitle - Content title. This is a required field that sets the logical context for the provided content.
  • content JSON | string - Text content that will be summarised. (JSON | string)
  • promptModifier - Can be used to modify prompt.

Usage

// 1. Import the function
import { summariseContent } from "@focus-reactive/content-ai-sdk";

// 2. Call the function
const summary = await summariseContent({
  contentTitle: "Batman movie overview.",
  content: JSON.stringify({
    title: "Batman",
    description: "Superhero movie",
  }),
  promptModifier: "Make sure that the summary is not longer than 3 sentences.",
});

Categotisation

Function applyTags

This function is created to logically tag content. Returns tags on order of relevance.

Parameters

interface Tag {
  id: string | number;
  title: string;
  description?: string;
}

interface AppplyTagsProps {
  content: unknown;
  contentTitle: string;
  promptModifier?: string;
  resultAmount?: number;
  tags: Tag[];
}
  • contentTitle- Content title. Sets the logical context for the provided content.
  • content - Text contentf for tagging. (JSON | string)
  • promptModifier - Can be used to modify prompt.
  • resultAmount - Amount of tags that should be returned.
  • tags - Array of tags that should be used for tagging.

Usage

// 1. Import the function
import { applyTags } from "@focus-reactive/content-ai-sdk";

// 2. Call the function
const tags = await applyTags({
  contentTitle: "Batman movie overview.",
  content: JSON.stringify({
    title: "Batman",
    description: "Superhero movie",
  }),
  tags: [] as Tag[],
  resultAmount: 5,
  promptModifier: "Make sure that the summary is not longer than 3 sentences.",
});