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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tsdiapi/gpt

v0.1.1

Published

A TSDIAPI plugin to extend API functionality with GPT.

Downloads

202

Readme

🚀 TSDIAPI GPT Plugin

A TSDIAPI plugin that provides seamless integration with OpenAI's GPT models, allowing structured responses, JSON-based AI output, and customizable chat interactions.


📦 Installation

Install the plugin via npm:

npm install --save @tsdiapi/gpt

Then, register the plugin in your TSDIAPI project:

import { createApp } from "@tsdiapi/server";
import createPlugin from "@tsdiapi/gpt";

createApp({
  plugins: [
    createPlugin({
      apiKey: "your-openai-api-key", // Required
      model: "gpt-4o-mini", // Optional (default: gpt-4o-mini)
    }),
  ],
});

🚀 Features

  • 🔥 Structured JSON Responses – Generate structured AI responses based on DTO classes.
  • 🛠 Automatic Schema Generation – Uses class-validator-jsonschema to create JSON schemas from DTOs.
  • Multi-Model Support – Works with various OpenAI models like gpt-4o, gpt-3.5-turbo, and more.
  • 🎯 Text and JSON Output – Supports standard chat completion and structured JSON responses.

🔧 Configuration Options

| Option | Type | Default | ENV Variable | Description | | -------- | -------- | --------------- | ----------------- | --------------------------- | | apiKey | string | "" | OPENAI_API_KEY | OpenAI API Key (Required) | | model | string | "gpt-4o-mini" | OPENAI_MODEL_ID | Default model to use |


📌 How to Use

Structured JSON Output (DTO-based)

Generate structured JSON responses from OpenAI using DTOs.

import { getGPTProvider } from "@tsdiapi/gpt";
import { IsString, IsEmail } from "class-validator";
import { Expose } from "class-transformer";

class UserDTO {
  @IsString()
  @Expose()
  name: string;

  @IsEmail()
  @Expose()
  email: string;
}

async function run() {
  const gpt = getGPTProvider();
  const response = await gpt.jsonDTO("Generate a random user", UserDTO);
  console.log(response);
}

run();

🔹 GPT will return a structured response following UserDTO schema.


Basic Chat Completion

Perform a simple text-based GPT completion:

import { getGPTProvider } from "@tsdiapi/gpt";

async function run() {
  const gpt = getGPTProvider();
  const response = await gpt.chat("Tell me a joke");
  console.log(response.result);
}

run();

Raw JSON Response

Send a JSON schema manually:

import { getGPTProvider } from "@tsdiapi/gpt";

const jsonSchema = {
  type: "object",
  properties: {
    title: { type: "string" },
    description: { type: "string" },
  },
  required: ["title", "description"],
};

async function run() {
  const gpt = getGPTProvider();
  const response = await gpt.JsonString("Describe a cat", jsonSchema);
  console.log(response);
}

run();

📌 Example Response (Structured Output)

{
  "message": {
    "role": "assistant",
    "content": "{ \"name\": \"John Doe\", \"email\": \"johndoe@example.com\" }"
  },
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 15,
    "total_tokens": 35
  },
  "result": {
    "name": "John Doe",
    "email": "johndoe@example.com"
  }
}

📌 Related Plugins

Explore other TSDIAPI plugins: 🔗 Available Plugins


👨‍💻 Contributing

Contributions are welcome! If you have ideas for improvements, open an issue or submit a pull request.

Author: unbywyd
📧 Contact: unbywyd@gmail.com

🚀 Happy coding with TSDIAPI GPT Plugin! 🎉