Compare commits

...

13 Commits

Author SHA1 Message Date
yisding e2b9b66f71 RELEASING: Releasing 2 package(s)
Releases:
  llamaindex@0.1.0
  docs@0.0.1

[skip ci]
2024-01-25 15:47:02 -08:00
yisding bb66cb7e36 Openai embeddings 3 (#445) 2024-01-25 15:45:21 -08:00
Alex Yang 2159e77c9d RELEASING: Releasing 1 package(s)
Releases:
  llamaindex@0.0.51

[skip ci]
2024-01-25 14:59:22 -06:00
Emanuel Ferreira 3154f521d9 chore: add qdrant readme (#444) 2024-01-25 17:58:37 -03:00
Alex Yang fda8024607 revert: export conditions not working with moduleResolution node (#443) 2024-01-25 13:51:05 -06:00
Marcus Schiesser 89336e4ddf feat: add deno jupyter examples (#428) 2024-01-25 18:09:19 +07:00
Marcus Schiesser a94f747307 RELEASING: Releasing 1 package(s)
Releases:
  create-llama@0.0.18

[skip ci]
2024-01-25 17:46:19 +07:00
Marcus Schiesser 88d3b41044 fix: create-llama packaging 2024-01-25 17:44:29 +07:00
Marcus Schiesser 7fd02ab8d1 RELEASING: Releasing 1 package(s)
Releases:
  create-llama@0.0.17

[skip ci]
2024-01-25 16:58:45 +07:00
Huu Le (Lee) 9e5d8e143e Feat: add local pdf file option (#441) 2024-01-25 15:20:42 +07:00
Huu Le (Lee) f0f7df29b3 remove chromadb override (as llamaindex is forcing now chromadb 1.7.3) 2024-01-25 14:24:01 +07:00
yisding 05ba70881c RELEASING: Releasing 1 package(s)
Releases:
  llamaindex@0.0.50

[skip ci]
2024-01-24 23:00:50 -08:00
yisding 8a729cdd0d minor bug fixes with together AI (#440) 2024-01-24 22:59:09 -08:00
36 changed files with 1115 additions and 415 deletions
-5
View File
@@ -1,5 +0,0 @@
---
"create-llama": patch
---
Add an option that allows the user to run the generated app
+1
View File
@@ -1,4 +1,5 @@
apps/docs/i18n
apps/docs/docs/api
pnpm-lock.yaml
lib/
dist/
+7
View File
@@ -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 -1
View File
@@ -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 -1
View File
@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "0.0.0",
"version": "0.0.1",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
+1
View File
@@ -0,0 +1 @@
.ipynb_checkpoints/
+31
View File
@@ -0,0 +1,31 @@
# Jupyter examples
## Preparation
1. Install Deno, e.g. on macOS:
```
brew install deno
```
2. Install Jupyter
```
pip3 install jupyterlab
```
3. Install Deno kernel
```
deno jupyter --unstable --install
```
4. Run Jupyter
```
jupyter lab
```
## Run examples
Then you can open in Jupyter any of the examples in this directory.
+82
View File
@@ -0,0 +1,82 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "8be89595-8885-4d5e-b1da-1df04eda5c7a",
"metadata": {},
"outputs": [],
"source": [
"import {\n",
" Document,\n",
" SimpleNodeParser\n",
"} from \"npm:llamaindex\";"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "65de03f9-455a-4c59-9089-093cb6998af7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\n",
" TextNode {\n",
" id_: \u001b[32m\"1b2ab25e-562a-4821-bdde-860bd23121c1\"\u001b[39m,\n",
" metadata: {},\n",
" excludedEmbedMetadataKeys: [],\n",
" excludedLlmMetadataKeys: [],\n",
" relationships: {\n",
" SOURCE: {\n",
" nodeId: \u001b[32m\"0cb8de0e-845f-4e73-a7bd-f04426aacfed\"\u001b[39m,\n",
" metadata: {},\n",
" hash: \u001b[32m\"jatVVXETDFjV2fV1/fbTrdpY6ZGnSYekq9m1X/Ff1qs=\"\u001b[39m\n",
" }\n",
" },\n",
" hash: \u001b[32m\"zVyeDsfMwWH1CqK2269o5uzGWl/DpIWO4ZcVCuyENi4=\"\u001b[39m,\n",
" text: \u001b[32m\"I am 10 years old. John is 20 years old.\"\u001b[39m,\n",
" metadataSeparator: \u001b[32m\"\\n\"\u001b[39m\n",
" }\n",
"]\n"
]
}
],
"source": [
"const nodeParser = new SimpleNodeParser();\n",
"const nodes = nodeParser.getNodesFromDocuments([\n",
" new Document({ text: \"I am 10 years old. John is 20 years old.\" }),\n",
"]);\n",
"\n",
"console.log(nodes);"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fc0ec12f-2062-47af-916d-7c77ca39433a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Deno",
"language": "typescript",
"name": "deno"
},
"language_info": {
"file_extension": ".ts",
"mimetype": "text/x.typescript",
"name": "typescript",
"nb_converter": "script",
"pygments_lexer": "typescript",
"version": "5.3.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
+83
View File
@@ -0,0 +1,83 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"id": "8be89595-8885-4d5e-b1da-1df04eda5c7a",
"metadata": {},
"outputs": [],
"source": [
"import {\n",
" Document,\n",
" VectorStoreIndex\n",
"} from \"npm:llamaindex\";"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "65de03f9-455a-4c59-9089-093cb6998af7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"In college, the author studied subjects such as linear algebra and physics, but did not find them particularly interesting. They also slacked off and skipped lectures, leading to gaps in their knowledge. They had a negative experience with their English classes and became resentful and suspicious of higher education. They eventually dropped out of college and did not return until five years later to pick up their papers.\n"
]
}
],
"source": [
"// Create Document object with essay\n",
"const resp = await fetch('https://raw.githubusercontent.com/run-llama/LlamaIndexTS/main/packages/core/examples/abramov.txt');\n",
"const text = await resp.text();\n",
"const document = new Document({ text });\n",
"\n",
"// Split text and create embeddings. Store them in a VectorStoreIndex\n",
"const index = await VectorStoreIndex.fromDocuments([document]);\n",
"\n",
"// Query the index\n",
"const queryEngine = index.asQueryEngine();\n",
"const response = await queryEngine.query({\n",
" query: \"What did the author do in college?\",\n",
"});\n",
"\n",
"// Output response\n",
"console.log(response.toString());"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fc0ec12f-2062-47af-916d-7c77ca39433a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "68bdd292-5cf7-46e0-8646-51be1f070ad6",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Deno",
"language": "typescript",
"name": "deno"
},
"language_info": {
"file_extension": ".ts",
"mimetype": "text/x.typescript",
"name": "typescript",
"nb_converter": "script",
"pygments_lexer": "typescript",
"version": "5.3.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
+1
View File
@@ -23,6 +23,7 @@ const together = new TogetherLLM({
for await (const message of generator) {
process.stdout.write(message.delta);
}
console.log();
const embedding = new TogetherEmbedding();
const vector = await embedding.getTextEmbedding("Hello world!");
console.log("vector:", vector);
+41
View File
@@ -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);
+3 -3
View File
@@ -18,7 +18,7 @@
},
"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:*",
@@ -27,8 +27,8 @@
"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",
+22
View File
@@ -1,5 +1,27 @@
# llamaindex
## 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
- 8a729cd: fix bugs in Together.AI integration (thanks @Nutlope for reporting)
## 0.0.49
### Patch Changes
+3 -148
View File
@@ -1,6 +1,6 @@
{
"name": "llamaindex",
"version": "0.0.49",
"version": "0.1.0",
"license": "MIT",
"dependencies": {
"@anthropic-ai/sdk": "^0.9.1",
@@ -11,7 +11,7 @@
"@qdrant/js-client-rest": "^1.7.0",
"@xenova/transformers": "^2.10.0",
"assemblyai": "^4.0.0",
"chromadb": "^1.7.3",
"chromadb": "~1.7.3",
"file-type": "^18.7.0",
"js-tiktoken": "^1.0.8",
"lodash": "^4.17.21",
@@ -19,7 +19,7 @@
"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",
@@ -47,151 +47,6 @@
},
"types": "./dist/index.d.ts",
"main": "./dist/index.js",
"exports": {
".": {
"types": "./dist/index.d.mts",
"edge-light": "./dist/index.edge-light.mjs",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"./env": {
"types": "./dist/env.d.mts",
"edge-light": "./dist/env.edge-light.mjs",
"import": "./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",
-2
View File
@@ -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 = 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,
});
+18 -8
View File
@@ -1,16 +1,26 @@
import { OpenAIEmbedding } from "./OpenAIEmbedding";
export class TogetherEmbedding extends OpenAIEmbedding {
override model: string;
constructor(init?: Partial<OpenAIEmbedding>) {
const {
apiKey = process.env.TOGETHER_API_KEY,
additionalSessionOptions = {},
model = "togethercomputer/m2-bert-80M-32k-retrieval",
...rest
} = init ?? {};
if (!apiKey) {
throw new Error("Set Together Key in TOGETHER_API_KEY env variable"); // Tell user to set correct env variable, and not OPENAI_API_KEY
}
additionalSessionOptions.baseURL =
additionalSessionOptions.baseURL ?? "https://api.together.xyz/v1";
super({
apiKey: process.env.TOGETHER_API_KEY,
...init,
additionalSessionOptions: {
...init?.additionalSessionOptions,
baseURL: "https://api.together.xyz/v1",
},
apiKey,
additionalSessionOptions,
model,
...rest,
});
this.model = init?.model ?? "togethercomputer/m2-bert-80M-32k-retrieval";
}
}
+8 -1
View File
@@ -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 },
};
/**
+26 -2
View File
@@ -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";
+18 -6
View File
@@ -2,13 +2,25 @@ import { OpenAI } from "./LLM";
export class TogetherLLM extends OpenAI {
constructor(init?: Partial<OpenAI>) {
const {
apiKey = process.env.TOGETHER_API_KEY,
additionalSessionOptions = {},
model = "togethercomputer/llama-2-7b-chat",
...rest
} = init ?? {};
if (!apiKey) {
throw new Error("Set Together Key in TOGETHER_API_KEY env variable"); // Tell user to set correct env variable, and not OPENAI_API_KEY
}
additionalSessionOptions.baseURL =
additionalSessionOptions.baseURL ?? "https://api.together.xyz/v1";
super({
...init,
apiKey: process.env.TOGETHER_API_KEY,
additionalSessionOptions: {
...init?.additionalSessionOptions,
baseURL: "https://api.together.xyz/v1",
},
apiKey,
additionalSessionOptions,
model,
...rest,
});
}
}
@@ -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");
}
}
+13
View File
@@ -1,5 +1,18 @@
# create-llama
## 0.0.18
### Patch Changes
- 88d3b41: fix packaging
## 0.0.17
### Patch Changes
- fa17f7e: Add an option that allows the user to run the generated app
- 9e5d8e1: Add an option to select a local PDF file as data source
## 0.0.16
### Patch Changes
+2
View File
@@ -35,6 +35,7 @@ export async function createApp({
vectorDb,
externalPort,
postInstallAction,
contextFile,
}: InstallAppArgs): Promise<void> {
const root = path.resolve(appPath);
@@ -77,6 +78,7 @@ export async function createApp({
vectorDb,
externalPort,
postInstallAction,
contextFile,
};
if (frontend) {
+23 -12
View File
@@ -70,22 +70,32 @@ const copyTestData = async (
engine?: TemplateEngine,
openAiKey?: string,
vectorDb?: TemplateVectorDB,
contextFile?: string,
// eslint-disable-next-line max-params
) => {
if (engine === "context") {
const srcPath = path.join(
__dirname,
"..",
"templates",
"components",
"data",
);
const destPath = path.join(root, "data");
console.log(`\nCopying test data to ${cyan(destPath)}\n`);
await copy("**", destPath, {
parents: true,
cwd: srcPath,
});
if (contextFile) {
console.log(`\nCopying provided file to ${cyan(destPath)}\n`);
await fs.mkdir(destPath, { recursive: true });
await fs.copyFile(
contextFile,
path.join(destPath, path.basename(contextFile)),
);
} else {
const srcPath = path.join(
__dirname,
"..",
"templates",
"components",
"data",
);
console.log(`\nCopying test data to ${cyan(destPath)}\n`);
await copy("**", destPath, {
parents: true,
cwd: srcPath,
});
}
}
if (packageManager && engine === "context") {
@@ -168,6 +178,7 @@ export const installTemplate = async (
props.engine,
props.openAiKey,
props.vectorDb,
props.contextFile,
);
} else {
// this is a frontend for a full-stack app, create .env file with model information
+1
View File
@@ -15,6 +15,7 @@ export interface InstallTemplateArgs {
template: TemplateType;
framework: TemplateFramework;
engine: TemplateEngine;
contextFile?: string;
ui: TemplateUI;
eslint: boolean;
customApiPath?: string;
+1
View File
@@ -240,6 +240,7 @@ async function run(): Promise<void> {
vectorDb: program.vectorDb,
externalPort: program.externalPort,
postInstallAction: program.postInstallAction,
contextFile: program.contextFile,
});
conf.set("preferences", preferences);
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "create-llama",
"version": "0.0.16",
"version": "0.0.18",
"keywords": [
"rag",
"llamaindex",
@@ -17,7 +17,7 @@
"create-llama": "./dist/index.js"
},
"files": [
"./dist/index.js",
"dist",
"./templates"
],
"scripts": {
+84 -12
View File
@@ -1,7 +1,8 @@
import { execSync } from "child_process";
import ciInfo from "ci-info";
import fs from "fs";
import path from "path";
import { blue, green } from "picocolors";
import { blue, green, red } from "picocolors";
import prompts from "prompts";
import { InstallAppArgs } from "./create-app";
import { TemplateFramework } from "./helpers";
@@ -9,6 +10,22 @@ import { COMMUNITY_OWNER, COMMUNITY_REPO } from "./helpers/constant";
import { getRepoRootFolders } from "./helpers/repo";
export type QuestionArgs = Omit<InstallAppArgs, "appPath" | "packageManager">;
const MACOS_FILE_SELECTION_SCRIPT = `
osascript -l JavaScript -e '
a = Application.currentApplication();
a.includeStandardAdditions = true;
a.chooseFile({ withPrompt: "Please select a file to process:" }).toString()
'`;
const WINDOWS_FILE_SELECTION_SCRIPT = `
Add-Type -AssemblyName System.Windows.Forms
$openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog.InitialDirectory = [Environment]::GetFolderPath('Desktop')
$result = $openFileDialog.ShowDialog()
if ($result -eq 'OK') {
$openFileDialog.FileName
}
`;
const defaults: QuestionArgs = {
template: "streaming",
@@ -55,6 +72,45 @@ const getVectorDbChoices = (framework: TemplateFramework) => {
return displayedChoices;
};
const selectPDFFile = async () => {
// Popup to select a PDF file
try {
let selectedFilePath: string = "";
switch (process.platform) {
case "win32": // Windows
selectedFilePath = execSync(WINDOWS_FILE_SELECTION_SCRIPT, {
shell: "powershell.exe",
})
.toString()
.trim();
break;
case "darwin": // MacOS
selectedFilePath = execSync(MACOS_FILE_SELECTION_SCRIPT)
.toString()
.trim();
break;
default: // Unsupported OS
console.log(red("Unsupported OS error!"));
process.exit(1);
}
// Check is pdf file
if (!selectedFilePath.endsWith(".pdf")) {
console.log(
red("Unsupported file error! Please select a valid PDF file!"),
);
process.exit(1);
}
return selectedFilePath;
} catch (error) {
console.log(
red(
"Got error when trying to select file! Please try again or select other options.",
),
);
process.exit(1);
}
};
export const onPromptState = (state: any) => {
if (state.aborted) {
// If we don't re-enable the terminal cursor before exiting
@@ -243,24 +299,40 @@ export const askQuestions = async (
if (ciInfo.isCI) {
program.engine = getPrefOrDefault("engine");
} else {
const { engine } = await prompts(
let choices = [
{
title: "No data, just a simple chat",
value: "simple",
},
{ title: "Use an example PDF", value: "exampleFile" },
];
if (process.platform === "win32" || process.platform === "darwin") {
choices.push({ title: "Use a local PDF file", value: "localFile" });
}
const { dataSource } = await prompts(
{
type: "select",
name: "engine",
name: "dataSource",
message: "Which data source would you like to use?",
choices: [
{
title: "No data, just a simple chat",
value: "simple",
},
{ title: "Use an example PDF", value: "context" },
],
choices: choices,
initial: 1,
},
handlers,
);
program.engine = engine;
preferences.engine = engine;
switch (dataSource) {
case "simple":
program.engine = "simple";
break;
case "exampleFile":
program.engine = "context";
break;
case "localFile":
program.engine = "context";
// If the user selected the "pdf" option, ask them to select a file
program.contextFile = await selectPDFFile();
break;
}
}
if (program.engine !== "simple" && !program.vectorDb) {
if (ciInfo.isCI) {
@@ -14,9 +14,6 @@
"express": "^4.18.2",
"llamaindex": "0.0.37"
},
"overrides": {
"chromadb": "1.7.3"
},
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
@@ -15,9 +15,6 @@
"express": "^4.18.2",
"llamaindex": "0.0.37"
},
"overrides": {
"chromadb": "1.7.3"
},
"devDependencies": {
"@types/cors": "^2.8.16",
"@types/express": "^4.17.21",
@@ -27,9 +27,6 @@
"supports-color": "^9.4.0",
"tailwind-merge": "^2.1.0"
},
"overrides": {
"chromadb": "1.7.3"
},
"devDependencies": {
"@types/node": "^20.10.3",
"@types/react": "^18.2.42",
+510 -191
View File
File diff suppressed because it is too large Load Diff