From 570973b9d6b8a4b720c75c60dbbb3c70ed5b8915 Mon Sep 17 00:00:00 2001 From: Alex Yang <himself65@outlook.com> Date: Wed, 24 Jan 2024 21:00:47 -0600 Subject: [PATCH] docs: add stackblitz playground (#439) --- README.md | 4 ++++ examples/README.md | 32 +++++++++++--------------------- examples/chatEngine.ts | 2 +- examples/keywordIndex.ts | 2 +- examples/package.json | 3 +-- examples/sentenceWindow.ts | 2 +- examples/storageContext.ts | 2 +- examples/subquestion.ts | 2 +- examples/summaryIndex.ts | 2 +- examples/tsconfig.json | 14 +++++++++++++- examples/vectorIndexCustomize.ts | 2 +- 11 files changed, 36 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 93bd71413..4d52c6abe 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,10 @@ Use your own data with large language models (LLMs, OpenAI ChatGPT and others) i Documentation: https://ts.llamaindex.ai/ +Try examples online: + +[](https://stackblitz.com/github/run-llama/LlamaIndexTS/tree/main/examples) + ## What is LlamaIndex.TS? LlamaIndex.TS aims to be a lightweight, easy to use set of libraries to help you integrate large language models into your applications with your own data. diff --git a/examples/README.md b/examples/README.md index eb16a1088..2b4fc0db5 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,29 +1,19 @@ -# Simple Examples +# LlamaIndexTS Examples -Before running any of the examples, make sure to set your OpenAI environment variable: +Before running any of the code examples, +make sure you have basic knowledge of the [LlamaIndexTS](https://ts.llamaindex.ai/). -```bash -export OPENAI_API_KEY="sk-..." -``` - -There are two ways to run the examples, using the latest published version of `llamaindex` or using a local build. - -## Using the latest published version +## Usage -Make sure to call `npm install` before running these examples: +```shell +# export your API key +export OPENAI_API_KEY="sk-..." -```bash -npm install +npx ts-node ./chatEngine.ts ``` -Then run the examples with `ts-node`, for example `npx ts-node vectorIndex.ts` - -## Using the local build +## Build your own RAG app -```bash -pnpm install -pnpm --filter llamaindex build -pnpm link ../packages/core +```shell +npx create llama ``` - -Then run the examples with `ts-node`, for example `pnpx ts-node vectorIndex.ts` diff --git a/examples/chatEngine.ts b/examples/chatEngine.ts index eb7580ac7..52538944b 100644 --- a/examples/chatEngine.ts +++ b/examples/chatEngine.ts @@ -10,7 +10,7 @@ import { VectorStoreIndex, } from "llamaindex"; -import essay from "./essay.js"; +import essay from "./essay"; async function main() { const document = new Document({ text: essay }); diff --git a/examples/keywordIndex.ts b/examples/keywordIndex.ts index edca73fbc..ad6c7b1d3 100644 --- a/examples/keywordIndex.ts +++ b/examples/keywordIndex.ts @@ -3,7 +3,7 @@ import { KeywordTableIndex, KeywordTableRetrieverMode, } from "llamaindex"; -import essay from "./essay.js"; +import essay from "./essay"; async function main() { const document = new Document({ text: essay, id_: "essay" }); diff --git a/examples/package.json b/examples/package.json index b0c8fcc53..66bec6144 100644 --- a/examples/package.json +++ b/examples/package.json @@ -1,7 +1,6 @@ { - "version": "0.0.3", - "private": true, "name": "examples", + "private": true, "dependencies": { "@datastax/astra-db-ts": "^0.1.2", "@notionhq/client": "^2.2.14", diff --git a/examples/sentenceWindow.ts b/examples/sentenceWindow.ts index 63c303faa..fcb89d99d 100644 --- a/examples/sentenceWindow.ts +++ b/examples/sentenceWindow.ts @@ -6,7 +6,7 @@ import { VectorStoreIndex, serviceContextFromDefaults, } from "llamaindex"; -import essay from "./essay.js"; +import essay from "./essay"; async function main() { const document = new Document({ text: essay, id_: "essay" }); diff --git a/examples/storageContext.ts b/examples/storageContext.ts index 9f62f8f73..74fbd43fb 100644 --- a/examples/storageContext.ts +++ b/examples/storageContext.ts @@ -3,7 +3,7 @@ import { storageContextFromDefaults, VectorStoreIndex, } from "llamaindex"; -import essay from "./essay.js"; +import essay from "./essay"; async function main() { // Create Document object with essay diff --git a/examples/subquestion.ts b/examples/subquestion.ts index 772447581..b1e692e1f 100644 --- a/examples/subquestion.ts +++ b/examples/subquestion.ts @@ -1,6 +1,6 @@ import { Document, SubQuestionQueryEngine, VectorStoreIndex } from "llamaindex"; -import essay from "./essay.js"; +import essay from "./essay"; (async () => { const document = new Document({ text: essay, id_: essay }); diff --git a/examples/summaryIndex.ts b/examples/summaryIndex.ts index 9f7b6c823..d11a47031 100644 --- a/examples/summaryIndex.ts +++ b/examples/summaryIndex.ts @@ -5,7 +5,7 @@ import { SummaryRetrieverMode, serviceContextFromDefaults, } from "llamaindex"; -import essay from "./essay.js"; +import essay from "./essay"; async function main() { const serviceContext = serviceContextFromDefaults({ diff --git a/examples/tsconfig.json b/examples/tsconfig.json index 05ebd271f..289a2d66d 100644 --- a/examples/tsconfig.json +++ b/examples/tsconfig.json @@ -1,5 +1,17 @@ { - "extends": "../tsconfig.json", + "compilerOptions": { + "target": "es2016", + "module": "esnext", + "moduleResolution": "bundler", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "outDir": "./lib", + "tsBuildInfoFile": "./lib/.tsbuildinfo", + "incremental": true, + "composite": true, + }, "ts-node": { "files": true, "compilerOptions": { diff --git a/examples/vectorIndexCustomize.ts b/examples/vectorIndexCustomize.ts index 48175f2af..e9013a0e6 100644 --- a/examples/vectorIndexCustomize.ts +++ b/examples/vectorIndexCustomize.ts @@ -6,7 +6,7 @@ import { SimilarityPostprocessor, VectorStoreIndex, } from "llamaindex"; -import essay from "./essay.js"; +import essay from "./essay"; // Customize retrieval and query args async function main() { -- GitLab