Compare commits

...

10 Commits

Author SHA1 Message Date
github-actions[bot] fa28cb5d0d Release 0.2.7 (#293)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-09-19 15:49:39 +07:00
Thuc Pham 8c1087f5f1 feat: enhance style for markdown (#298) 2024-09-18 11:37:56 +07:00
Huu Le 27333973f1 fixed llama-index-core with 0.11.9 (#296) 2024-09-18 11:26:43 +07:00
Marcus Schiesser cf3ec97a4c Dynamically select model for Groq (#278)
---------
Co-authored-by: Jac-Zac <jacopozac@icloud.com>
Co-authored-by: Thuc Pham <51660321+thucpn@users.noreply.github.com>
2024-09-18 09:29:10 +07:00
Thuc Pham 505b8e944a bump: use latest ai package version (#292) 2024-09-16 17:49:58 +07:00
github-actions[bot] 578f7f9e50 Release 0.2.6 (#288)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-09-13 18:58:55 +07:00
Thuc Pham adc40cf770 fix: vercel ai update crash sending annotations (#287)
* fix: vercel ai update crash sending annotations

* Create five-ties-happen.md
2024-09-13 18:55:46 +07:00
github-actions[bot] 7bce7386d5 Release 0.2.5 (#285)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-09-12 13:53:28 +07:00
Huu Le c011455dc4 fix cannot upload file (#286) 2024-09-12 13:51:48 +07:00
Thuc Pham 38a8be8d12 fix: filter in mongo vector store (#269) 2024-09-12 11:34:54 +07:00
16 changed files with 172 additions and 42 deletions
+20
View File
@@ -1,5 +1,25 @@
# create-llama
## 0.2.7
### Patch Changes
- 505b8e9: bump: use latest ai package version
- cf3ec97: Dynamically select model for Groq
- 8c1087f: feat: enhance style for markdown
## 0.2.6
### Patch Changes
- adc40cf: fix: vercel ai update crash sending annotations
## 0.2.5
### Patch Changes
- 38a8be8: fix: filter in mongo vector store
## 0.2.4
### Patch Changes
+52 -3
View File
@@ -3,8 +3,55 @@ import prompts from "prompts";
import { ModelConfigParams } from ".";
import { questionHandlers, toChoice } from "../../questions";
const MODELS = ["llama3-8b", "llama3-70b", "mixtral-8x7b"];
const DEFAULT_MODEL = MODELS[0];
import got from "got";
import ora from "ora";
import { red } from "picocolors";
const GROQ_API_URL = "https://api.groq.com/openai/v1";
async function getAvailableModelChoicesGroq(apiKey: string) {
if (!apiKey) {
throw new Error("Need Groq API key to retrieve model choices");
}
const spinner = ora("Fetching available models from Groq").start();
try {
const response = await got(`${GROQ_API_URL}/models`, {
headers: {
Authorization: `Bearer ${apiKey}`,
},
timeout: 5000,
responseType: "json",
});
const data: any = await response.body;
spinner.stop();
// Filter out the Whisper models
return data.data
.filter((model: any) => !model.id.toLowerCase().includes("whisper"))
.map((el: any) => {
return {
title: el.id,
value: el.id,
};
});
} catch (error: unknown) {
spinner.stop();
console.log(error);
if ((error as any).response?.statusCode === 401) {
console.log(
red(
"Invalid Groq API key provided! Please provide a valid key and try again!",
),
);
} else {
console.log(red("Request failed: " + error));
}
process.exit(1);
}
}
const DEFAULT_MODEL = "llama3-70b-8192";
// Use huggingface embedding models for now as Groq doesn't support embedding models
enum HuggingFaceEmbeddingModelType {
@@ -66,12 +113,14 @@ export async function askGroqQuestions({
// use default model values in CI or if user should not be asked
const useDefaults = ciInfo.isCI || !askModels;
if (!useDefaults) {
const modelChoices = await getAvailableModelChoicesGroq(config.apiKey!);
const { model } = await prompts(
{
type: "select",
name: "model",
message: "Which LLM model would you like to use?",
choices: MODELS.map(toChoice),
choices: modelChoices,
initial: 0,
},
questionHandlers,
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "create-llama",
"version": "0.2.4",
"version": "0.2.7",
"description": "Create LlamaIndex-powered apps with one command",
"keywords": [
"rag",
+7 -2
View File
@@ -3,7 +3,7 @@ import mimetypes
import os
from io import BytesIO
from pathlib import Path
from typing import Any, List, Tuple
from typing import List, Optional, Tuple
from app.engine.index import IndexConfig, get_index
from llama_index.core import VectorStoreIndex
@@ -72,7 +72,12 @@ class PrivateFileService:
return documents
@staticmethod
def process_file(file_name: str, base64_content: str, params: Any) -> List[str]:
def process_file(
file_name: str, base64_content: str, params: Optional[dict] = None
) -> List[str]:
if params is None:
params = {}
file_data, extension = PrivateFileService.preprocess_base64_file(base64_content)
# Add the nodes to the index and persist it
@@ -126,13 +126,7 @@ def init_fastembed():
def init_groq():
from llama_index.llms.groq import Groq
model_map: Dict[str, str] = {
"llama3-8b": "llama3-8b-8192",
"llama3-70b": "llama3-70b-8192",
"mixtral-8x7b": "mixtral-8x7b-32768",
}
Settings.llm = Groq(model=model_map[os.getenv("MODEL")])
Settings.llm = Groq(model=os.getenv("MODEL"))
# Groq does not provide embeddings, so we use FastEmbed instead
init_fastembed()
@@ -1,14 +1,11 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import * as dotenv from "dotenv";
import {
MongoDBAtlasVectorSearch,
VectorStoreIndex,
storageContextFromDefaults,
} from "llamaindex";
import { storageContextFromDefaults, VectorStoreIndex } from "llamaindex";
import { MongoDBAtlasVectorSearch } from "llamaindex/storage/vectorStore/MongoDBAtlasVectorStore";
import { MongoClient } from "mongodb";
import { getDocuments } from "./loader";
import { initSettings } from "./settings";
import { checkRequiredEnvVars } from "./shared";
import { checkRequiredEnvVars, POPULATED_METADATA_FIELDS } from "./shared";
dotenv.config();
@@ -30,6 +27,12 @@ async function loadAndIndex() {
dbName: databaseName,
collectionName: vectorCollectionName, // this is where your embeddings will be stored
indexName: indexName, // this is the name of the index you will need to create
indexedMetadataFields: POPULATED_METADATA_FIELDS,
embeddingDefinition: {
dimensions: process.env.EMBEDDING_DIM
? parseInt(process.env.EMBEDDING_DIM)
: 1536,
},
});
// now create an index from all the Documents and store them in Atlas
@@ -1,16 +1,23 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import { MongoDBAtlasVectorSearch, VectorStoreIndex } from "llamaindex";
import { VectorStoreIndex } from "llamaindex";
import { MongoDBAtlasVectorSearch } from "llamaindex/storage/vectorStore/MongoDBAtlasVectorStore";
import { MongoClient } from "mongodb";
import { checkRequiredEnvVars } from "./shared";
import { checkRequiredEnvVars, POPULATED_METADATA_FIELDS } from "./shared";
export async function getDataSource(params?: any) {
checkRequiredEnvVars();
const client = new MongoClient(process.env.MONGO_URI!);
const client = new MongoClient(process.env.MONGODB_URI!);
const store = new MongoDBAtlasVectorSearch({
mongodbClient: client,
dbName: process.env.MONGODB_DATABASE!,
collectionName: process.env.MONGODB_VECTORS!,
indexName: process.env.MONGODB_VECTOR_INDEX,
indexedMetadataFields: POPULATED_METADATA_FIELDS,
embeddingDefinition: {
dimensions: process.env.EMBEDDING_DIM
? parseInt(process.env.EMBEDDING_DIM)
: 1536,
},
});
return await VectorStoreIndex.fromVectorStore(store);
@@ -5,6 +5,8 @@ const REQUIRED_ENV_VARS = [
"MONGODB_VECTOR_INDEX",
];
export const POPULATED_METADATA_FIELDS = ["private", "doc_id"]; // for filtering in MongoDB VectorSearchIndex
export function checkRequiredEnvVars() {
const missingEnvVars = REQUIRED_ENV_VARS.filter((envVar) => {
return !process.env[envVar];
@@ -12,7 +12,8 @@ generate = "app.engine.generate:generate_datasource"
[tool.poetry.dependencies]
python = "^3.11"
llama-index-agent-openai = ">=0.3.0,<0.4.0"
llama-index = "^0.11.4"
llama-index = "0.11.9"
llama-index-core = "0.11.9"
fastapi = "^0.112.2"
python-dotenv = "^1.0.0"
uvicorn = { extras = ["standard"], version = "^0.23.2" }
@@ -15,12 +15,12 @@
"dev": "concurrently \"tsup index.ts --format esm --dts --watch\" \"nodemon --watch dist/index.js\""
},
"dependencies": {
"ai": "^3.0.21",
"ai": "3.3.38",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"duck-duck-scrape": "^2.2.5",
"express": "^4.18.2",
"llamaindex": "0.5.20",
"llamaindex": "0.6.2",
"pdf2json": "3.0.5",
"ajv": "^8.12.0",
"@e2b/code-interpreter": "^0.0.5",
@@ -138,14 +138,8 @@ function initGroq() {
"all-mpnet-base-v2": "Xenova/all-mpnet-base-v2",
};
const modelMap: Record<string, string> = {
"llama3-8b": "llama3-8b-8192",
"llama3-70b": "llama3-70b-8192",
"mixtral-8x7b": "mixtral-8x7b-32768",
};
Settings.llm = new Groq({
model: modelMap[process.env.MODEL!],
model: process.env.MODEL!,
});
Settings.embedModel = new HuggingFaceEmbedding({
@@ -138,14 +138,8 @@ function initGroq() {
"all-mpnet-base-v2": "Xenova/all-mpnet-base-v2",
};
const modelMap: Record<string, string> = {
"llama3-8b": "llama3-8b-8192",
"llama3-70b": "llama3-70b-8192",
"mixtral-8x7b": "mixtral-8x7b-32768",
};
Settings.llm = new Groq({
model: modelMap[process.env.MODEL!],
model: process.env.MODEL!,
});
Settings.embedModel = new HuggingFaceEmbedding({
@@ -29,6 +29,7 @@ export default function ChatSection() {
const message = JSON.parse(error.message);
alert(message.detail);
},
sendExtraMessageFields: true,
});
return (
@@ -133,7 +133,11 @@ export default function Markdown({
return <></>;
}
}
return <a href={href}>{children}</a>;
return (
<a href={href} target="_blank">
{children}
</a>
);
},
}}
>
@@ -2,11 +2,15 @@
.custom-markdown ul {
list-style-type: disc;
margin-left: 20px;
margin-top: 20px;
margin-bottom: 20px;
}
.custom-markdown ol {
list-style-type: decimal;
margin-left: 20px;
margin-top: 20px;
margin-bottom: 20px;
}
.custom-markdown li {
@@ -21,3 +25,55 @@
.custom-markdown ol ol {
margin-left: 20px;
}
.custom-markdown img {
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
margin: 10px 0;
}
.custom-markdown a {
text-decoration: underline;
color: #007bff;
}
.custom-markdown h1,
h2,
h3,
h4,
h5,
h6 {
font-weight: bold;
margin-bottom: 20px;
margin-top: 20px;
}
.custom-markdown h6 {
font-size: 16px;
}
.custom-markdown h5 {
font-size: 18px;
}
.custom-markdown h4 {
font-size: 20px;
}
.custom-markdown h3 {
font-size: 22px;
}
.custom-markdown h2 {
font-size: 24px;
}
.custom-markdown h1 {
font-size: 26px;
}
.custom-markdown hr {
border: 0;
border-top: 1px solid #e1e4e8;
margin: 20px 0;
}
@@ -17,7 +17,7 @@
"@radix-ui/react-hover-card": "^1.0.7",
"@radix-ui/react-select": "^2.1.1",
"@radix-ui/react-slot": "^1.0.2",
"ai": "^3.0.21",
"ai": "3.3.38",
"ajv": "^8.12.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
@@ -25,7 +25,7 @@
"duck-duck-scrape": "^2.2.5",
"formdata-node": "^6.0.3",
"got": "^14.4.1",
"llamaindex": "0.5.20",
"llamaindex": "0.6.2",
"lucide-react": "^0.294.0",
"next": "^14.2.4",
"react": "^18.2.0",