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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pga-ai/adapters-llm-openai

v0.1.0

Published

OpenAI adapter for PGA

Readme

@pga-ai/adapters-llm-openai

OpenAI adapter for PGA (Genomic Self-Evolving Prompts).

Supported Models

  • GPT-4 Turbo (gpt-4-turbo-preview)
  • GPT-4 (gpt-4)
  • GPT-3.5 Turbo (gpt-3.5-turbo)

Features

  • ✅ Full LLMAdapter interface implementation
  • ✅ Streaming responses support
  • ✅ Token usage tracking
  • ✅ Configurable temperature and top_p
  • ✅ Support for custom base URLs (proxies, Azure)
  • ✅ Organization ID support

Installation

npm install @pga-ai/adapters-llm-openai

Usage

Basic Usage

import { OpenAIAdapter } from '@pga-ai/adapters-llm-openai';

const adapter = new OpenAIAdapter({
  apiKey: process.env.OPENAI_API_KEY!,
  model: 'gpt-4-turbo-preview',
});

// Chat
const response = await adapter.chat([
  { role: 'user', content: 'Hello, GPT-4!' }
]);

console.log(response.content);

Streaming Responses

const adapter = new OpenAIAdapter({
  apiKey: process.env.OPENAI_API_KEY!,
  model: 'gpt-4',
});

for await (const chunk of adapter.chatStream([
  { role: 'user', content: 'Tell me a story' }
])) {
  process.stdout.write(chunk.content);
}

With PGA Genome

import { PGA } from '@pga-ai/core';
import { OpenAIAdapter } from '@pga-ai/adapters-llm-openai';
import { PostgresAdapter } from '@pga-ai/adapters-storage-postgres';

const pga = new PGA({
  llmAdapter: new OpenAIAdapter({
    apiKey: process.env.OPENAI_API_KEY!,
    model: 'gpt-4-turbo-preview',
    temperature: 0.7,
  }),
  storageAdapter: new PostgresAdapter({
    connectionString: process.env.DATABASE_URL!,
  }),
});

const genome = await pga.createGenome({
  layer0: {
    systemPrompt: 'You are a helpful AI assistant.',
    constraints: ['Be concise', 'Use examples'],
    capabilities: ['coding', 'debugging'],
  },
});

const response = await genome.chat('Help me debug this code', {
  userId: 'user-123',
});

Configuration

interface OpenAIAdapterConfig {
  /** OpenAI API Key (required) */
  apiKey: string;

  /** Model to use (default: 'gpt-4-turbo-preview') */
  model?: string;

  /** Organization ID (optional) */
  organization?: string;

  /** Base URL for proxies or Azure (optional) */
  baseURL?: string;

  /** Temperature 0-2 (default: 1.0) */
  temperature?: number;

  /** Top P 0-1 (default: 1.0) */
  topP?: number;
}

Available Models

| Model | ID | Context | Best For | |-------|-----|---------|----------| | GPT-4 Turbo | gpt-4-turbo-preview | 128K | Complex tasks, latest features | | GPT-4 | gpt-4 | 8K | High-quality responses | | GPT-3.5 Turbo | gpt-3.5-turbo | 16K | Fast, cost-effective |

Environment Variables

# Required
OPENAI_API_KEY=sk-...

# Optional
OPENAI_ORGANIZATION=org-...
OPENAI_BASE_URL=https://api.openai.com/v1

Error Handling

try {
  const response = await adapter.chat(messages);
} catch (error) {
  if (error.status === 401) {
    console.error('Invalid API key');
  } else if (error.status === 429) {
    console.error('Rate limit exceeded');
  } else if (error.status === 500) {
    console.error('OpenAI server error');
  }
}

Token Usage

const response = await adapter.chat(messages);

console.log('Usage:', {
  prompt: response.usage.promptTokens,
  completion: response.usage.completionTokens,
  total: response.usage.totalTokens,
});

Advanced Configuration

Custom Base URL (Azure OpenAI)

const adapter = new OpenAIAdapter({
  apiKey: process.env.AZURE_OPENAI_KEY!,
  baseURL: 'https://your-resource.openai.azure.com',
  model: 'gpt-4',
});

Per-Request Options

const response = await adapter.chat(messages, {
  temperature: 0.5,
  topP: 0.9,
  maxTokens: 2000,
});

Comparison with Claude

| Feature | OpenAI (GPT-4) | Claude (Opus/Sonnet) | |---------|----------------|----------------------| | Context Window | 128K (Turbo) | 200K | | Streaming | ✅ | ✅ | | Function Calling | ✅ | ✅ (Tool Use) | | Vision | ✅ | ✅ | | Speed | Fast | Very Fast (Sonnet) | | Cost | Medium | Varies |

License

MIT

Author

Luis Alfredo Velasquez Duran (Germany, 2025)

Links