Skip to content

Commit

Permalink
feat: ask to use embedding model
Browse files Browse the repository at this point in the history
  • Loading branch information
thucpn committed Apr 8, 2024
1 parent 0cf6386 commit 36f2880
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
10 changes: 5 additions & 5 deletions helpers/env-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ export const createBackendEnvFile = async (
description: `The Llama Cloud API key.`,
value: opts.llamaCloudKey,
},
{
name: "EMBEDDING_MODEL",
description: "Name of the embedding model to use.",
value: opts.embeddingModel,
},
// Add vector database environment variables
...(opts.vectorDb ? getVectorDBEnvs(opts.vectorDb) : []),
];
Expand All @@ -164,11 +169,6 @@ export const createBackendEnvFile = async (
description: "The port to start the backend app.",
value: opts.port?.toString() || "8000",
},
{
name: "EMBEDDING_MODEL",
description: "Name of the embedding model to use.",
value: opts.embeddingModel,
},
{
name: "EMBEDDING_DIM",
description: "Dimension of the embedding model to use.",
Expand Down
48 changes: 31 additions & 17 deletions questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,26 +581,40 @@ export const askQuestions = async (
}
}

if (!program.embeddingModel && program.framework === "fastapi") {
if (!program.embeddingModel) {
if (ciInfo.isCI) {
program.embeddingModel = getPrefOrDefault("embeddingModel");
} else {
const { embeddingModel } = await prompts(
{
type: "select",
name: "embeddingModel",
message: "Which embedding model would you like to use?",
choices: await getAvailableModelChoices(
true,
program.openAiKey,
program.listServerModels,
),
initial: 0,
},
handlers,
);
program.embeddingModel = embeddingModel;
preferences.embeddingModel = embeddingModel;
const { useEmbeddingModel } = await prompts({
onState: onPromptState,
type: "toggle",
name: "useEmbeddingModel",
message: "Would you like to use an embedding model?",
initial: false,
active: "Yes",
inactive: "No",
});

let selectedEmbeddingModel = getPrefOrDefault("embeddingModel");
if (useEmbeddingModel) {
const { embeddingModel } = await prompts(
{
type: "select",
name: "embeddingModel",
message: "Which embedding model would you like to use?",
choices: await getAvailableModelChoices(
true,
program.openAiKey,
program.listServerModels,
),
initial: 0,
},
handlers,
);
selectedEmbeddingModel = embeddingModel;
}
program.embeddingModel = selectedEmbeddingModel;
preferences.embeddingModel = selectedEmbeddingModel;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { OpenAI, Settings } from "llamaindex";
import { OpenAI, OpenAIEmbedding, Settings } from "llamaindex";

const CHUNK_SIZE = 512;
const CHUNK_OVERLAP = 20;
const EMBEDDING_MODEL = process.env.EMBEDDING_MODEL;

export const initSettings = async () => {
Settings.llm = new OpenAI({
Expand All @@ -10,4 +11,7 @@ export const initSettings = async () => {
});
Settings.chunkSize = CHUNK_SIZE;
Settings.chunkOverlap = CHUNK_OVERLAP;
Settings.embedModel = new OpenAIEmbedding({
model: EMBEDDING_MODEL,
});
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { OpenAI, Settings } from "llamaindex";
import { OpenAI, OpenAIEmbedding, Settings } from "llamaindex";

const CHUNK_SIZE = 512;
const CHUNK_OVERLAP = 20;
const EMBEDDING_MODEL = process.env.EMBEDDING_MODEL;

export const initSettings = async () => {
Settings.llm = new OpenAI({
Expand All @@ -10,4 +11,7 @@ export const initSettings = async () => {
});
Settings.chunkSize = CHUNK_SIZE;
Settings.chunkOverlap = CHUNK_OVERLAP;
Settings.embedModel = new OpenAIEmbedding({
model: EMBEDDING_MODEL,
});
};

0 comments on commit 36f2880

Please sign in to comment.