mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-15 14:55:41 -04:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| de070dbfa7 | |||
| 87eb72bdb2 | |||
| fe03aaae55 | |||
| 9ce7d3d648 | |||
| 0471407761 | |||
| e4b807a018 | |||
| 0a0ec37725 | |||
| 8abca5d818 | |||
| 3a29a8036b | |||
| e2b9b66f71 | |||
| bb66cb7e36 | |||
| 2159e77c9d | |||
| 3154f521d9 | |||
| fda8024607 |
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"llamaindex": patch
|
||||
---
|
||||
|
||||
update dependencies
|
||||
@@ -1,6 +1,3 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
pnpm format
|
||||
pnpm lint
|
||||
npx lint-staged
|
||||
|
||||
@@ -1,4 +1 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
pnpm test
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# docs
|
||||
|
||||
## 0.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 3154f52: chore: add qdrant readme
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
sidebar_position: 0
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# Documents and Nodes
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
sidebar_position: 0
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# LLM
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
label: "Vector Stores"
|
||||
position: 0
|
||||
@@ -0,0 +1,88 @@
|
||||
# Qdrant Vector Store
|
||||
|
||||
To run this example, you need to have a Qdrant instance running. You can run it with Docker:
|
||||
|
||||
```bash
|
||||
docker pull qdrant/qdrant
|
||||
docker run -p 6333:6333 qdrant/qdrant
|
||||
```
|
||||
|
||||
## Importing the modules
|
||||
|
||||
```ts
|
||||
import fs from "node:fs/promises";
|
||||
import { Document, VectorStoreIndex, QdrantVectorStore } from "llamaindex";
|
||||
```
|
||||
|
||||
## Load the documents
|
||||
|
||||
```ts
|
||||
const path = "node_modules/llamaindex/examples/abramov.txt";
|
||||
const essay = await fs.readFile(path, "utf-8");
|
||||
```
|
||||
|
||||
## Setup Qdrant
|
||||
|
||||
```ts
|
||||
const vectorStore = new QdrantVectorStore({
|
||||
url: "http://localhost:6333",
|
||||
port: 6333,
|
||||
});
|
||||
```
|
||||
|
||||
## Setup the index
|
||||
|
||||
```ts
|
||||
const document = new Document({ text: essay, id_: path });
|
||||
|
||||
const index = await VectorStoreIndex.fromDocuments([document], {
|
||||
vectorStore,
|
||||
});
|
||||
```
|
||||
|
||||
## Query the index
|
||||
|
||||
```ts
|
||||
const queryEngine = index.asQueryEngine();
|
||||
|
||||
const response = await queryEngine.query({
|
||||
query: "What did the author do in college?",
|
||||
});
|
||||
|
||||
// Output response
|
||||
console.log(response.toString());
|
||||
```
|
||||
|
||||
## Full code
|
||||
|
||||
```ts
|
||||
import fs from "node:fs/promises";
|
||||
import { Document, VectorStoreIndex, QdrantVectorStore } from "llamaindex";
|
||||
|
||||
async function main() {
|
||||
const path = "node_modules/llamaindex/examples/abramov.txt";
|
||||
const essay = await fs.readFile(path, "utf-8");
|
||||
|
||||
const vectorStore = new QdrantVectorStore({
|
||||
url: "http://localhost:6333",
|
||||
port: 6333,
|
||||
});
|
||||
|
||||
const document = new Document({ text: essay, id_: path });
|
||||
|
||||
const index = await VectorStoreIndex.fromDocuments([document], {
|
||||
vectorStore,
|
||||
});
|
||||
|
||||
const queryEngine = index.asQueryEngine();
|
||||
|
||||
const response = await queryEngine.query({
|
||||
query: "What did the author do in college?",
|
||||
});
|
||||
|
||||
// Output response
|
||||
console.log(response.toString());
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
```
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docs",
|
||||
"version": "0.0.0",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"docusaurus": "docusaurus",
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
import {
|
||||
Document,
|
||||
OpenAIEmbedding,
|
||||
VectorStoreIndex,
|
||||
serviceContextFromDefaults,
|
||||
} from "llamaindex";
|
||||
|
||||
async function main() {
|
||||
// Load essay from abramov.txt in Node
|
||||
const path = "node_modules/llamaindex/examples/abramov.txt";
|
||||
|
||||
const essay = await fs.readFile(path, "utf-8");
|
||||
|
||||
// Create Document object with essay
|
||||
const document = new Document({ text: essay, id_: path });
|
||||
|
||||
// Create service context and specify text-embedding-3-large
|
||||
const embedModel = new OpenAIEmbedding({
|
||||
model: "text-embedding-3-large",
|
||||
dimensions: 1024,
|
||||
});
|
||||
const serviceContext = serviceContextFromDefaults({ embedModel });
|
||||
|
||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||
const index = await VectorStoreIndex.fromDocuments([document], {
|
||||
serviceContext,
|
||||
});
|
||||
|
||||
// Query the index
|
||||
const queryEngine = index.asQueryEngine();
|
||||
const response = await queryEngine.query({
|
||||
query: "What did the author do in college?",
|
||||
});
|
||||
|
||||
// Output response
|
||||
console.log(response.toString());
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
+6
-6
@@ -8,7 +8,7 @@
|
||||
"format": "prettier --ignore-unknown --cache --check .",
|
||||
"format:write": "prettier --ignore-unknown --write .",
|
||||
"lint": "turbo run lint",
|
||||
"prepare": "husky install",
|
||||
"prepare": "husky",
|
||||
"test": "turbo run test",
|
||||
"type-check": "tsc -b --diagnostics",
|
||||
"release": "pnpm run build:release && changeset publish",
|
||||
@@ -18,20 +18,20 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@changesets/cli": "^2.27.1",
|
||||
"@turbo/gen": "^1.11.2",
|
||||
"@turbo/gen": "^1.11.3",
|
||||
"@types/jest": "^29.5.11",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-config-custom": "workspace:*",
|
||||
"husky": "^8.0.3",
|
||||
"husky": "^9.0.6",
|
||||
"jest": "^29.7.0",
|
||||
"lint-staged": "^15.2.0",
|
||||
"prettier": "^3.2.4",
|
||||
"prettier-plugin-organize-imports": "^3.2.4",
|
||||
"ts-jest": "^29.1.1",
|
||||
"turbo": "^1.11.2",
|
||||
"ts-jest": "^29.1.2",
|
||||
"turbo": "^1.11.3",
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"packageManager": "pnpm@8.10.5+sha256.a4bd9bb7b48214bbfcd95f264bd75bb70d100e5d4b58808f5cd6ab40c6ac21c5",
|
||||
"packageManager": "pnpm@8.14.3+sha256.2d0363bb6c314daa67087ef07743eea1ba2e2d360c835e8fec6b5575e4ed9484",
|
||||
"pnpm": {
|
||||
"overrides": {
|
||||
"trim": "1.0.1",
|
||||
|
||||
@@ -1,5 +1,29 @@
|
||||
# llamaindex
|
||||
|
||||
## 0.1.2
|
||||
|
||||
- e4b807a: fix: invalid package.json
|
||||
|
||||
## 0.1.1
|
||||
|
||||
No changes for this release.
|
||||
|
||||
## 0.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- 3154f52: chore: add qdrant readme
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- bb66cb7: add new OpenAI embeddings (with dimension reduction support)
|
||||
|
||||
## 0.0.51
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- fda8024: revert: export conditions not working with moduleResolution `node`
|
||||
|
||||
## 0.0.50
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
# LlamaIndex.TS
|
||||
|
||||
[](https://www.npmjs.com/package/llamaindex)
|
||||
[](https://www.npmjs.com/package/llamaindex)
|
||||
[](https://www.npmjs.com/package/llamaindex)
|
||||
[](https://discord.com/invite/eN6D2HQ4aX)
|
||||
|
||||
LlamaIndex is a data framework for your LLM application.
|
||||
|
||||
Use your own data with large language models (LLMs, OpenAI ChatGPT and others) in Typescript and Javascript.
|
||||
|
||||
Documentation: https://ts.llamaindex.ai/
|
||||
|
||||
## 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.
|
||||
|
||||
## Getting started with an example:
|
||||
|
||||
LlamaIndex.TS requires Node v18 or higher. You can download it from https://nodejs.org or use https://nvm.sh (our preferred option).
|
||||
|
||||
In a new folder:
|
||||
|
||||
```bash
|
||||
export OPENAI_API_KEY="sk-......" # Replace with your key from https://platform.openai.com/account/api-keys
|
||||
pnpm init
|
||||
pnpm install typescript
|
||||
pnpm exec tsc --init # if needed
|
||||
pnpm install llamaindex
|
||||
pnpm install @types/node
|
||||
```
|
||||
|
||||
Create the file example.ts
|
||||
|
||||
```ts
|
||||
// example.ts
|
||||
import fs from "fs/promises";
|
||||
import { Document, VectorStoreIndex } from "llamaindex";
|
||||
|
||||
async function main() {
|
||||
// Load essay from abramov.txt in Node
|
||||
const essay = await fs.readFile(
|
||||
"node_modules/llamaindex/examples/abramov.txt",
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
// Create Document object with essay
|
||||
const document = new Document({ text: essay });
|
||||
|
||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||
const index = await VectorStoreIndex.fromDocuments([document]);
|
||||
|
||||
// Query the index
|
||||
const queryEngine = index.asQueryEngine();
|
||||
const response = await queryEngine.query(
|
||||
"What did the author do in college?",
|
||||
);
|
||||
|
||||
// Output response
|
||||
console.log(response.toString());
|
||||
}
|
||||
|
||||
main();
|
||||
```
|
||||
|
||||
Then you can run it using
|
||||
|
||||
```bash
|
||||
pnpx ts-node example.ts
|
||||
```
|
||||
|
||||
## Playground
|
||||
|
||||
Check out our NextJS playground at https://llama-playground.vercel.app/. The source is available at https://github.com/run-llama/ts-playground
|
||||
|
||||
## Core concepts for getting started:
|
||||
|
||||
- [Document](/packages/core/src/Node.ts): A document represents a text file, PDF file or other contiguous piece of data.
|
||||
|
||||
- [Node](/packages/core/src/Node.ts): The basic data building block. Most commonly, these are parts of the document split into manageable pieces that are small enough to be fed into an embedding model and LLM.
|
||||
|
||||
- [Embedding](/packages/core/src/Embedding.ts): Embeddings are sets of floating point numbers which represent the data in a Node. By comparing the similarity of embeddings, we can derive an understanding of the similarity of two pieces of data. One use case is to compare the embedding of a question with the embeddings of our Nodes to see which Nodes may contain the data needed to answer that quesiton.
|
||||
|
||||
- [Indices](/packages/core/src/indices/): Indices store the Nodes and the embeddings of those nodes. QueryEngines retrieve Nodes from these Indices using embedding similarity.
|
||||
|
||||
- [QueryEngine](/packages/core/src/QueryEngine.ts): Query engines are what generate the query you put in and give you back the result. Query engines generally combine a pre-built prompt with selected Nodes from your Index to give the LLM the context it needs to answer your query.
|
||||
|
||||
- [ChatEngine](/packages/core/src/ChatEngine.ts): A ChatEngine helps you build a chatbot that will interact with your Indices.
|
||||
|
||||
- [SimplePrompt](/packages/core/src/Prompt.ts): A simple standardized function call definition that takes in inputs and formats them in a template literal. SimplePrompts can be specialized using currying and combined using other SimplePrompt functions.
|
||||
|
||||
## Note: NextJS:
|
||||
|
||||
If you're using NextJS App Router, you'll need to use the NodeJS runtime (default) and add the following config to your next.config.js to have it use imports/exports in the same way Node does.
|
||||
|
||||
```js
|
||||
export const runtime = "nodejs"; // default
|
||||
```
|
||||
|
||||
```js
|
||||
// next.config.js
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
webpack: (config) => {
|
||||
config.resolve.alias = {
|
||||
...config.resolve.alias,
|
||||
sharp$: false,
|
||||
"onnxruntime-node$": false,
|
||||
};
|
||||
return config;
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = nextConfig;
|
||||
```
|
||||
|
||||
## Supported LLMs:
|
||||
|
||||
- OpenAI GPT-3.5-turbo and GPT-4
|
||||
- Anthropic Claude Instant and Claude 2
|
||||
- Llama2 Chat LLMs (70B, 13B, and 7B parameters)
|
||||
- MistralAI Chat LLMs
|
||||
|
||||
## Contributing:
|
||||
|
||||
We are in the very early days of LlamaIndex.TS. If you’re interested in hacking on it with us check out our [contributing guide](/CONTRIBUTING.md)
|
||||
|
||||
## Bugs? Questions?
|
||||
|
||||
Please join our Discord! https://discord.com/invite/eN6D2HQ4aX
|
||||
+24
-152
@@ -1,16 +1,17 @@
|
||||
{
|
||||
"name": "llamaindex",
|
||||
"version": "0.0.50",
|
||||
"private": true,
|
||||
"version": "0.1.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@anthropic-ai/sdk": "^0.9.1",
|
||||
"@datastax/astra-db-ts": "^0.1.2",
|
||||
"@mistralai/mistralai": "^0.0.7",
|
||||
"@anthropic-ai/sdk": "^0.12.4",
|
||||
"@datastax/astra-db-ts": "^0.1.4",
|
||||
"@mistralai/mistralai": "^0.0.10",
|
||||
"@notionhq/client": "^2.2.14",
|
||||
"@pinecone-database/pinecone": "^1.1.2",
|
||||
"@pinecone-database/pinecone": "^1.1.3",
|
||||
"@qdrant/js-client-rest": "^1.7.0",
|
||||
"@xenova/transformers": "^2.10.0",
|
||||
"assemblyai": "^4.0.0",
|
||||
"@xenova/transformers": "^2.14.1",
|
||||
"assemblyai": "^4.2.1",
|
||||
"chromadb": "~1.7.3",
|
||||
"file-type": "^18.7.0",
|
||||
"js-tiktoken": "^1.0.8",
|
||||
@@ -19,26 +20,28 @@
|
||||
"md-utils-ts": "^2.0.0",
|
||||
"mongodb": "^6.3.0",
|
||||
"notion-md-crawler": "^0.0.2",
|
||||
"openai": "^4.20.1",
|
||||
"openai": "^4.26.0",
|
||||
"papaparse": "^5.4.1",
|
||||
"pathe": "^1.1.2",
|
||||
"pdfjs-dist": "4.0.269",
|
||||
"pg": "^8.11.3",
|
||||
"pgvector": "^0.1.5",
|
||||
"pgvector": "^0.1.7",
|
||||
"portkey-ai": "^0.1.16",
|
||||
"rake-modified": "^1.0.8",
|
||||
"replicate": "^0.21.1",
|
||||
"string-strip-html": "^13.4.3",
|
||||
"replicate": "^0.25.2",
|
||||
"string-strip-html": "^13.4.5",
|
||||
"wink-nlp": "^1.14.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@aws-crypto/sha256-js": "^5.2.0",
|
||||
"@types/edit-json-file": "^1.7.3",
|
||||
"@types/jest": "^29.5.11",
|
||||
"@types/lodash": "^4.14.202",
|
||||
"@types/node": "^18.19.6",
|
||||
"@types/node": "^18.19.9",
|
||||
"@types/papaparse": "^5.3.14",
|
||||
"@types/pg": "^8.10.9",
|
||||
"bunchee": "^4.4.1",
|
||||
"@types/pg": "^8.11.0",
|
||||
"bunchee": "^4.4.2",
|
||||
"edit-json-file": "^1.8.0",
|
||||
"madge": "^6.1.0",
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
@@ -50,154 +53,19 @@
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.mts",
|
||||
"edge-light": "./dist/index.edge-light.mjs",
|
||||
"import": "./dist/index.mjs",
|
||||
"edge-light": "./dist/index.mjs",
|
||||
"require": "./dist/index.js"
|
||||
},
|
||||
"./env": {
|
||||
"types": "./dist/env.d.mts",
|
||||
"edge-light": "./dist/env.edge-light.mjs",
|
||||
"import": "./dist/env.mjs",
|
||||
"edge-light": "./dist/env.mjs",
|
||||
"require": "./dist/env.js"
|
||||
},
|
||||
"./storage/FileSystem": {
|
||||
"types": "./dist/storage/FileSystem.d.mts",
|
||||
"edge-light": "./dist/storage/FileSystem.edge-light.mjs",
|
||||
"import": "./dist/storage/FileSystem.mjs",
|
||||
"require": "./dist/storage/FileSystem.js"
|
||||
},
|
||||
"./ChatHistory": {
|
||||
"types": "./dist/ChatHistory.d.mts",
|
||||
"import": "./dist/ChatHistory.mjs",
|
||||
"require": "./dist/ChatHistory.js"
|
||||
},
|
||||
"./constants": {
|
||||
"types": "./dist/constants.d.mts",
|
||||
"import": "./dist/constants.mjs",
|
||||
"require": "./dist/constants.js"
|
||||
},
|
||||
"./GlobalsHelper": {
|
||||
"types": "./dist/GlobalsHelper.d.mts",
|
||||
"import": "./dist/GlobalsHelper.mjs",
|
||||
"require": "./dist/GlobalsHelper.js"
|
||||
},
|
||||
"./Node": {
|
||||
"types": "./dist/Node.d.mts",
|
||||
"import": "./dist/Node.mjs",
|
||||
"require": "./dist/Node.js"
|
||||
},
|
||||
"./OutputParser": {
|
||||
"types": "./dist/OutputParser.d.mts",
|
||||
"import": "./dist/OutputParser.mjs",
|
||||
"require": "./dist/OutputParser.js"
|
||||
},
|
||||
"./Prompt": {
|
||||
"types": "./dist/Prompt.d.mts",
|
||||
"import": "./dist/Prompt.mjs",
|
||||
"require": "./dist/Prompt.js"
|
||||
},
|
||||
"./PromptHelper": {
|
||||
"types": "./dist/PromptHelper.d.mts",
|
||||
"import": "./dist/PromptHelper.mjs",
|
||||
"require": "./dist/PromptHelper.js"
|
||||
},
|
||||
"./QueryEngine": {
|
||||
"types": "./dist/QueryEngine.d.mts",
|
||||
"import": "./dist/QueryEngine.mjs",
|
||||
"require": "./dist/QueryEngine.js"
|
||||
},
|
||||
"./QuestionGenerator": {
|
||||
"types": "./dist/QuestionGenerator.d.mts",
|
||||
"import": "./dist/QuestionGenerator.mjs",
|
||||
"require": "./dist/QuestionGenerator.js"
|
||||
},
|
||||
"./Response": {
|
||||
"types": "./dist/Response.d.mts",
|
||||
"import": "./dist/Response.mjs",
|
||||
"require": "./dist/Response.js"
|
||||
},
|
||||
"./Retriever": {
|
||||
"types": "./dist/Retriever.d.mts",
|
||||
"import": "./dist/Retriever.mjs",
|
||||
"require": "./dist/Retriever.js"
|
||||
},
|
||||
"./ServiceContext": {
|
||||
"types": "./dist/ServiceContext.d.mts",
|
||||
"import": "./dist/ServiceContext.mjs",
|
||||
"require": "./dist/ServiceContext.js"
|
||||
},
|
||||
"./TextSplitter": {
|
||||
"types": "./dist/TextSplitter.d.mts",
|
||||
"import": "./dist/TextSplitter.mjs",
|
||||
"require": "./dist/TextSplitter.js"
|
||||
},
|
||||
"./Tool": {
|
||||
"types": "./dist/Tool.d.mts",
|
||||
"import": "./dist/Tool.mjs",
|
||||
"require": "./dist/Tool.js"
|
||||
},
|
||||
"./readers/AssemblyAI": {
|
||||
"types": "./dist/readers/AssemblyAI.d.mts",
|
||||
"import": "./dist/readers/AssemblyAI.mjs",
|
||||
"require": "./dist/readers/AssemblyAI.js"
|
||||
},
|
||||
"./readers/base": {
|
||||
"types": "./dist/readers/base.d.mts",
|
||||
"import": "./dist/readers/base.mjs",
|
||||
"require": "./dist/readers/base.js"
|
||||
},
|
||||
"./readers/CSVReader": {
|
||||
"types": "./dist/readers/CSVReader.d.mts",
|
||||
"import": "./dist/readers/CSVReader.mjs",
|
||||
"require": "./dist/readers/CSVReader.js"
|
||||
},
|
||||
"./readers/DocxReader": {
|
||||
"types": "./dist/readers/DocxReader.d.mts",
|
||||
"import": "./dist/readers/DocxReader.mjs",
|
||||
"require": "./dist/readers/DocxReader.js"
|
||||
},
|
||||
"./readers/HTMLReader": {
|
||||
"types": "./dist/readers/HTMLReader.d.mts",
|
||||
"import": "./dist/readers/HTMLReader.mjs",
|
||||
"require": "./dist/readers/HTMLReader.js"
|
||||
},
|
||||
"./readers/ImageReader": {
|
||||
"types": "./dist/readers/ImageReader.d.mts",
|
||||
"import": "./dist/readers/ImageReader.mjs",
|
||||
"require": "./dist/readers/ImageReader.js"
|
||||
},
|
||||
"./readers/MarkdownReader": {
|
||||
"types": "./dist/readers/MarkdownReader.d.mts",
|
||||
"import": "./dist/readers/MarkdownReader.mjs",
|
||||
"require": "./dist/readers/MarkdownReader.js"
|
||||
},
|
||||
"./readers/NotionReader": {
|
||||
"types": "./dist/readers/NotionReader.d.mts",
|
||||
"import": "./dist/readers/NotionReader.mjs",
|
||||
"require": "./dist/readers/NotionReader.js"
|
||||
},
|
||||
"./readers/PDFReader": {
|
||||
"types": "./dist/readers/PDFReader.d.mts",
|
||||
"import": "./dist/readers/PDFReader.mjs",
|
||||
"require": "./dist/readers/PDFReader.js"
|
||||
},
|
||||
"./readers/SimpleDirectoryReader": {
|
||||
"types": "./dist/readers/SimpleDirectoryReader.d.mts",
|
||||
"import": "./dist/readers/SimpleDirectoryReader.mjs",
|
||||
"require": "./dist/readers/SimpleDirectoryReader.js"
|
||||
},
|
||||
"./readers/SimpleMongoReader": {
|
||||
"types": "./dist/readers/SimpleMongoReader.d.mts",
|
||||
"import": "./dist/readers/SimpleMongoReader.mjs",
|
||||
"require": "./dist/readers/SimpleMongoReader.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"examples",
|
||||
"src",
|
||||
"types",
|
||||
"CHANGELOG.md"
|
||||
"**"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -208,6 +76,10 @@
|
||||
"lint": "eslint .",
|
||||
"test": "jest",
|
||||
"build": "bunchee",
|
||||
"postbuild": "pnpm run copy && pnpm run modify-package-json",
|
||||
"copy": "cp -r package.json CHANGELOG.md ../../README.md ../../LICENSE examples src dist/",
|
||||
"modify-package-json": "node ./scripts/modify-package-json.mjs",
|
||||
"prepublish": "pnpm run modify-package-json && echo \"please cd ./dist and run pnpm publish\" && exit 1",
|
||||
"dev": "bunchee -w",
|
||||
"circular-check": "madge --circular ./src/*.ts"
|
||||
}
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* This script is used to modify the package.json file in the dist folder
|
||||
* so that it can be published to npm.
|
||||
*/
|
||||
import editJsonFile from "edit-json-file";
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
{
|
||||
await fs.copyFile("./package.json", "./dist/package.json");
|
||||
const file = editJsonFile("./dist/package.json");
|
||||
|
||||
file.unset("scripts");
|
||||
file.unset("private");
|
||||
await new Promise((resolve) => file.save(resolve));
|
||||
}
|
||||
{
|
||||
const packageJson = await fs.readFile("./dist/package.json", "utf8");
|
||||
const modifiedPackageJson = packageJson.replaceAll("./dist/", "./");
|
||||
await fs.writeFile(
|
||||
"./dist/package.json",
|
||||
JSON.stringify(JSON.parse(modifiedPackageJson), null, 2),
|
||||
"utf8",
|
||||
);
|
||||
}
|
||||
@@ -6,6 +6,4 @@ export const DEFAULT_CHUNK_OVERLAP = 20;
|
||||
export const DEFAULT_CHUNK_OVERLAP_RATIO = 0.1;
|
||||
export const DEFAULT_SIMILARITY_TOP_K = 2;
|
||||
|
||||
// NOTE: for text-embedding-ada-002
|
||||
export const DEFAULT_EMBEDDING_DIM = 1536;
|
||||
export const DEFAULT_PADDING = 5;
|
||||
|
||||
@@ -9,28 +9,55 @@ import {
|
||||
import { OpenAISession, getOpenAISession } from "../llm/openai";
|
||||
import { BaseEmbedding } from "./types";
|
||||
|
||||
export enum OpenAIEmbeddingModelType {
|
||||
TEXT_EMBED_ADA_002 = "text-embedding-ada-002",
|
||||
}
|
||||
export const ALL_OPENAI_EMBEDDING_MODELS = {
|
||||
"text-embedding-ada-002": {
|
||||
dimensions: 1536,
|
||||
maxTokens: 8191,
|
||||
},
|
||||
"text-embedding-3-small": {
|
||||
dimensions: 1536,
|
||||
dimensionOptions: [512, 1536],
|
||||
maxTokens: 8191,
|
||||
},
|
||||
"text-embedding-3-large": {
|
||||
dimensions: 3072,
|
||||
dimensionOptions: [256, 1024, 3072],
|
||||
maxTokens: 8191,
|
||||
},
|
||||
};
|
||||
|
||||
export class OpenAIEmbedding extends BaseEmbedding {
|
||||
model: OpenAIEmbeddingModelType | string;
|
||||
/** embeddding model. defaults to "text-embedding-ada-002" */
|
||||
model: string;
|
||||
/** number of dimensions of the resulting vector, for models that support choosing fewer dimensions. undefined will default to model default */
|
||||
dimensions: number | undefined;
|
||||
|
||||
// OpenAI session params
|
||||
|
||||
/** api key */
|
||||
apiKey?: string = undefined;
|
||||
/** maximum number of retries, default 10 */
|
||||
maxRetries: number;
|
||||
/** timeout in ms, default 60 seconds */
|
||||
timeout?: number;
|
||||
/** other session options for OpenAI */
|
||||
additionalSessionOptions?: Omit<
|
||||
Partial<OpenAIClientOptions>,
|
||||
"apiKey" | "maxRetries" | "timeout"
|
||||
>;
|
||||
|
||||
/** session object */
|
||||
session: OpenAISession;
|
||||
|
||||
/**
|
||||
* OpenAI Embedding
|
||||
* @param init - initial parameters
|
||||
*/
|
||||
constructor(init?: Partial<OpenAIEmbedding> & { azure?: AzureOpenAIConfig }) {
|
||||
super();
|
||||
|
||||
this.model = init?.model ?? OpenAIEmbeddingModelType.TEXT_EMBED_ADA_002;
|
||||
this.model = init?.model ?? "text-embedding-ada-002";
|
||||
this.dimensions = init?.dimensions; // if no dimensions provided, will be undefined/not sent to OpenAI
|
||||
|
||||
this.maxRetries = init?.maxRetries ?? 10;
|
||||
this.timeout = init?.timeout ?? 60 * 1000; // Default is 60 seconds
|
||||
@@ -76,6 +103,7 @@ export class OpenAIEmbedding extends BaseEmbedding {
|
||||
private async getOpenAIEmbedding(input: string) {
|
||||
const { data } = await this.session.openai.embeddings.create({
|
||||
model: this.model,
|
||||
dimensions: this.dimensions, // only sent to OpenAI if set by user
|
||||
input,
|
||||
});
|
||||
|
||||
|
||||
@@ -41,14 +41,21 @@ import {
|
||||
export const GPT4_MODELS = {
|
||||
"gpt-4": { contextWindow: 8192 },
|
||||
"gpt-4-32k": { contextWindow: 32768 },
|
||||
"gpt-4-32k-0613": { contextWindow: 32768 },
|
||||
"gpt-4-turbo-preview": { contextWindow: 128000 },
|
||||
"gpt-4-1106-preview": { contextWindow: 128000 },
|
||||
"gpt-4-vision-preview": { contextWindow: 8192 },
|
||||
"gpt-4-0125-preview": { contextWindow: 128000 },
|
||||
"gpt-4-vision-preview": { contextWindow: 128000 },
|
||||
};
|
||||
|
||||
// NOTE we don't currently support gpt-3.5-turbo-instruct and don't plan to in the near future
|
||||
export const GPT35_MODELS = {
|
||||
"gpt-3.5-turbo": { contextWindow: 4096 },
|
||||
"gpt-3.5-turbo-0613": { contextWindow: 4096 },
|
||||
"gpt-3.5-turbo-16k": { contextWindow: 16384 },
|
||||
"gpt-3.5-turbo-16k-0613": { contextWindow: 16384 },
|
||||
"gpt-3.5-turbo-1106": { contextWindow: 16384 },
|
||||
"gpt-3.5-turbo-0125": { contextWindow: 16384 },
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,14 @@ const ALL_AZURE_OPENAI_CHAT_MODELS = {
|
||||
},
|
||||
"gpt-4": { contextWindow: 8192, openAIModel: "gpt-4" },
|
||||
"gpt-4-32k": { contextWindow: 32768, openAIModel: "gpt-4-32k" },
|
||||
"gpt-4-vision-preview": {
|
||||
contextWindow: 128000,
|
||||
openAIModel: "gpt-4-vision-preview",
|
||||
},
|
||||
"gpt-4-1106-preview": {
|
||||
contextWindow: 128000,
|
||||
openAIModel: "gpt-4-1106-preview",
|
||||
},
|
||||
};
|
||||
|
||||
const ALL_AZURE_OPENAI_EMBEDDING_MODELS = {
|
||||
@@ -25,13 +33,29 @@ const ALL_AZURE_OPENAI_EMBEDDING_MODELS = {
|
||||
openAIModel: "text-embedding-ada-002",
|
||||
maxTokens: 8191,
|
||||
},
|
||||
"text-embedding-3-small": {
|
||||
dimensions: 1536,
|
||||
dimensionOptions: [512, 1536],
|
||||
openAIModel: "text-embedding-3-small",
|
||||
maxTokens: 8191,
|
||||
},
|
||||
"text-embedding-3-large": {
|
||||
dimensions: 3072,
|
||||
dimensionOptions: [256, 1024, 3072],
|
||||
openAIModel: "text-embedding-3-large",
|
||||
maxTokens: 8191,
|
||||
},
|
||||
};
|
||||
|
||||
const ALL_AZURE_API_VERSIONS = [
|
||||
"2022-12-01",
|
||||
"2023-05-15",
|
||||
"2023-06-01-preview",
|
||||
"2023-07-01-preview",
|
||||
"2023-03-15-preview", // retiring 2024-04-02
|
||||
"2023-06-01-preview", // retiring 2024-04-02
|
||||
"2023-07-01-preview", // retiring 2024-04-02
|
||||
"2023-08-01-preview", // retiring 2024-04-02
|
||||
"2023-09-01-preview",
|
||||
"2023-12-01-preview",
|
||||
];
|
||||
|
||||
const DEFAULT_API_VERSION = "2023-05-15";
|
||||
|
||||
@@ -20,6 +20,7 @@ export class PGVectorStore implements VectorStore {
|
||||
private schemaName: string = PGVECTOR_SCHEMA;
|
||||
private tableName: string = PGVECTOR_TABLE;
|
||||
private connectionString: string | undefined = undefined;
|
||||
private dimensions: number = 1536;
|
||||
|
||||
private db?: pg.Client;
|
||||
|
||||
@@ -38,15 +39,18 @@ export class PGVectorStore implements VectorStore {
|
||||
* @param {string} config.schemaName - The name of the schema (optional). Defaults to PGVECTOR_SCHEMA.
|
||||
* @param {string} config.tableName - The name of the table (optional). Defaults to PGVECTOR_TABLE.
|
||||
* @param {string} config.connectionString - The connection string (optional).
|
||||
* @param {number} config.dimensions - The dimensions of the embedding model.
|
||||
*/
|
||||
constructor(config?: {
|
||||
schemaName?: string;
|
||||
tableName?: string;
|
||||
connectionString?: string;
|
||||
dimensions?: number;
|
||||
}) {
|
||||
this.schemaName = config?.schemaName ?? PGVECTOR_SCHEMA;
|
||||
this.tableName = config?.tableName ?? PGVECTOR_TABLE;
|
||||
this.connectionString = config?.connectionString;
|
||||
this.dimensions = config?.dimensions ?? 1536;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +112,7 @@ export class PGVectorStore implements VectorStore {
|
||||
collection VARCHAR,
|
||||
document TEXT,
|
||||
metadata JSONB DEFAULT '{}',
|
||||
embeddings VECTOR(1536)
|
||||
embeddings VECTOR(${this.dimensions})
|
||||
)`;
|
||||
await db.query(tbl);
|
||||
|
||||
|
||||
@@ -54,11 +54,9 @@ export class QdrantVectorStore implements VectorStore {
|
||||
apiKey,
|
||||
batchSize,
|
||||
}: QdrantParams) {
|
||||
if (!client && (!url || !apiKey)) {
|
||||
if (!url || !apiKey || !collectionName) {
|
||||
throw new Error(
|
||||
"QdrantVectorStore requires url, apiKey and collectionName",
|
||||
);
|
||||
if (!client && !url) {
|
||||
if (!url || !collectionName) {
|
||||
throw new Error("QdrantVectorStore requires url and collectionName");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
-3
@@ -1,3 +0,0 @@
|
||||
declare module "@mistralai/mistralai" {
|
||||
export = MistralClient;
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
# create-llama
|
||||
|
||||
## 0.0.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 3a29a80: Add node_modules to gitignore in Express backends
|
||||
- fe03aaa: feat: generate llama pack example
|
||||
|
||||
## 0.0.18
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -32,6 +32,7 @@ export async function createApp({
|
||||
openAiKey,
|
||||
model,
|
||||
communityProjectPath,
|
||||
llamapack,
|
||||
vectorDb,
|
||||
externalPort,
|
||||
postInstallAction,
|
||||
@@ -75,6 +76,7 @@ export async function createApp({
|
||||
openAiKey,
|
||||
model,
|
||||
communityProjectPath,
|
||||
llamapack,
|
||||
vectorDb,
|
||||
externalPort,
|
||||
postInstallAction,
|
||||
|
||||
@@ -1,2 +1,6 @@
|
||||
export const COMMUNITY_OWNER = "run-llama";
|
||||
export const COMMUNITY_REPO = "create_llama_projects";
|
||||
export const LLAMA_PACK_OWNER = "run-llama";
|
||||
export const LLAMA_PACK_REPO = "llama-hub";
|
||||
export const LLAMA_HUB_FOLDER_PATH = `${LLAMA_PACK_OWNER}/${LLAMA_PACK_REPO}/main/llama_hub`;
|
||||
export const LLAMA_PACK_CONFIG_PATH = `${LLAMA_HUB_FOLDER_PATH}/llama_packs/library.json`;
|
||||
|
||||
@@ -7,6 +7,7 @@ import { cyan } from "picocolors";
|
||||
|
||||
import { COMMUNITY_OWNER, COMMUNITY_REPO } from "./constant";
|
||||
import { PackageManager } from "./get-pkg-manager";
|
||||
import { installLlamapackProject } from "./llama-pack";
|
||||
import { isHavingPoetryLockFile, tryPoetryRun } from "./poetry";
|
||||
import { installPythonTemplate } from "./python";
|
||||
import { downloadAndExtractRepo } from "./repo";
|
||||
@@ -153,6 +154,11 @@ export const installTemplate = async (
|
||||
return;
|
||||
}
|
||||
|
||||
if (props.template === "llamapack" && props.llamapack) {
|
||||
await installLlamapackProject(props);
|
||||
return;
|
||||
}
|
||||
|
||||
if (props.framework === "fastapi") {
|
||||
await installPythonTemplate(props);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
import { LLAMA_HUB_FOLDER_PATH, LLAMA_PACK_CONFIG_PATH } from "./constant";
|
||||
import { copy } from "./copy";
|
||||
import { installPythonDependencies } from "./python";
|
||||
import { getRepoRawContent } from "./repo";
|
||||
import { InstallTemplateArgs } from "./types";
|
||||
|
||||
export async function getAvailableLlamapackOptions(): Promise<
|
||||
{
|
||||
name: string;
|
||||
folderPath: string;
|
||||
example: boolean | undefined;
|
||||
}[]
|
||||
> {
|
||||
const libraryJsonRaw = await getRepoRawContent(LLAMA_PACK_CONFIG_PATH);
|
||||
const libraryJson = JSON.parse(libraryJsonRaw);
|
||||
const llamapackKeys = Object.keys(libraryJson);
|
||||
return llamapackKeys
|
||||
.map((key) => ({
|
||||
name: key,
|
||||
folderPath: libraryJson[key].id,
|
||||
example: libraryJson[key].example,
|
||||
}))
|
||||
.filter((item) => !!item.example);
|
||||
}
|
||||
|
||||
const copyLlamapackEmptyProject = async ({
|
||||
root,
|
||||
}: Pick<InstallTemplateArgs, "root">) => {
|
||||
const templatePath = path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
"templates/components/sample-projects/llamapack",
|
||||
);
|
||||
await copy("**", root, {
|
||||
parents: true,
|
||||
cwd: templatePath,
|
||||
});
|
||||
};
|
||||
|
||||
const copyData = async ({
|
||||
root,
|
||||
}: Pick<InstallTemplateArgs, "root" | "llamapack">) => {
|
||||
const dataPath = path.join(__dirname, "..", "templates/components/data");
|
||||
await copy("**", path.join(root, "data"), {
|
||||
parents: true,
|
||||
cwd: dataPath,
|
||||
});
|
||||
};
|
||||
|
||||
const installLlamapackExample = async ({
|
||||
root,
|
||||
llamapack,
|
||||
}: Pick<InstallTemplateArgs, "root" | "llamapack">) => {
|
||||
const exampleFileName = "example.py";
|
||||
const readmeFileName = "README.md";
|
||||
const exampleFilePath = `${LLAMA_HUB_FOLDER_PATH}/${llamapack}/${exampleFileName}`;
|
||||
const readmeFilePath = `${LLAMA_HUB_FOLDER_PATH}/${llamapack}/${readmeFileName}`;
|
||||
|
||||
// Download example.py from llamapack and save to root
|
||||
const exampleContent = await getRepoRawContent(exampleFilePath);
|
||||
await fs.writeFile(path.join(root, exampleFileName), exampleContent);
|
||||
|
||||
// Download README.md from llamapack and combine with README-template.md,
|
||||
// save to root and then delete template file
|
||||
const readmeContent = await getRepoRawContent(readmeFilePath);
|
||||
const readmeTemplateContent = await fs.readFile(
|
||||
path.join(root, "README-template.md"),
|
||||
"utf-8",
|
||||
);
|
||||
await fs.writeFile(
|
||||
path.join(root, readmeFileName),
|
||||
`${readmeContent}\n${readmeTemplateContent}`,
|
||||
);
|
||||
await fs.unlink(path.join(root, "README-template.md"));
|
||||
};
|
||||
|
||||
export const installLlamapackProject = async ({
|
||||
root,
|
||||
llamapack,
|
||||
postInstallAction,
|
||||
}: Pick<InstallTemplateArgs, "root" | "llamapack" | "postInstallAction">) => {
|
||||
console.log("\nInstalling Llamapack project:", llamapack!);
|
||||
await copyLlamapackEmptyProject({ root });
|
||||
await copyData({ root });
|
||||
await installLlamapackExample({ root, llamapack });
|
||||
if (postInstallAction !== "none") {
|
||||
installPythonDependencies({ noRoot: true });
|
||||
}
|
||||
};
|
||||
@@ -10,9 +10,11 @@ export function isPoetryAvailable(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function tryPoetryInstall(): boolean {
|
||||
export function tryPoetryInstall(noRoot: boolean): boolean {
|
||||
try {
|
||||
execSync("poetry install", { stdio: "inherit" });
|
||||
execSync(`poetry install${noRoot ? " --no-root" : ""}`, {
|
||||
stdio: "inherit",
|
||||
});
|
||||
return true;
|
||||
} catch (_) {}
|
||||
return false;
|
||||
|
||||
@@ -92,12 +92,14 @@ export const addDependencies = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const installPythonDependencies = (root: string) => {
|
||||
export const installPythonDependencies = (
|
||||
{ noRoot }: { noRoot: boolean } = { noRoot: false },
|
||||
) => {
|
||||
if (isPoetryAvailable()) {
|
||||
console.log(
|
||||
`Installing python dependencies using poetry. This may take a while...`,
|
||||
);
|
||||
const installSuccessful = tryPoetryInstall();
|
||||
const installSuccessful = tryPoetryInstall(noRoot);
|
||||
if (!installSuccessful) {
|
||||
console.error(
|
||||
red("Install failed. Please install dependencies manually."),
|
||||
@@ -181,6 +183,6 @@ export const installPythonTemplate = async ({
|
||||
await addDependencies(root, addOnDependencies);
|
||||
|
||||
if (postInstallAction !== "none") {
|
||||
installPythonDependencies(root);
|
||||
installPythonDependencies();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -61,3 +61,11 @@ export async function getRepoRootFolders(
|
||||
const folders = data.filter((item) => item.type === "dir");
|
||||
return folders.map((item) => item.name);
|
||||
}
|
||||
|
||||
export async function getRepoRawContent(repoFilePath: string) {
|
||||
const url = `https://raw.githubusercontent.com/${repoFilePath}`;
|
||||
const response = await got(url, {
|
||||
responseType: "text",
|
||||
});
|
||||
return response.body;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PackageManager } from "../helpers/get-pkg-manager";
|
||||
|
||||
export type TemplateType = "simple" | "streaming" | "community";
|
||||
export type TemplateType = "simple" | "streaming" | "community" | "llamapack";
|
||||
export type TemplateFramework = "nextjs" | "express" | "fastapi";
|
||||
export type TemplateEngine = "simple" | "context";
|
||||
export type TemplateUI = "html" | "shadcn";
|
||||
@@ -23,6 +23,7 @@ export interface InstallTemplateArgs {
|
||||
forBackend?: string;
|
||||
model: string;
|
||||
communityProjectPath?: string;
|
||||
llamapack?: string;
|
||||
vectorDb?: TemplateVectorDB;
|
||||
externalPort?: number;
|
||||
postInstallAction?: TemplatePostInstallAction;
|
||||
|
||||
@@ -237,6 +237,7 @@ async function run(): Promise<void> {
|
||||
openAiKey: program.openAiKey,
|
||||
model: program.model,
|
||||
communityProjectPath: program.communityProjectPath,
|
||||
llamapack: program.llamapack,
|
||||
vectorDb: program.vectorDb,
|
||||
externalPort: program.externalPort,
|
||||
postInstallAction: program.postInstallAction,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "create-llama",
|
||||
"version": "0.0.18",
|
||||
"version": "0.0.19",
|
||||
"keywords": [
|
||||
"rag",
|
||||
"llamaindex",
|
||||
|
||||
@@ -7,6 +7,7 @@ import prompts from "prompts";
|
||||
import { InstallAppArgs } from "./create-app";
|
||||
import { TemplateFramework } from "./helpers";
|
||||
import { COMMUNITY_OWNER, COMMUNITY_REPO } from "./helpers/constant";
|
||||
import { getAvailableLlamapackOptions } from "./helpers/llama-pack";
|
||||
import { getRepoRootFolders } from "./helpers/repo";
|
||||
|
||||
export type QuestionArgs = Omit<InstallAppArgs, "appPath" | "packageManager">;
|
||||
@@ -37,6 +38,7 @@ const defaults: QuestionArgs = {
|
||||
openAiKey: "",
|
||||
model: "gpt-3.5-turbo",
|
||||
communityProjectPath: "",
|
||||
llamapack: "",
|
||||
postInstallAction: "dependencies",
|
||||
};
|
||||
|
||||
@@ -129,6 +131,48 @@ export const askQuestions = async (
|
||||
field: K,
|
||||
): QuestionArgs[K] => preferences[field] ?? defaults[field];
|
||||
|
||||
// Ask for next action after installation
|
||||
async function askPostInstallAction() {
|
||||
if (program.postInstallAction === undefined) {
|
||||
if (ciInfo.isCI) {
|
||||
program.postInstallAction = getPrefOrDefault("postInstallAction");
|
||||
} else {
|
||||
let actionChoices = [
|
||||
{
|
||||
title: "Just generate code (~1 sec)",
|
||||
value: "none",
|
||||
},
|
||||
{
|
||||
title: "Generate code and install dependencies (~2 min)",
|
||||
value: "dependencies",
|
||||
},
|
||||
];
|
||||
|
||||
const hasOpenAiKey = program.openAiKey || process.env["OPENAI_API_KEY"];
|
||||
if (program.vectorDb === "none" && hasOpenAiKey) {
|
||||
actionChoices.push({
|
||||
title:
|
||||
"Generate code, install dependencies, and run the app (~2 min)",
|
||||
value: "runApp",
|
||||
});
|
||||
}
|
||||
|
||||
const { action } = await prompts(
|
||||
{
|
||||
type: "select",
|
||||
name: "action",
|
||||
message: "How would you like to proceed?",
|
||||
choices: actionChoices,
|
||||
initial: 1,
|
||||
},
|
||||
handlers,
|
||||
);
|
||||
|
||||
program.postInstallAction = action;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!program.template) {
|
||||
if (ciInfo.isCI) {
|
||||
program.template = getPrefOrDefault("template");
|
||||
@@ -148,6 +192,10 @@ export const askQuestions = async (
|
||||
title: `Community template from ${styledRepo}`,
|
||||
value: "community",
|
||||
},
|
||||
{
|
||||
title: "Example using a LlamaPack",
|
||||
value: "llamapack",
|
||||
},
|
||||
],
|
||||
initial: 1,
|
||||
},
|
||||
@@ -181,6 +229,27 @@ export const askQuestions = async (
|
||||
return; // early return - no further questions needed for community projects
|
||||
}
|
||||
|
||||
if (program.template === "llamapack") {
|
||||
const availableLlamaPacks = await getAvailableLlamapackOptions();
|
||||
const { llamapack } = await prompts(
|
||||
{
|
||||
type: "select",
|
||||
name: "llamapack",
|
||||
message: "Select LlamaPack",
|
||||
choices: availableLlamaPacks.map((pack) => ({
|
||||
title: pack.name,
|
||||
value: pack.folderPath,
|
||||
})),
|
||||
initial: 0,
|
||||
},
|
||||
handlers,
|
||||
);
|
||||
program.llamapack = llamapack;
|
||||
preferences.llamapack = llamapack;
|
||||
await askPostInstallAction();
|
||||
return; // early return - no further questions needed for llamapack projects
|
||||
}
|
||||
|
||||
if (!program.framework) {
|
||||
if (ciInfo.isCI) {
|
||||
program.framework = getPrefOrDefault("framework");
|
||||
@@ -386,45 +455,7 @@ export const askQuestions = async (
|
||||
}
|
||||
}
|
||||
|
||||
// Ask for next action after installation
|
||||
if (program.postInstallAction === undefined) {
|
||||
if (ciInfo.isCI) {
|
||||
program.postInstallAction = getPrefOrDefault("postInstallAction");
|
||||
} else {
|
||||
let actionChoices = [
|
||||
{
|
||||
title: "Just generate code (~1 sec)",
|
||||
value: "none",
|
||||
},
|
||||
{
|
||||
title: "Generate code and install dependencies (~2 min)",
|
||||
value: "dependencies",
|
||||
},
|
||||
];
|
||||
|
||||
const hasOpenAiKey = program.openAiKey || process.env["OPENAI_API_KEY"];
|
||||
if (program.vectorDb === "none" && hasOpenAiKey) {
|
||||
actionChoices.push({
|
||||
title:
|
||||
"Generate code, install dependencies, and run the app (~2 min)",
|
||||
value: "runApp",
|
||||
});
|
||||
}
|
||||
|
||||
const { action } = await prompts(
|
||||
{
|
||||
type: "select",
|
||||
name: "action",
|
||||
message: "How would you like to proceed?",
|
||||
choices: actionChoices,
|
||||
initial: 1,
|
||||
},
|
||||
handlers,
|
||||
);
|
||||
|
||||
program.postInstallAction = action;
|
||||
}
|
||||
}
|
||||
await askPostInstallAction();
|
||||
|
||||
// TODO: consider using zod to validate the input (doesn't work like this as not every option is required)
|
||||
// templateUISchema.parse(program.ui);
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
---
|
||||
|
||||
## Quickstart
|
||||
|
||||
1. Check above instructions for setting up your environment and export required environment variables
|
||||
For example, if you are using bash, you can run the following command to set up OpenAI API key
|
||||
|
||||
```bash
|
||||
export OPENAI_API_KEY=your_api_key
|
||||
```
|
||||
|
||||
2. Run the example
|
||||
|
||||
```
|
||||
poetry run python example.py
|
||||
```
|
||||
@@ -0,0 +1,16 @@
|
||||
[tool.poetry]
|
||||
name = "app"
|
||||
version = "0.1.0"
|
||||
description = "Llama Pack Example"
|
||||
authors = ["Marcus Schiesser <mail@marcusschiesser.de>"]
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.11,<3.12"
|
||||
llama-index = "^0.9.19"
|
||||
python-dotenv = "^1.0.0"
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
@@ -1,2 +1,3 @@
|
||||
# local env files
|
||||
.env
|
||||
node_modules/
|
||||
@@ -1,2 +1,3 @@
|
||||
# local env files
|
||||
.env
|
||||
node_modules/
|
||||
Generated
+789
-282
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user