Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@edgedb/ai

Package Overview
Dependencies
Maintainers
3
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@edgedb/ai

Helper library for the EdgeDB AI extension

  • 0.1.0-alpha.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
79
decreased by-48.37%
Maintainers
3
Weekly downloads
 
Created
Source

@edgedb/ai

Installation

You can install the @edgedb/ai package using npm, yarn, or pnpm. Choose the command corresponding to your package manager:

npm install @edgedb/ai
yarn add @edgedb/ai
pnpm add @edgedb/ai

EdgeDB Configuration

See the AI documentation for detailed guidance on setting up the AI extension and creating a schema for use with the specialized indexes it includes.

API Reference

createAI(client: Client, options: Partial<AIOptions> = {}): EdgeDBAI

Creates an instance of EdgeDBAI with the specified client and options.

  • client: An EdgeDB client instance.
  • options: Configuration options for the AI model.
    • model: Required. Specifies the AI model to use. This could be a version of GPT or any other model supported by EdgeDB AI.
    • prompt: Optional. Defines the input prompt for the AI model. The prompt can be a simple string, an ID referencing a stored prompt, or a custom prompt structure that includes roles and content for more complex interactions. The default is the built-in system prompt.

EdgeDBAI

Public Methods
  • withConfig(options: Partial<AIOptions>): EdgeDBAI

    Returns a new EdgeDBAI instance with updated configuration options.

  • withContext(context: Partial<QueryContext>): EdgeDBAI

    Returns a new EdgeDBAI instance with an updated query context.

  • async queryRag(message: string, context: QueryContext = this.context): Promise<string>

    Sends a query with context to the configured AI model and returns the response as a string.

Example

The following example demonstrates how to use the @edgedb/ai package to query an AI model about astronomy and chemistry.

import { createClient } from "edgedb";
import { createAI } from "./src/index.js";

const client = createClient({
  instanceName: "_localdev",
  database: "main",
  tlsSecurity: "insecure",
});

const gpt4Ai = createAI(client, {
  model: "gpt-4-turbo-preview",
});

const astronomyAi = gpt4Ai.withContext({ query: "Astronomy" });

console.time("gpt-4 Time");
console.log(await astronomyAi.queryRag("What color is the sky on Mars?"));
console.timeEnd("gpt-4 Time");

const fastAstronomyAi = astronomyAi.withConfig({
  model: "gpt-3.5-turbo",
});

console.time("gpt-3.5 Time");
console.log(await fastAstronomyAi.queryRag("What color is the sky on Mars?"));
console.timeEnd("gpt-3.5 Time");

const fastChemistryAi = fastAstronomyAi.withContext({ query: "Chemistry" });

console.log(
  await fastChemistryAi.queryRag("What is the atomic number of gold?")
);

FAQs

Package last updated on 17 Jun 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc