Compare commits

..

15 Commits

Author SHA1 Message Date
sweep-ai[bot] f3c4a4d217 Merge main into sweep/fix-index-initialization 2023-11-15 04:49:32 +00:00
sweep-ai[bot] d3199d8cf4 Merge main into sweep/fix-index-initialization 2023-11-15 01:24:47 +00:00
sweep-ai[bot] 82c30e4b7e Merge main into sweep/fix-index-initialization 2023-11-15 00:21:37 +00:00
sweep-ai[bot] beec819061 Merge main into sweep/fix-index-initialization 2023-11-15 00:18:17 +00:00
sweep-ai[bot] f62e234188 Merge main into sweep/fix-index-initialization 2023-11-14 23:05:47 +00:00
sweep-ai[bot] d86cd5d178 Merge main into sweep/fix-index-initialization 2023-11-14 20:08:16 +00:00
sweep-ai[bot] 3ea2f544f8 Merge main into sweep/fix-index-initialization 2023-11-14 17:16:36 +00:00
sweep-ai[bot] 324b886225 Merge main into sweep/fix-index-initialization 2023-11-14 17:09:20 +00:00
sweep-ai[bot] 884b951c03 Merge main into sweep/fix-index-initialization 2023-11-14 04:20:01 +00:00
sweep-ai[bot] 601a3390c8 Merge main into sweep/fix-index-initialization 2023-11-14 04:00:11 +00:00
sweep-ai[bot] 6789cadf2a Merge main into sweep/fix-index-initialization 2023-11-14 02:10:45 +00:00
sweep-ai[bot] db72c4a2c3 Merge main into sweep/fix-index-initialization 2023-11-14 02:02:15 +00:00
sweep-ai[bot] f01bf00123 Merge main into sweep/fix-index-initialization 2023-11-14 01:59:07 +00:00
sweep-ai[bot] d51cc6f869 Merge main into sweep/fix-index-initialization 2023-11-10 03:12:28 +00:00
sweep-ai[bot] 49574cb493 feat: Updated packages/core/src/indices/vectorStor 2023-11-08 11:17:10 +00:00
8 changed files with 18 additions and 94 deletions
@@ -63,13 +63,7 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
let indexStructs = (await indexStore.getIndexStructs()) as IndexDict[];
let indexStruct: IndexDict | undefined;
if (options.indexStruct && indexStructs.length > 0) {
throw new Error(
"Cannot initialize index with both indexStruct and indexStore",
);
}
if (options.indexStruct) {
if (options.indexStruct && indexStructs.length == 0) {
indexStruct = options.indexStruct;
} else if (indexStructs.length == 1) {
indexStruct = indexStructs[0];
-6
View File
@@ -1,11 +1,5 @@
# create-llama
## 0.0.6
### Patch Changes
- 4431ec7: Label bug fix
## 0.0.5
### Patch Changes
+12 -60
View File
@@ -2,69 +2,19 @@
The easiest way to get started with [LlamaIndex](https://www.llamaindex.ai/) is by using `create-llama`. This CLI tool enables you to quickly start building a new LlamaIndex application, with everything set up for you.
Just run
## Features
```bash
npx create-llama@latest
```
- NextJS, ExpressJS, or FastAPI (python) stateless backend generation 💻
- Streaming or non-streaming backend ⚡
- Optional `shadcn` frontend generation 🎨
to get started, or see below for more options. Once your app is generated, run
## Get Started
```bash
npm run dev
```
You can run `create-llama` in interactive or non-interactive mode.
to start the development server. You can then visit [http://localhost:3000](http://localhost:3000) to see your app.
### Interactive
## What you'll get
- A Next.js-powered front-end. The app is set up as a chat interface that can answer questions about your data (see below)
- You can style it with HTML and CSS, or you can optionally use components from [shadcn/ui](https://ui.shadcn.com/)
- Your choice of 3 back-ends:
- **Next.js**: if you select this option, youll have a full stack Next.js application that you can deploy to a host like [Vercel](https://vercel.com/) in just a few clicks. This uses [LlamaIndex.TS](https://www.npmjs.com/package/llamaindex), our TypeScript library.
- **Express**: if you want a more traditional Node.js application you can generate an Express backend. This also uses LlamaIndex.TS.
- **Python FastAPI**: if you select this option youll get a backend powered by the [llama-index python package](https://pypi.org/project/llama-index/), which you can deploy to a service like Render or fly.io.
- The back-end has a single endpoint that allows you to send the state of your chat and receive additional responses
- You can choose whether you want a streaming or non-streaming back-end (if you're not sure, we recommend streaming)
- You can choose whether you want to use `ContextChatEngine` or `SimpleChatEngine`
- `SimpleChatEngine` will just talk to the LLM directly without using your data
- `ContextChatEngine` will use your data to answer questions (see below).
- The app uses OpenAI by default, so you'll need an OpenAI API key, or you can customize it to use any of the dozens of LLMs we support.
## Using your data
If you've enabled `ContextChatEngine`, you can supply your own data and the app will index it and answer questions. Your generated app will have a folder called `data`:
- With the Next.js backend this is `./data`
- With the Express or Python backend this is in `./backend/data`
The app will ingest any supported files you put in this directory. Your Next.js and Express apps use LlamaIndex.TS so they will be able to ingest any PDF, text, CSV, Markdown, Word and HTML files. The Python backend can read even more types, including video and audio files.
Before you can use your data, you need to index it. If you're using the Next.js or Express apps, run:
```bash
npm run generate
```
Then re-start your app. Remember you'll need to re-run `generate` if you add new files to your `data` folder. If you're using the Python backend, you can trigger indexing of your data by deleting the `./storage` folder and re-starting the app.
## Don't want a front-end?
It's optional! If you've selected the Python or Express back-ends, just delete the `frontend` folder and you'll get an API without any front-end code.
## Customizing the LLM
By default the app will use OpenAI's gpt-3.5-turbo model. If you want to use GPT-4, you can modify this by editing a file:
- In the Next.js backend, edit `./app/api/chat/route.ts` and replace `gpt-3.5-turbo` with `gpt-4`
- In the Express backend, edit `./backend/src/controllers/chat.controller.ts` and likewise replace `gpt-3.5-turbo` with `gpt-4`
- In the Python backend, edit `./backend/app/utils/index.py` and once again replace `gpt-3.5-turbo` with `gpt-4`
You can also replace OpenAI with one of our [dozens of other supported LLMs](https://docs.llamaindex.ai/en/stable/module_guides/models/llms/modules.html).
## Example
The simplest thing to do is run `create-llama` in interactive mode:
You can create a new project interactively by running:
```bash
npx create-llama@latest
@@ -76,7 +26,9 @@ yarn create llama
pnpm create llama@latest
```
You will be asked for the name of your project, along with other configuration options, something like this:
You will be asked for the name of your project, along with other configuration options.
Here is an example:
```bash
>> npm create llama@latest
@@ -93,7 +45,7 @@ Ok to proceed? (y) y
Creating a new LlamaIndex app in /home/my-app.
```
### Running non-interactively
### Non-interactive
You can also pass command line arguments to set up a new project
non-interactively. See `create-llama --help`:
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "create-llama",
"version": "0.0.6",
"version": "0.0.5",
"keywords": [
"rag",
"llamaindex",
@@ -6,17 +6,12 @@ from llama_index import (
StorageContext,
VectorStoreIndex,
load_index_from_storage,
ServiceContext,
)
from llama_index.llms import OpenAI
STORAGE_DIR = "./storage" # directory to cache the generated index
DATA_DIR = "./data" # directory containing the documents to index
service_context = ServiceContext.from_defaults(
llm=OpenAI("gpt-3.5-turbo")
)
def get_index():
logger = logging.getLogger("uvicorn")
@@ -25,7 +20,7 @@ def get_index():
logger.info("Creating new index")
# load the documents and create the index
documents = SimpleDirectoryReader(DATA_DIR).load_data()
index = VectorStoreIndex.from_documents(documents,service_context=service_context)
index = VectorStoreIndex.from_documents(documents)
# store it for later
index.storage_context.persist(STORAGE_DIR)
logger.info(f"Finished creating new index. Stored in {STORAGE_DIR}")
@@ -33,6 +28,6 @@ def get_index():
# load the existing index
logger.info(f"Loading index from {STORAGE_DIR}...")
storage_context = StorageContext.from_defaults(persist_dir=STORAGE_DIR)
index = load_index_from_storage(storage_context,service_context=service_context)
index = load_index_from_storage(storage_context)
logger.info(f"Finished loading index from {STORAGE_DIR}")
return index
@@ -2,9 +2,6 @@
const nextConfig = {
experimental: {
serverComponentsExternalPackages: ["llamaindex"],
outputFileTracingIncludes: {
"/*": ["./cache/**/*"],
},
},
};
@@ -6,17 +6,12 @@ from llama_index import (
StorageContext,
VectorStoreIndex,
load_index_from_storage,
ServiceContext,
)
from llama_index.llms import OpenAI
STORAGE_DIR = "./storage" # directory to cache the generated index
DATA_DIR = "./data" # directory containing the documents to index
service_context = ServiceContext.from_defaults(
llm=OpenAI("gpt-3.5-turbo")
)
def get_index():
logger = logging.getLogger("uvicorn")
@@ -25,7 +20,7 @@ def get_index():
logger.info("Creating new index")
# load the documents and create the index
documents = SimpleDirectoryReader(DATA_DIR).load_data()
index = VectorStoreIndex.from_documents(documents,service_context=service_context)
index = VectorStoreIndex.from_documents(documents)
# store it for later
index.storage_context.persist(STORAGE_DIR)
logger.info(f"Finished creating new index. Stored in {STORAGE_DIR}")
@@ -33,6 +28,6 @@ def get_index():
# load the existing index
logger.info(f"Loading index from {STORAGE_DIR}...")
storage_context = StorageContext.from_defaults(persist_dir=STORAGE_DIR)
index = load_index_from_storage(storage_context,service_context=service_context)
index = load_index_from_storage(storage_context)
logger.info(f"Finished loading index from {STORAGE_DIR}")
return index
@@ -2,9 +2,6 @@
const nextConfig = {
experimental: {
serverComponentsExternalPackages: ["llamaindex"],
outputFileTracingIncludes: {
"/*": ["./cache/**/*"],
},
},
};