Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

ai-sql

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ai-sql

Give any Vercel AI SDK project the ability to interact with PostgreSQL, SQlite or MySQL databases in one line.

latest
npmnpm
Version
0.0.1-8
Version published
Maintainers
1
Created
Source

AI SQL

Tools for Vercel AI SDK that lets your AI query PostgreSQL, MySQL or SQLite databases in one line.

Installation

npm install ai-sql

Usage

import * as ai from "ai";
import { createOpenAI } from "@ai-sdk/openai";
import { postgres } from "ai-sql"; // or mysql, sqlite

const openai = createOpenAI({
  compatibility: "strict",
});

const { text } = await ai.generateText({
  model: openai("gpt-4-turbo"),
  prompt: "",
  tools: {
    database: await postgres(process.env.POSTGRES_URL!),
  },
  maxSteps: 3,
});

For more examples, see the example directory.

Creating a provider

import { Schema, Database, sqlTool } from "ai-sql";

export class MyDbTool implements Database {
  async initialize() {
    // do setup here
  }

  async describe(): Promise<Schema> {
    // describe the schema

    return {
      // database type
      database: "my database",
      // stringified schema representation
      description: `
        create table messages (
          id integer primary key,
          text string not null,
        );
      `,
    };
  }

  async query(query: string) {
    // return result rows here
    return [];
  }
}

const tools = {
  database: await sqlTool(new MyDbTool()),
};

Keywords

ai

FAQs

Package last updated on 03 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts