The FinetuneDB Node.js SDK serves as a drop-in replacement for the OpenAI SDK, preserving full compatibility while capturing all requests and responses, including streaming responses.

By logging your requests, you can build a comprehensive dataset for fine-tuning, gain deeper insights into model performance, and conduct thorough evaluations. This data-driven approach enables seamless transitions to custom models tailored to your specific use cases.

Installation

npm install --save finetunedb
# or
yarn add finetunedb

Usage

  1. Create a workspace at https://app.finetunedb.com
  2. Generate an API key from the workspace settings
  3. Find the project ID you want to log to
  4. Configure the FinetuneDB client as shown below
// import OpenAI from 'openai'
import OpenAI from "finetunedb/openai";

// Fully compatible with original OpenAI initialization
const openai = new OpenAI({
  apiKey: "your api key", // defaults to process.env["OPENAI_API_KEY"]
  // Optional: Step 1 - Initialize FinetuneDB to enable logging
  finetunedb: {
    apiKey: "your api key", // defaults to process.env["FINETUNEDB_API_KEY"]
  },
});

async function main() {
  // Allows optional finetunedb object
  const completion = await openai.chat.completions.create({
    messages: [{ role: "user", content: "Hello world!" }],
    model: "gpt-3.5-turbo",
    // Optional: Step 2 - Log a chat completion
    finetunedb: {
      // Define the project ID
      projectId: "cloio7t90000...",
      // Enable/disable data collection. Defaults to true.
      logRequest: true,
      // Optional: Add custom searchable tags
      tags: ["test-prompt"],
    },
  });

  // Optional: Update log
  await completion.finetunedb.updateLastLog({
    tags: ["test-prompt", "new-tag"],
  });
}

main();

FAQ

What is the difference between the apiKey and the projectId?

The apiKey is shared across a workspace, while each project within that workspace has a unique projectId. This structure allows you to:

  • Organize multiple projects under one workspace
  • Use different fine-tuned models for specific tasks within each project
  • Implement best practices by fine-tuning task-specific models

Does FinetuneDB affect OpenAI calls?

No, your OpenAI calls will continue to function normally regardless of FinetuneDB’s status. The SDK is designed to:

  • Handle logging errors gracefully
  • Operate independently of OpenAI inference
  • Ensure no disruption to your OpenAI API interactions, even if FinetuneDB is misconfigured or unavailable