{"id":30046717,"url":"https://github.com/sidharth-e/unify-llm","last_synced_at":"2025-08-07T08:53:40.967Z","repository":{"id":308165904,"uuid":"1031855973","full_name":"Sidharth-e/unify-llm","owner":"Sidharth-e","description":"A unified TypeScript SDK for interacting with multiple Large Language Model providers including OpenAI and Google Gemini. This SDK provides a consistent interface across different providers, making it easy to switch between models or implement fallback strategies.","archived":false,"fork":false,"pushed_at":"2025-08-04T12:51:16.000Z","size":79,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-04T16:56:34.178Z","etag":null,"topics":["npm-package","sdk-javascript","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sidharth-e.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-04T12:39:27.000Z","updated_at":"2025-08-04T12:56:28.000Z","dependencies_parsed_at":"2025-08-04T17:10:45.096Z","dependency_job_id":null,"html_url":"https://github.com/Sidharth-e/unify-llm","commit_stats":null,"previous_names":["sidharth-e/unify"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Sidharth-e/unify-llm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sidharth-e%2Funify-llm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sidharth-e%2Funify-llm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sidharth-e%2Funify-llm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sidharth-e%2Funify-llm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sidharth-e","download_url":"https://codeload.github.com/Sidharth-e/unify-llm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sidharth-e%2Funify-llm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269227923,"owners_count":24381839,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-07T02:00:09.698Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["npm-package","sdk-javascript","typescript"],"created_at":"2025-08-07T08:53:35.348Z","updated_at":"2025-08-07T08:53:40.902Z","avatar_url":"https://github.com/Sidharth-e.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unify LLM\n\nA unified TypeScript SDK for interacting with multiple Large Language Model providers including OpenAI and Google Gemini. This SDK provides a consistent interface across different providers, making it easy to switch between models or implement fallback strategies.\n\n## Features\n\n- 🚀 **Unified Interface**: Single API for both OpenAI and Gemini models\n- 🔄 **Automatic Provider Detection**: Automatically detects the appropriate provider based on model name\n- 📡 **Streaming Support**: Real-time streaming responses for both providers\n- 🛡️ **Error Handling**: Robust error handling with retry mechanisms\n- 🔧 **Flexible Configuration**: Customizable timeouts, retries, and provider settings\n- 📊 **Model Information**: Easy access to model capabilities and limits\n- 🎯 **TypeScript Support**: Full TypeScript support with comprehensive type definitions\n- 🆕 **Latest Gemini SDK**: Updated to use the latest `@google/genai` SDK with Gemini 2.0 models\n\n## Installation\n\n```bash\nnpm install unify-llm\n```\n\n## Quick Start\n\n```typescript\nimport { UnifyLLM } from 'unify-llm';\n\n// Initialize with your API keys\nconst unify = new UnifyLLM({\n  openai: {\n    apiKey: process.env.OPENAI_API_KEY!,\n  },\n  gemini: {\n    apiKey: process.env.GEMINI_API_KEY!,\n  },\n  defaultProvider: 'openai',\n});\n\n// Simple chat completion\nconst response = await unify.chatCompletion({\n  messages: [\n    { role: 'user', content: 'Hello! How are you?' }\n  ],\n});\n\nconsole.log(response.choices[0].message.content);\n```\n\n## Configuration\n\n### Basic Configuration\n\n```typescript\nconst unify = new UnifyLLM({\n  openai: {\n    apiKey: 'your-openai-api-key',\n  },\n  gemini: {\n    apiKey: 'your-gemini-api-key',\n  },\n  defaultProvider: 'openai', // or 'gemini'\n  defaultModel: 'gpt-3.5-turbo', // or 'gemini-2.0-flash-001'\n});\n```\n\n### Advanced Configuration\n\n```typescript\nconst unify = new UnifyLLM({\n  openai: {\n    apiKey: 'your-openai-api-key',\n    baseUrl: 'https://api.openai.com/v1', // Optional custom base URL\n    timeout: 60000, // 60 seconds\n    maxRetries: 3,\n  },\n  gemini: {\n    apiKey: 'your-gemini-api-key',\n    timeout: 45000, // 45 seconds\n    maxRetries: 2,\n  },\n  defaultProvider: 'openai',\n  defaultModel: 'gpt-4',\n});\n```\n\n## API Reference\n\n### Chat Completion\n\n#### Basic Usage\n\n```typescript\nconst response = await unify.chatCompletion({\n  messages: [\n    { role: 'user', content: 'What is the capital of France?' }\n  ],\n});\n```\n\n#### With Custom Parameters\n\n```typescript\nconst response = await unify.chatCompletion({\n  messages: [\n    { role: 'system', content: 'You are a helpful assistant.' },\n    { role: 'user', content: 'Explain quantum computing.' }\n  ],\n  model: 'gpt-4', // or 'gemini-2.0-flash-001'\n  temperature: 0.7,\n  maxTokens: 1000,\n  topP: 0.9,\n  frequencyPenalty: 0.1,\n  presencePenalty: 0.1,\n});\n```\n\n### Streaming\n\n```typescript\nawait unify.streamChatCompletion(\n  {\n    messages: [\n      { role: 'user', content: 'Write a story about a robot.' }\n    ],\n    model: 'gpt-3.5-turbo',\n  },\n  (chunk) =\u003e {\n    const content = chunk.choices[0]?.delta?.content;\n    if (content) {\n      process.stdout.write(content);\n    }\n  }\n);\n```\n\n### Model Management\n\n#### List Available Models\n\n```typescript\n// List all models from all providers\nconst allModels = await unify.listModels();\n\n// List models from a specific provider\nconst openaiModels = await unify.listModels('openai');\nconst geminiModels = await unify.listModels('gemini');\n```\n\n#### Get Model Information\n\n```typescript\nconst modelInfo = await unify.getModelInfo('gpt-4');\nif (modelInfo) {\n  console.log('Model:', modelInfo.name);\n  console.log('Provider:', modelInfo.provider);\n  console.log('Max Tokens:', modelInfo.maxTokens);\n  console.log('Supports Streaming:', modelInfo.supportsStreaming);\n}\n```\n\n### Provider Management\n\n```typescript\n// Check if a provider is configured\nconst hasOpenAI = unify.isProviderConfigured('openai');\nconst hasGemini = unify.isProviderConfigured('gemini');\n\n// Get a specific provider instance\nconst openaiProvider = unify.getProvider('openai');\nconst geminiProvider = unify.getProvider('gemini');\n```\n\n## Supported Models\n\n### OpenAI Models\n- `gpt-4`\n- `gpt-4-32k`\n- `gpt-4-turbo`\n- `gpt-4-turbo-preview`\n- `gpt-3.5-turbo`\n- `gpt-3.5-turbo-16k`\n\n### Gemini Models\n- `gemini-pro`\n- `gemini-pro-vision`\n- `gemini-1.5-pro`\n- `gemini-1.5-flash`\n\n## Error Handling\n\nThe SDK includes robust error handling with automatic retries and exponential backoff:\n\n```typescript\ntry {\n  const response = await unify.chatCompletion({\n    messages: [{ role: 'user', content: 'Hello!' }],\n  });\n} catch (error) {\n  if (error.message.includes('rate limit')) {\n    console.log('Rate limit exceeded, retrying...');\n  } else if (error.message.includes('authentication')) {\n    console.log('Invalid API key');\n  } else {\n    console.log('Unexpected error:', error.message);\n  }\n}\n```\n\n## Advanced Usage Examples\n\n### Multi-turn Conversations\n\n```typescript\nconst conversation = [\n  { role: 'system', content: 'You are a helpful coding assistant.' },\n  { role: 'user', content: 'What is TypeScript?' },\n];\n\nlet response = await unify.chatCompletion({ messages: conversation });\nconversation.push(response.choices[0].message);\nconversation.push({ role: 'user', content: 'How does it compare to JavaScript?' });\n\nresponse = await unify.chatCompletion({ messages: conversation });\n```\n\n### Provider Fallback Strategy\n\n```typescript\nasync function getResponseWithFallback(prompt: string) {\n  try {\n    // Try GPT-4 first\n    return await unify.chatCompletion({\n      messages: [{ role: 'user', content: prompt }],\n      model: 'gpt-4',\n    });\n  } catch (error) {\n    console.log('GPT-4 failed, trying Gemini...');\n    // Fallback to Gemini\n    return await unify.chatCompletion({\n      messages: [{ role: 'user', content: prompt }],\n      model: 'gemini-2.0-flash-001',\n    });\n  }\n}\n```\n\n### Available Gemini Models\n\nThe SDK now supports the latest Gemini models including:\n\n- **gemini-2.0-flash-001**: Latest Gemini 2.0 Flash model (1M tokens)\n- **gemini-2.0-flash-exp**: Experimental Gemini 2.0 Flash model\n- **gemini-1.5-pro**: Gemini 1.5 Pro model (1M tokens)\n- **gemini-1.5-flash**: Gemini 1.5 Flash model (1M tokens)\n- **gemini-pro**: Original Gemini Pro model (32K tokens)\n- **gemini-pro-vision**: Gemini Pro Vision model (32K tokens)\n\n```typescript\n// Use the latest Gemini 2.0 model\nconst response = await unify.chatCompletion({\n  messages: [{ role: 'user', content: 'Explain quantum computing' }],\n  model: 'gemini-2.0-flash-001',\n  maxTokens: 1000,\n});\n```\n\n### Batch Processing\n\n```typescript\nconst questions = [\n  'What is machine learning?',\n  'Explain neural networks',\n  'What is deep learning?',\n];\n\nconst results = await Promise.all(\n  questions.map(question =\u003e\n    unify.chatCompletion({\n      messages: [{ role: 'user', content: question }],\n      model: 'gpt-3.5-turbo',\n    })\n  )\n);\n```\n\n## TypeScript Types\n\nThe SDK provides comprehensive TypeScript types:\n\n```typescript\nimport type {\n  Message,\n  ChatCompletionRequest,\n  ChatCompletionResponse,\n  ModelInfo,\n  UnifyConfig,\n  ModelProvider,\n} from 'unify-llm';\n\n// Use types in your code\nconst messages: Message[] = [\n  { role: 'user', content: 'Hello!' }\n];\n\nconst config: UnifyConfig = {\n  openai: { apiKey: 'your-key' },\n  defaultProvider: 'openai',\n};\n```\n\n## Development\n\n### Building from Source\n\n```bash\ngit clone \u003crepository-url\u003e\ncd unify-llm\nnpm install\nnpm run build\n```\n\n### Running Tests\n\n```bash\nnpm test\n```\n\n### Running Examples\n\n```bash\n# Set your API keys\nexport OPENAI_API_KEY=\"your-openai-key\"\nexport GEMINI_API_KEY=\"your-gemini-key\"\n\n# Run basic example\nnpx ts-node examples/basic-usage.ts\n\n# Run advanced example\nnpx ts-node examples/advanced-usage.ts\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests for new functionality\n5. Submit a pull request\n\n## License\n\nMIT License - see LICENSE file for details.\n\n## Support\n\nFor issues and questions, please open an issue on GitHub or contact the maintainers. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidharth-e%2Funify-llm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsidharth-e%2Funify-llm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidharth-e%2Funify-llm/lists"}