Skip to content

Commit

Permalink
feat: use edge runtime (run-llama#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusschiesser committed Mar 18, 2024
1 parent 7ed47c4 commit 2e50d85
Show file tree
Hide file tree
Showing 5 changed files with 490 additions and 234 deletions.
5 changes: 1 addition & 4 deletions app/api/fetch/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import {
Document,
MetadataMode,
OpenAIEmbedding,
SentenceSplitter,
SimpleNodeParser,
VectorStoreIndex,
serviceContextFromDefaults,
} from "llamaindex";
} from "@llamaindex/edge";

export default async function splitAndEmbed(
document: string,
Expand Down
9 changes: 3 additions & 6 deletions app/api/llm/datasource.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { DATASOURCES_CACHE_DIR } from "@/scripts/constants.mjs";
import {
VectorStoreIndex,
storageContextFromDefaults,
ServiceContext,
SimpleDocumentStore,
} from "llamaindex";
import { VectorStoreIndex, ServiceContext } from "@llamaindex/edge";
import { storageContextFromDefaults } from "@llamaindex/edge/storage/StorageContext";
import { SimpleDocumentStore } from "@llamaindex/edge/storage/docStore/SimpleDocumentStore";

export async function getDataSource(
serviceContext: ServiceContext,
Expand Down
8 changes: 3 additions & 5 deletions app/api/llm/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
serviceContextFromDefaults,
Response,
VectorStoreIndex,
} from "llamaindex";
import { IndexDict } from "llamaindex/indices/json-to-index-struct";
IndexDict,
} from "@llamaindex/edge";
import { NextRequest, NextResponse } from "next/server";
import { LLMConfig, MessageContent } from "@/app/client/platforms/llm";
import { getDataSource } from "./datasource";
Expand Down Expand Up @@ -200,7 +200,5 @@ export async function POST(request: NextRequest) {
}
}

export const runtime = "nodejs";
export const runtime = "edge";
export const dynamic = "force-dynamic";
// Set max running time of function, for Vercel Hobby use 10 seconds, see https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration
export const maxDuration = 120;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"@fortaine/fetch-event-source": "^3.0.6",
"@google/generative-ai": "^0.1.3",
"@llamaindex/edge": "^0.2.1",
"@radix-ui/react-alert-dialog": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.4",
Expand All @@ -39,7 +40,6 @@
"dotenv": "^16.3.1",
"emoji-picker-react": "^4.4.12",
"encoding": "^0.1.13",
"llamaindex": "^0.1.18",
"lucide-react": "^0.277.0",
"mermaid": "^10.3.1",
"nanoid": "^5.0.2",
Expand Down
Loading

0 comments on commit 2e50d85

Please sign in to comment.