JSPM

  • Created
  • Published
  • Downloads 84
  • Score
    100M100P100Q61260F
  • License MIT

A service hub for AI services

Package Exports

  • ai-service-hub
  • ai-service-hub/dist/index.js
  • ai-service-hub/dist/index.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ai-service-hub) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

AI Service Hub

npm version License: MIT TypeScript

A unified TypeScript library for interacting with multiple AI services through a single, consistent interface.

Features

  • πŸš€ Single API - Access multiple AI services through one consistent interface
  • πŸ”Œ Multiple Providers - Support for OpenAI, Claude, Groq, Gemini, DeepSeek, Perplexity, Ollama, and LM Studio
  • πŸ–ΌοΈ Vision Support - Process images with AI models that support vision capabilities
  • πŸ“Š Embeddings - Generate embeddings for semantic search and similarity applications
  • πŸ”„ Auto-Detection - Automatically select the appropriate service based on the model
  • πŸ’¬ Chat Interfaces - Easy-to-use chat completion APIs with system prompts
  • πŸ“ Format Flexibility - Support for text and JSON response formats

Installation

npm install ai-service-hub

Supported Services

Service Chat Vision Embeddings Description
OpenAI βœ… βœ… βœ… GPT-4o, GPT-4.5-Preview, O1, etc.
Claude βœ… βœ… ❌ Claude 3.7, 3.5 Sonnet & Haiku, Opus
Groq βœ… βœ… βœ… Grok-2, Grok-2-Vision, Grok-Beta
Gemini βœ… ❌ βœ… Gemini 2.5, 2.0, 1.5, and Imagen 3.0
DeepSeek βœ… ❌ ❌ DeepSeek Chat, Reasoner
Perplexity βœ… ❌ ❌ Sonar models, R1-1776
Ollama βœ… βœ… βœ… Self-hosted open source models
LM Studio βœ… βœ… βœ… Self-hosted Hugging Face models

Current Model Support

OpenAI Models

  • GPT-4.5 Preview
  • GPT-4o Mini
  • GPT-4o
  • GPT-3.5 Turbo
  • GPT-4
  • GPT-4 Turbo
  • GPT-4 Turbo Preview
  • GPT-4 Vision Preview
  • O1
  • O1 Mini
  • O1 Preview
  • O3 Mini
  • ChatGPT-4o Latest
  • ChatGPT-4o Mini

Claude Models

  • Claude 3.7 Sonnet Latest
  • Claude 3.5 Haiku Latest
  • Claude 3.5 Sonnet Latest
  • Claude 3.5 Sonnet (20240620)
  • Claude 3 Opus Latest
  • Claude 3 Sonnet (20240229)
  • Claude 3 Haiku (20240307)

Gemini Models

  • Gemini 2.5 Pro Experimental (03/25)
  • Gemini 2.0 Flash
  • Gemini 2.0 Flash Lite
  • Gemini 1.5 Flash
  • Gemini 1.5 Flash 8B
  • Gemini 1.5 Pro
  • Gemini Embedding Experimental
  • Imagen 3.0 Generate 002

DeepSeek Models

  • DeepSeek Chat
  • DeepSeek Reasoner

Perplexity Models

  • Sonar Deep Research
  • Sonar Reasoning Pro
  • Sonar Reasoning
  • Sonar Pro
  • Sonar
  • R1-1776

Basic Usage

import { GlobalInstance, ModelOpenAi } from 'ai-service-hub';

// Initialize with your API keys
const ai = new GlobalInstance({
  openAiKey: 'your-openai-key',
  claudeKey: 'your-claude-key',
  grokKey: 'your-groq-key',
  // Add other service keys as needed
});

// Basic chat completion
async function getCompletion() {
  const response = await ai.chat({
    prompt: "What's the capital of France?",
    model: ModelOpenAi.gpt4o,
    systemPrompt: "You are a helpful assistant."
  });
  
  console.log(response);
}

Examples

OpenAI Chat

import { OpenAiInstance, ModelOpenAi } from 'ai-service-hub';

const openai = new OpenAiInstance('your-api-key');

const response = await openai.chat(
  "Explain quantum computing in simple terms", 
  "You are a helpful assistant", 
  ModelOpenAi.gpt4o
);

Claude Chat

import { ClaudeInstance, ModelClaude } from 'ai-service-hub';

const claude = new ClaudeInstance('your-api-key');

const response = await claude.chat(
  "Write a short story about a robot learning to paint", 
  "You are a creative writer", 
  ModelClaude.claude37SonnetLatest
);

Vision API (OpenAI)

import { OpenAiInstance, ModelOpenAIVision } from 'ai-service-hub';

const openai = new OpenAiInstance('your-api-key');

// Convert your image to base64 first
const response = await openai.vision(
  "What's in this image?", 
  base64Image, 
  "Describe the image in detail",
  ModelOpenAIVision.gpt4o
);

Embeddings (OpenAI)

import { OpenAiInstance, ModelOpenAiEmbedding } from 'ai-service-hub';

const openai = new OpenAiInstance('your-api-key');

const embedding = await openai.embedding(
  "This is a sample text to embed", 
  ModelOpenAiEmbedding.textEmbedding3Large
);

Using Global Instance

import { GlobalInstance, ModelOpenAi, ModelClaude } from 'ai-service-hub';

const ai = new GlobalInstance({
  openAiKey: 'your-openai-key',
  claudeKey: 'your-claude-key'
});

// OpenAI will be automatically selected based on the model
const openaiResponse = await ai.chat({
  prompt: "Explain how rainbows form",
  model: ModelOpenAi.gpt4o
});

// Claude will be automatically selected based on the model
const claudeResponse = await ai.chat({
  prompt: "Write a poem about autumn",
  model: ModelClaude.claude37SonnetLatest
});

Configuration

Each service requires different configuration parameters:

const globalInstance = new GlobalInstance({
  openAiKey: 'your-openai-key',
  claudeKey: 'your-anthropic-key',
  grokKey: 'your-groq-key',
  geminiKey: 'your-gemini-key',
  deepSeekKey: 'your-deepseek-key',
  perplexityKey: 'your-perplexity-key',
  ollamaUrl: 'http://localhost:11434',
  lmstudioUrl: 'http://localhost:1234'
});

Recent Updates

  • Updated to support newest models including Claude 3.7 Sonnet and Gemini 2.5
  • Added comprehensive model definitions for all providers
  • Added Claude AI integration with chat and vision capabilities
  • Converted all enums to modern TypeScript object literals
  • Added ESLint and Prettier for code quality
  • Enhanced vision capabilities across multiple providers
  • Improved type safety throughout the codebase

License

MIT

Author

BartΕ‚omiej Zimny