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

tunerkit

v1.0.4

Published

Tunerkit Node SDK: E2E development of AI Agents

Downloads

12

Readme

Tunerkit

Tunerkit is a powerful Node.js SDK for end-to-end development of AI agents. It provides tools for logging, monitoring, and simulating runs through your code, making it easier to develop, debug, and optimize your AI applications.

Features

  • Easy integration with existing AI clients
  • Logging and monitoring of API calls
  • Simulation of API responses for development and testing
  • Flexible configuration options
  • Integration with Helicone for advanced logging and analytics

Installation

Install Tunerkit using npm:

npm install tunerkit

Setup

To use Tunerkit, you'll need to set up a client with your Tunerkit API key. Here's a basic setup:

import { TunerkitClient } from 'tunerkit';
import OpenAI from 'openai';

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

const tunerkitClient = new TunerkitClient({
  client: openai,
  tunerkitApiKey: 'your-tunerkit-api-key',
});

Usage

Basic Usage

Once set up, you can use the tunerkitClient just like you would use your original client:

tunerkitClient.setSession({
  sessionId: 'unique-session-id',
  sessionName: 'My Chat Session',
});

const response = await tunerkitClient.chat.completions.create({
  model: "gpt-3.5-turbo",
  messages: [{ role: "user", content: "Hello, how are you?" }],
});

console.log(response.choices[0].message.content);

Using the Tool Decorator

Tunerkit provides a tool decorator for integrating Tunerkit functionality into your existing functions. Here's an example:

import { TunerkitClient } from 'tunerkit';
import axios from 'axios';

const tunerkitClient = new TunerkitClient({
  client: {},
  tunerkitApiKey: 'your-tunerkit-api-key',
});

@tunerkitClient.tool()
async function fetchWebContent(url: string): Promise<string> {
  const response = await axios.get(url);
  return response.data;
}

// Usage
async function main() {
  tunerkitClient.setSession({
    sessionId: 'unique-fetch-session-id',
    sessionName: 'Web Content Fetch',
  });

  try {
    const html = await fetchWebContent('https://example.com');
    console.log('Fetched HTML:', html.substring(0, 100) + '...');
  } catch (error) {
    console.error('Error fetching web content:', error);
  }
}

main();

Development Mode with Tool Decorator

To use development mode with the tool decorator:

@tunerkitClient.tool({ dev: true })
async function fetchWebContent(url: string): Promise<string> {
  // ... function implementation ...
}

Changing Sessions

To change the session during runtime:

tunerkitClient.setSession({
  sessionId: 'another-unique-id',
  sessionName: 'Another Task',
});

// Subsequent calls will use this new session

Logging with Helicone

To use Helicone logging:

import { HeliconeLogger } from 'tunerkit';

const heliconeLogger = new HeliconeLogger('your-helicone-api-key', 'https://api.hconeai.com');

const tunerkitClient = new TunerkitClient({
  client: openai,
  tunerkitApiKey: 'your-tunerkit-api-key',
  logger: heliconeLogger,
});

Setting Up Simulations

To set up simulations of your AI workflows:

  1. Host your AI workflow:
import express from 'express';
import { registerWorkflowCall } from 'tunerkit';

const app = express();

app.use(express.json());

app.post('/ai-workflow', async (req, res) => {
  const { ...params } = req.body;

  await registerWorkflowCall(req);

  // Your AI workflow logic here
  const result = await runAIWorkflow(params);

  res.json(result);
});

app.listen(3000, () => console.log('AI workflow server running on port 3000'));
  1. Register your webhook in your dataset at app.tunerkit.dev.

  2. Run simulations from Tunerkit:

Once you've hosted your AI workflow and registered the webhook, you can run simulations directly from the Tunerkit platform:

  • Log in to your Tunerkit account at app.tunerkit.dev
  • Navigate to your registered dataset
  • Select the workflow you want to simulate
  • Click on the "Run Simulation" button
  • Configure any necessary parameters for your simulation
  • Start the simulation and observe the results in real-time

Tunerkit will send requests to your hosted AI workflow, allowing you to test and refine your AI application without incurring costs from actual API calls.

API Reference

TunerkitClient

Constructor

new TunerkitClient({
  client: T,
  tunerkitApiKey: string,
  logger?: TunerkitLogger
})

Methods

  • setSession(options: { sessionId: string, sessionName: string }): void
  • tool(options?: { dev?: boolean }): MethodDecorator

Tunerkit also proxies all methods of the original client, adding logging and development mode capabilities.

HeliconeLogger

Constructor

new HeliconeLogger(heliconeApiKey: string, baseURL: string)

Best Practices

  1. Always use setSession to manage session information.
  2. Use descriptive session names to easily identify different parts of your application.
  3. Leverage development mode for testing and debugging without making actual API calls.
  4. Implement proper error handling for both Tunerkit and your AI client operations.

Contributing

We welcome contributions to Tunerkit! Please see our Contributing Guide for more details.

License

Tunerkit is released under the MIT License.

Support

For support, please open an issue on our GitHub repository or contact our support team at [email protected].