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

llm-logger

v0.0.4

Published

LLM Logger is a TypeScript/JavaScript library that allows you to easily log your AI API calls to [LLM Logger](https://llmlogger.com/). This package provides direct support for OpenAI, Claude, and Gemini, but you can use it with any LLM by structuring the

Downloads

2

Readme

LLM Logger

LLM Logger is a TypeScript/JavaScript library that allows you to easily log your AI API calls to LLM Logger. This package provides direct support for OpenAI, Claude, and Gemini, but you can use it with any LLM by structuring the output yourself.

Installation

To install the llm-logger package, run the following command:

npm install llm-logger

or if you're using yarn:

yarn add llm-logger

Setup

First, import the LLMLogger class from the package:

import { LLMLogger } from 'llm-logger';

Then, create an instance of LLMLogger with your API key:

const logger = new LLMLogger({ apiKey: 'your-api-key-here' });

Usage

OpenAI

To log OpenAI API calls, send the completion object directly as it's returned by the openai library to LLM Logger:

import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: 'your-openai-api-key',
});

const messages = [{ role: 'user', content: 'Hello, how are you?' }]
const completion = await openai.chat.completions.create({
  model: 'gpt-4o-mini',
  messages,
});

await logger.openaiLog(messages, chatCompletion, ['openai-example'], null);

Claude (Anthropic)

To log Claude API calls:

import Anthropic from '@anthropic-ai/sdk';

const anthropic = new Anthropic({
  apiKey: 'your-anthropic-api-key',
});

const system = 'You are a helpful assistant';
const messages = [{ role: 'user', content: 'Hello, how are you?' }];
const completion = await anthropic.messages.create({
  model: 'claude-3-haiku-20240307',
  system,
  messages,
  max_tokens: 4096,
});

await logger.claudeLog(messages, system, completion, ['claude-example'], null);

Gemini (Google)

To log Gemini API calls:

import { GoogleGenerativeAI } from '@google/generative-ai';

const model = 'gemini-1.5-flash-latest';
const genAI = new GoogleGenerativeAI('your-google-api-key');
const geminiModel = genAI.getGenerativeModel({ model });

const messages = [{ role: 'user', content: 'Hello, how are you?' }];
const result = await geminiModel.generateContent(messages[0].content);
const response = result.response;

await logger.geminiLog(messages, model, geminiResponse, ['gemini-example'], null);

Benefits

Using LLM Logger allows you to:

  1. Keep track of all your AI API calls in one place.
  2. Analyze usage patterns and optimize your API usage.
  3. Debug and improve your AI-powered applications more effectively.

For more information and advanced usage, visit LLM Logger.