Skip to content

Commit

Permalink
Use edgedb-ai-sdk provider
Browse files Browse the repository at this point in the history
  • Loading branch information
diksipav committed Oct 17, 2024
1 parent e387af4 commit 99fbc59
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 18 deletions.
11 changes: 6 additions & 5 deletions nextjs-ai-new/app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
34 changes: 27 additions & 7 deletions nextjs-ai-new/app/api/completion/route.ts
Original file line number Diff line number Diff line change
@@ -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",
// });
35 changes: 30 additions & 5 deletions nextjs-ai-new/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nextjs-ai-new/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 99fbc59

Please sign in to comment.