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

multi-llm-package

v2.0.0

Published

This package provides interfaces and implementations to interact with Large Language Models (LLMs) such as OpenAI, Claude, and Gemini. It includes tools for generating and streaming text from LLM providers.

Downloads

70

Readme

Multi LLM TS Package

Overview

This package provides interfaces and implementations to interact with Large Language Models (LLMs) such as OpenAI, Claude, and Gemini. It includes tools for generating and streaming text from LLM providers.

Features:

  • Easy integration with OpenAI, Claude, and Gemini providers.
  • Text generation and streaming support.
  • Environment variable management for API keys and configuration.

Installation

  1. Clone the repository:

    git clone https://github.com/hemanthgalam/multi-llm-api-ts
    cd multi-llm-api
  2. Install dependencies:

    npm install
  3. Install dotenv for environment variables:

    npm install dotenv

Usage

  1. Set up environment variables:

    • Create a .env file at the root of your project.
    • Add your API keys and configuration:
    OPENAI_API_KEY=your-openai-api-key
    OPENAI_ENDPOINT=https://api.openai.com/v1/completions
    OPENAI_MODEL=text-davinci-003
    
    CLAUDE_API_KEY=your-claude-api-key
    CLAUDE_ENDPOINT=https://claude.example.com/v1/completions
    CLAUDE_MODEL=claude-2
    
    GEMINI_API_KEY=your-gemini-api-key
    GEMINI_ENDPOINT=https://gemini.example.com/v1/completions
    GEMINI_MODEL=gemini-1
    
// 2. Import the providers in your code:


import { OpenAIProvider } from './src/providers/openai';
import { ClaudeProvider } from './src/providers/claude';
import { GeminiProvider } from './src/providers/gemini';

// 2. Configure and use the providers:

## OpenAIProvider Example:

const openAIConfig = {
  apiKey: process.env.OPENAI_API_KEY,
  endpoint: process.env.OPENAI_ENDPOINT,
  model: process.env.OPENAI_MODEL,
};

const openAIProvider = new OpenAIProvider(openAIConfig);

async function getOpenAIResponse() {
  const response = await openAIProvider.generateText("What is the capital of France?");
  console.log(response.text); // Output: "Paris"
}

async function streamOpenAIResponse() {
  const responseStream = openAIProvider.streamText("Generate large content...");
  for await (const chunk of responseStream) {
    console.log(chunk.text); // Stream large content in chunks
  }
}

## ClaudeProvider Example:

const claudeConfig = {
  apiKey: process.env.CLAUDE_API_KEY,
  endpoint: process.env.CLAUDE_ENDPOINT,
  model: process.env.CLAUDE_MODEL,
};

const claudeProvider = new ClaudeProvider(claudeConfig);

async function getClaudeResponse() {
  const response = await claudeProvider.generateText("What is the capital of Germany?");
  console.log(response.text); // Output: "Berlin"
}

async function streamClaudeResponse() {
  const responseStream = claudeProvider.streamText("Generate content in chunks...");
  for await (const chunk of responseStream) {
    console.log(chunk.text); // Stream large content in chunks
  }
}

## GeminiProvider Example:

const geminiConfig = {
  apiKey: process.env.GEMINI_API_KEY,
  endpoint: process.env.GEMINI_ENDPOINT,
  model: process.env.GEMINI_MODEL,
};

const geminiProvider = new GeminiProvider(geminiConfig);

async function getGeminiResponse() {
  const response = await geminiProvider.generateText("What is the capital of the United States?");
  console.log(response.text); // Output: "New York"
}

async function streamGeminiResponse() {
  const responseStream = geminiProvider.streamText("Generate long-form content...");
  for await (const chunk of responseStream) {
    console.log(chunk.text); // Stream large content in chunks
  }
}

// 3. **Log Request and Response Time (Optional)**:

import { logRequestResponseTime } from './logger';

const startTime = Date.now();
// Perform API request
const endTime = Date.now();

logRequestResponseTime(startTime, endTime, "POST", endpoint, requestPayload, responseData);

Contribution

Contributions are welcome! Feel free to fork the repository, make your changes, and submit a pull request.