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/storyblok-ai-sdk

v0.0.6

Published

<a href="https://focusreactive.com/" align="center"> <img width="25%" height="auto" src="https://cdn.sanity.io/images/vftxng62/production/25e191578a3c3d4ddfaf69c5f6f7070aead0bff4-507x168.png?auto=format" alt="FocusReactive logo"> </a>

Downloads

11

Readme

StoryBlok AI SDK

🚀 Usage

Install

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

How to use it

Initialisation

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

interface InitSDKProps {
  pluginName: string;
  token: string;
  managementToken: string;
  openAiToken: string;
  spaceId: string;
}

// 2. Initialize the SDK with the OpenAI token
initSDK({
  pluginName: "my-plugin",
  token: YOUR_TOKEN,
  managementToken: YOUR_MANAGEMENT_TOKEN,
  openAiToken: YOUR_OPENAI_TOKEN,
  spaceId: YOUR_SPACE_ID,
});

Documentation

Localization

We implemented localization functions that can be used to translate your stories.

Function localizeStory

Parameters

type TranslationModes = "selected" | "all";
type TranslationLevels = "field" | "folder";

type FolderTranslationData = {
  targetFolderId: number | string;
  translationMode: TranslationModes;
};

interface LocalizeStoryProps {
  targetLanguageCode: string;
  targetLanguageName: string;
  cb: (newStoryData: { story: ISbStoryData }) => void;
  promptModifier?: string;
  translationLevel: TranslationLevels;
  folderLevelTranslation: FolderTranslationData;
}
  • targetLanguage - Language to which you want to translate your story.
  • cb - Callback function that will be called with the result.
  • hasToCreateNewStory - Optional. If you want to create a new story, you can pass true here.
  • promptModifier - Optional. If you want to add some instructions to the prompt, you can pass the modifier here.
  • translationLevel - Can be a field or a folder. When field will perform field-level translation for the current story. When folder, translation will be done at the folder level. Storyblok Internationalization docs.
  • folderLevelTranslation - Data required for folder level translation: targetFolderId and translationMode. Where translationMode can have two options: selected and theall. When using the selected option, only text fields that are explicitly marked as translatable will be processed. Using all will translate all text fields regardless of the translatable flag.

Usage

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

// 2. Call the function
const localizedStory = localizeStory({
  translationLevel,
  targetLanguageCode,
  targetLanguageName,
  folderLevelTranslation,
  cb: (localizedStory) => {
    setIsLoading(false); // turn off the loading indicator
    console.log(localizedStory);
  },
});

Categorisation

We implemented categorisation functions that can be used to categorise documents based on their content.

Function findRelevantTags

Parameters

interface Tag {
  id: string;
  title: string;
}

interface FindRelevantTagsProps {
  contentTitle: string;
  promptModifier?: string;
  cb: (summary: Tag[]) => void;
}
  • contentTitle - Title of the content that we need to process. We use it to set a logical context.
  • promptModifier - Optional. If you want to add some instructions to the prompt, you can pass the modifier here.
  • cb - Callback function that will be called with the result.

Usage

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

// 2. Call the function
findRelevantTags({ contentTitle, cb: (tags) => setTags(tags) });

Function summariseStory

Parameters

interface SummariseStoryProps {
  contentTitle: string;
  promptModifier?: string;
  cb: (summary: string) => void;
}
  • contentTitle - Title of the content that we need to process. We use it to set a logical context.
  • promptModifier - Optional. If you want to add some instructions to the prompt, you can pass the modifier here.
  • cb - Callback function that will be called with the result.

Usage

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

// 2. Call the function
summariseStory({
  contentTitle: "My content title",
  promptModifier:
    "Provided content is a website page. Summary should be short and concise.",
  cb: (summary) => {
    setSummary(summary);
  },
});