Skip to content

Commit

Permalink
refactor: @llamaindex/vercel
Browse files Browse the repository at this point in the history
  • Loading branch information
thucpn committed Nov 29, 2024
1 parent 719ded9 commit 26e6251
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 12 deletions.
4 changes: 2 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@llamaindex/core": "^0.4.10",
"@llamaindex/readers": "^1.0.11",
"@llamaindex/workflow": "^0.0.6",
"@llamaindex/vercel": "^0.0.1",
"@notionhq/client": "^2.2.15",
"@pinecone-database/pinecone": "^4.0.0",
"@vercel/postgres": "^0.10.0",
Expand All @@ -23,8 +24,7 @@
"llamaindex": "^0.8.13",
"mongodb": "^6.7.0",
"pathe": "^1.1.2",
"postgres": "^3.4.4",
"zod": "^3.23.8"
"postgres": "^3.4.4"
},
"devDependencies": {
"@types/node": "^22.9.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/vercel/llamacloud.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { openai } from "@ai-sdk/openai";
import { llamaindex } from "@llamaindex/vercel";

Check failure on line 2 in examples/vercel/llamacloud.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find module '@llamaindex/vercel' or its corresponding type declarations.
import { streamText } from "ai";
import { Document, LlamaCloudIndex } from "llamaindex";
import fs from "node:fs/promises";
import { llamaindex } from "./tool";

async function main() {
const path = "node_modules/llamaindex/examples/abramov.txt";
Expand All @@ -17,7 +17,7 @@ async function main() {
});
const queryTool = await llamaindex({
index,
description: "Search through Abramov's essay", // optional description
description: "Search through the documents", // optional description
});
console.log("Successfully created index and queryTool");

Expand Down
4 changes: 2 additions & 2 deletions examples/vercel/vector-store.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { openai } from "@ai-sdk/openai";
import { llamaindex } from "@llamaindex/vercel";

Check failure on line 2 in examples/vercel/vector-store.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find module '@llamaindex/vercel' or its corresponding type declarations.
import { streamText } from "ai";
import { Document, VectorStoreIndex } from "llamaindex";
import fs from "node:fs/promises";
import { llamaindex } from "./tool";

async function main() {
const path = "node_modules/llamaindex/examples/abramov.txt";
Expand All @@ -12,7 +12,7 @@ async function main() {
const index = await VectorStoreIndex.fromDocuments([document]);
const queryTool = await llamaindex({
index,
description: "Search through Abramov's essay", // optional description
description: "Search through the documents", // optional description
});
console.log("Successfully created index and queryTool");

Expand Down
50 changes: 50 additions & 0 deletions packages/providers/vercel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@llamaindex/vercel",
"description": "Vercel Adapter for LlamaIndex",
"version": "0.0.1",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"exports": {
".": {
"edge-light": {
"types": "./dist/index.edge-light.d.ts",
"default": "./dist/index.edge-light.js"
},
"workerd": {
"types": "./dist/index.edge-light.d.ts",
"default": "./dist/index.edge-light.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
},
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "https://github.com/run-llama/LlamaIndexTS.git",
"directory": "packages/providers/vercel"
},
"scripts": {
"build": "bunchee",
"dev": "bunchee --watch"
},
"devDependencies": {
"bunchee": "5.6.1"
},
"dependencies": {
"@llamaindex/core": "workspace:*",
"zod": "^3.23.8"
},
"peerDependencies": {
"ai": "^4.0.0"
}
}
1 change: 1 addition & 0 deletions packages/providers/vercel/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { llamaindex } from "./tool";
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { CoreTool } from "ai";
import { LlamaCloudIndex, VectorStoreIndex } from "llamaindex";
import type { BaseQueryEngine } from "@llamaindex/core/query-engine";
import type { CoreTool } from "ai";
import { z } from "zod";

interface DatasourceIndex {
asQueryEngine: () => BaseQueryEngine;
}

export async function llamaindex({
index,
description,
}: {
index: VectorStoreIndex | LlamaCloudIndex;
index: DatasourceIndex;
description?: string;
}): Promise<CoreTool> {
const queryEngine = index.asQueryEngine();
Expand Down
19 changes: 19 additions & 0 deletions packages/providers/vercel/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"outDir": "./lib",
"tsBuildInfoFile": "./lib/.tsbuildinfo"
},
"include": ["./src"],
"references": [
{
"path": "../../core/tsconfig.json"
},
{
"path": "../../env/tsconfig.json"
}
]
}
22 changes: 19 additions & 3 deletions pnpm-lock.yaml

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

3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
{
"path": "./packages/providers/vllm/tsconfig.json"
},
{
"path": "./packages/providers/vercel/tsconfig.json"
},
{
"path": "./packages/cloud/tsconfig.json"
},
Expand Down

0 comments on commit 26e6251

Please sign in to comment.