Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI binding: rename EdgeDB to Gel #1149

Open
wants to merge 1 commit into
base: gel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions packages/ai/README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
# @edgedb/ai
# @gel/ai

## Installation

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

```bash
npm install @edgedb/ai
yarn add @edgedb/ai
pnpm add @edgedb/ai
npm install @gel/ai
yarn add @gel/ai
pnpm add @gel/ai
```

## EdgeDB Configuration
## Gel 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`
### `createAI(client: Client, options: Partial<AIOptions> = {}): GelAI`

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

- `client`: An EdgeDB client instance.
- `client`: An Gel client instance.
- `options`: Configuration options for the AI model.
- `model`: Required. Specifies the AI model to use. This could be some of the OpenAI, Mistral or Anthropic models supported by EdgeDB AI.
- `model`: Required. Specifies the AI model to use. This could be some of the OpenAI, Mistral or Anthropic models supported by Gel AI.
- `prompt`: Optional. Defines the input messages for the AI model. The prompt can have an `ID` or a `name` referencing a stored prompt. The referenced prompt will supply predefined messages. Optionally, include a custom list of messages using the `custom` field. These custom messages will be concatenated with messages from the stored prompt referenced by `id` or `name`. If no `id` or `name` is specified, only the `custom` messages will be used. If no `id`, `name`, or `custom` messages are provided, the built-in system prompt will be used by default.

### `EdgeDBAI`
### `GelAI`

#### Public Methods

- `withConfig(options: Partial<AIOptions>): EdgeDBAI`
- `withConfig(options: Partial<AIOptions>): GelAI`

Returns a new `EdgeDBAI` instance with updated configuration options.
Returns a new `GelAI` instance with updated configuration options.

- `withContext(context: Partial<QueryContext>): EdgeDBAI`
- `withContext(context: Partial<QueryContext>): GelAI`

Returns a new `EdgeDBAI` instance with an updated query context.
Returns a new `GelAI` instance with an updated query context.

- `async queryRag(message: string, context?: QueryContext): Promise<string>`

Expand All @@ -54,14 +54,14 @@ Creates an instance of `EdgeDBAI` with the specified client and options.

## Tool Calls

Tool calls are supported by the AI extension. They should be executed on the client side and tool call results should be provided back to the EdgeDB AI.
Tool calls are supported by the AI extension. They should be executed on the client side and tool call results should be provided back to the Gel AI.

## Example

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

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

const client = createClient({
Expand Down
12 changes: 6 additions & 6 deletions packages/ai/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@edgedb/ai",
"description": "Helper library for the EdgeDB AI extension",
"name": "@gel/ai",
"description": "Helper library for the Gel AI extension",
"version": "0.1.0-alpha.2",
"author": "EdgeDB <info@edgedb.com>",
"author": "Gel <info@gel.com>",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/edgedb/edgedb-js.git",
"url": "https://github.com/gel/gel-js.git",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe will need an update.

"directory": "packages/ai"
},
"main": "./dist/index.js",
Expand Down Expand Up @@ -39,11 +39,11 @@
"jest": "29.7.0",
"ts-jest": "29.1.4",
"typescript": "^5.5.2",
"edgedb": "*",
"gel": "*",
"@repo/tsconfig": "*"
},
"peerDependencies": {
"edgedb": "^1.5.0"
"gel": "^1.5.0"
},
"dependencies": {
"eventsource-parser": "^1.1.2"
Expand Down
20 changes: 10 additions & 10 deletions packages/ai/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Client } from "edgedb";
import type { Client } from "gel";
import { EventSourceParserStream } from "eventsource-parser/stream";

import type { ResolvedConnectConfig } from "edgedb/dist/conUtils.js";
import type { ResolvedConnectConfig } from "gel/dist/conUtils.js";
import {
getAuthenticatedFetch,
type AuthenticatedFetch,
} from "edgedb/dist/utils.js";
} from "gel/dist/utils.js";
import {
type AIOptions,
type QueryContext,
Expand All @@ -14,17 +14,17 @@ import {
type EmbeddingRequest,
isPromptRequest,
} from "./types.js";
import { getHTTPSCRAMAuth } from "edgedb/dist/httpScram.js";
import { cryptoUtils } from "edgedb/dist/browserCrypto.js";
import { getHTTPSCRAMAuth } from "gel/dist/httpScram.js";
import { cryptoUtils } from "gel/dist/browserCrypto.js";
import { extractMessageFromParsedEvent, handleResponseError } from "./utils.js";

export function createAI(client: Client, options: AIOptions) {
return new EdgeDBAI(client, options);
return new GelAI(client, options);
}

const httpSCRAMAuth = getHTTPSCRAMAuth(cryptoUtils);

export class EdgeDBAI {
export class GelAI {
/** @internal */
private readonly authenticatedFetch: Promise<AuthenticatedFetch>;
private readonly options: AIOptions;
Expand All @@ -36,7 +36,7 @@ export class EdgeDBAI {
options: AIOptions,
context: Partial<QueryContext> = {},
) {
this.authenticatedFetch = EdgeDBAI.getAuthenticatedFetch(client);
this.authenticatedFetch = GelAI.getAuthenticatedFetch(client);
this.options = options;
this.context = {
query: context.query ?? "",
Expand All @@ -54,15 +54,15 @@ export class EdgeDBAI {
}

withConfig(options: Partial<AIOptions>) {
return new EdgeDBAI(
return new GelAI(
this.client,
{ ...this.options, ...options },
this.context,
);
}

withContext(context: Partial<QueryContext>) {
return new EdgeDBAI(this.client, this.options, {
return new GelAI(this.client, this.options, {
...this.context,
...context,
});
Expand Down
26 changes: 13 additions & 13 deletions packages/ai/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export type ChatParticipantRole = "system" | "user" | "assistant" | "tool";

export interface EdgeDBSystemMessage {
export interface GelSystemMessage {
role: "system";
content: string;
}

export interface EdgeDBUserMessage {
export interface GelUserMessage {
role: "user";
content: { type: "text"; text: string }[];
}

export interface EdgeDBAssistantMessage {
export interface GelAssistantMessage {
role: "assistant";
content: string;
tool_calls?: {
Expand All @@ -20,22 +20,22 @@ export interface EdgeDBAssistantMessage {
}[];
}

export interface EdgeDBToolMessage {
export interface GelToolMessage {
role: "tool";
content: string;
tool_call_id: string;
}

export type EdgeDBMessage =
| EdgeDBSystemMessage
| EdgeDBUserMessage
| EdgeDBAssistantMessage
| EdgeDBToolMessage;
export type GelMessage =
| GelSystemMessage
| GelUserMessage
| GelAssistantMessage
| GelToolMessage;

export type Prompt =
| { name: string; custom?: EdgeDBMessage[] }
| { id: string; custom?: EdgeDBMessage[] }
| { custom: EdgeDBMessage[] };
| { name: string; custom?: GelMessage[] }
| { id: string; custom?: GelMessage[] }
| { custom: GelMessage[] };

export interface AIOptions {
model: string;
Expand All @@ -55,7 +55,7 @@ export interface RagRequestPrompt {
}

export interface RagRequestMessages {
messages: EdgeDBMessage[];
messages: GelMessage[];
[key: string]: unknown;
}

Expand Down
Loading