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

ai-fetcher

v0.3.2

Published

A Node.js package that provides integration with popular language models. It is designed to facilitate easy and efficient ai-fetching tasks for your application.

Downloads

173

Readme

ai-fetcher

Test

Overview

ai-fetcher is a Node.js package that provides integration with popular language models. It is designed to facilitate easy and efficient ai-fetching tasks for your application. Currently the package supports Claude and DeepL models, and the supported models/services is keep expanding.

Installation

$ npm install ai-fetcher@latest

Supported AI Services

  • DeepL - Supports both free and pro API keys;
  • Claude - Supports regular text generation for now;
  • OpenAI
    • Chat - Supports chat generation;
    • Text-to-Speech - Convery given texts to audio;

Examples:

DeepL:

import { DeepL } from "ai-fetcher";

// Initialize the DeepL agent with your API key
const deepLAgent = new DeepL(YOUR_DEEPL_API_KEY, true); // Change `true` to `false` if not using Pro API key

// Example tranlation parameters
const translationParams = {
  from: "EN", // Source language code (optional, DeepL can also auto-detect the input language)
  to: "DE", // Target language code
  text: ["Hello world!", "This is a test translation"], // Text(s) to translate
};

// Call the translate method
async function translateText() {
  try {
    const result = await deepLAgent.translate(translationParams);
    console.log(result.translations);
    return result.translations;
  } catch (error) {
    console.error("Translation Error:", error);
  }
}

// Execute the function to translate the text
translateText();

Claude:

import { Claude } from "ai-fetcher";

// Initialize the Claude agent with your API key and preferred model
const claudeAgent = new Claude(YOUR_CLAUDE_API_KEY, "claude-3-haiku-20240307"); // You can also specify the model

// example system prompt and message for generating a response
const systemPrompt = "Write a haiku about the sea.";
const conversationHistory = [
  { role: "user", content: [{ type: "text", text: "Randomly generate 10 words."] } }
];

// Call the generate method
async function generateResponse() {
  try {
    const result = await claudeAgent.generate(
      systemPrompt,
      conversationHistory,
    );
    console.log(result.content);
    return result.content;
  } catch (error) {
    console.error(error);
  }
}

// execute the function and get the generated result
generateResponse();

OpenAI:

Chat Model

import { OpenAI } from "ai-fetcher";

// Initialize the OpenAI chat agent with your API key and preferred model
const openaiChatAgent = OpenAI.chat(YOUR_OPENAI_API_KEY, "gpt-4o-mini");

// Call the generate method
async function generateResponse() {
  try {
    const result = await openaiChatAgent.generate([
      { role: "user", content: "Randomly generate 20 words" },
    ]);
    console.log(result.choices[0].message.content);
  } catch (error) {
    console.error(error);
  }
}

// execute the function and get the generated result
generateResponse();

Text-to-Speech(TTS) Model

import { OpenAI } from "ai-fetcher";

// Initialize the OpenAI tts agent with your API key
const openaiTTSAgent = OpenAI.textToSpeech(YOUR_OPENAI_API_KEY);

async function convertTextToSpeech() {
  try {
    const result = await openaiTTSAgent.convert(
      "Read this text.",
      "filename",
      "speech.mp3",
    );
    console.log(result); // The result is a filename
  } catch (error) {
    console.error(error);
  }
}

// execute the function and get the generated result
convertTextToSpeech();