diff --git a/nextjs-ai-new/app/api/chat/route.ts b/nextjs-ai-new/app/api/chat/route.ts index 62b23b6..2accf76 100644 --- a/nextjs-ai-new/app/api/chat/route.ts +++ b/nextjs-ai-new/app/api/chat/route.ts @@ -1,16 +1,17 @@ import { streamText } from "ai"; import { createClient } from "edgedb"; -import { createGel } from "../../../../../edgedb-js/packages/gel/dist"; +import { createEdgeDBRag } from "../../../../../edgedb-js/packages/edgedb-ai-sdk/dist"; -export const client = createClient({ tlsSecurity: "insecure" }); +export const client = createClient(); export async function POST(req: Request) { const requestData = await req.json(); + const edgedbRag = await createEdgeDBRag(client); + const textModel = edgedbRag.languageModel("gpt-4-turbo-preview"); + const result = await streamText({ - model: ( - await createGel(client) - ).languageModel("gpt-4-turbo-preview", { + model: textModel.withSettings({ context: { query: "Book" }, prompt: { custom: requestData.messages, diff --git a/nextjs-ai-new/app/api/completion/route.ts b/nextjs-ai-new/app/api/completion/route.ts index cee9dce..f75c538 100644 --- a/nextjs-ai-new/app/api/completion/route.ts +++ b/nextjs-ai-new/app/api/completion/route.ts @@ -1,18 +1,38 @@ import { streamText } from "ai"; -import { createClient } from "edgedb"; -import { createGel } from "../../../../../edgedb-js/packages/gel/dist"; - -export const client = createClient(); +import { edgedbRag } from "../../../../../edgedb-js/packages/edgedb-ai-sdk/dist"; export async function POST(req: Request) { const { prompt } = await req.json(); + const textModel = (await edgedbRag).languageModel("gpt-4-turbo-preview"); + const result = await streamText({ - model: ( - await createGel(client) - ).languageModel("gpt-4-turbo-preview", { context: { query: "Book" } }), + model: textModel.withSettings({ context: { query: "Book" } }), prompt, }); return result.toDataStreamResponse(); } + +// or + +// import { streamText } from "ai"; +// import { createClient } from "edgedb"; +// import { edgedbRag } from "../../../../../edgedb-js/packages/edgedb-ai-sdk/dist"; + +// export const client = createClient(); + +// const edgedbRag = await createEdgeDBRag(client); +// const result = await streamText({ +// model: edgedbRag.languageModel("gpt-4-turbo-preview", { +// context: { query: "Book" }, +// }), +// prompt, +// }); + +// Embedding example + +// const embeddingResult = await embed({ +// model: edgedbRag.textEmbeddingModel("text-embedding-3-small"), +// value: "sunny day at the beach", +// }); diff --git a/nextjs-ai-new/package-lock.json b/nextjs-ai-new/package-lock.json index 1d3769e..248580d 100644 --- a/nextjs-ai-new/package-lock.json +++ b/nextjs-ai-new/package-lock.json @@ -10,11 +10,11 @@ "dependencies": { "@ai-sdk/react": "^0.0.62", "@edgedb/ai": "file:../../edgedb-js/packages/ai", + "@edgedb/ai-sdk": "file:../../edgedb-js/packages/edgedb-ai-sdk", "@next/env": "^14.2.3", "ai": "latest", "edgedb": "^1.5.0", "eventsource-parser": "^1.1.2", - "gel": "file:../../edgedb-js/packages/gel", "next": "^14.2.3", "react": "^18", "react-dom": "^18" @@ -97,9 +97,34 @@ "edgedb": "^1.5.0" } }, + "../../edgedb-js/packages/edgedb-ai-sdk": { + "name": "@edgedb/ai-sdk", + "version": "0.0.1", + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "0.0.24", + "@ai-sdk/provider-utils": "^1.0.20" + }, + "devDependencies": { + "@repo/tsconfig": "*", + "@types/node": "^18", + "edgedb": "*", + "tsup": "^8", + "typescript": "5.5.4", + "zod": "3.23.8" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "edgedb": "^1.5.0", + "zod": "^3.0.0" + } + }, "../../edgedb-js/packages/gel": { "name": "@edgedb/gel", "version": "0.0.1", + "extraneous": true, "license": "Apache-2.0", "dependencies": { "@ai-sdk/provider": "0.0.24", @@ -371,6 +396,10 @@ "resolved": "../../edgedb-js/packages/ai", "link": true }, + "node_modules/@edgedb/ai-sdk": { + "resolved": "../../edgedb-js/packages/edgedb-ai-sdk", + "link": true + }, "node_modules/@esbuild/aix-ppc64": { "version": "0.23.1", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.23.1.tgz", @@ -3431,10 +3460,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/gel": { - "resolved": "../../edgedb-js/packages/gel", - "link": true - }, "node_modules/get-intrinsic": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", diff --git a/nextjs-ai-new/package.json b/nextjs-ai-new/package.json index fb0c355..989b448 100644 --- a/nextjs-ai-new/package.json +++ b/nextjs-ai-new/package.json @@ -16,7 +16,7 @@ "ai": "latest", "edgedb": "^1.5.0", "eventsource-parser": "^1.1.2", - "gel": "file:../../edgedb-js/packages/gel", + "@edgedb/ai-sdk": "file:../../edgedb-js/packages/edgedb-ai-sdk", "next": "^14.2.3", "react": "^18", "react-dom": "^18"