-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integration: Add Hugging Face local models; ST for embeddings (#402)
--------- Co-authored-by: Marcus Schiesser <[email protected]>
- Loading branch information
Showing
7 changed files
with
132 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-llama": patch | ||
--- | ||
|
||
Add local models via Hugging Face; use Sentence Transformers w. ONNX instead of FastEmbed (support for more models, etc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import prompts from "prompts"; | ||
import { ModelConfigParams } from "."; | ||
import { questionHandlers, toChoice } from "../../questions/utils"; | ||
|
||
const MODELS = ["HuggingFaceH4/zephyr-7b-alpha"]; | ||
type ModelData = { | ||
dimensions: number; | ||
}; | ||
const EMBEDDING_MODELS: Record<string, ModelData> = { | ||
"all-MiniLM-L6-v2": { dimensions: 384 }, | ||
}; | ||
|
||
const DEFAULT_MODEL = MODELS[0]; | ||
const DEFAULT_EMBEDDING_MODEL = Object.keys(EMBEDDING_MODELS)[0]; | ||
const DEFAULT_DIMENSIONS = Object.values(EMBEDDING_MODELS)[0].dimensions; | ||
|
||
type HuggingfaceQuestionsParams = { | ||
askModels: boolean; | ||
}; | ||
|
||
export async function askHuggingfaceQuestions({ | ||
askModels, | ||
}: HuggingfaceQuestionsParams): Promise<ModelConfigParams> { | ||
const config: ModelConfigParams = { | ||
model: DEFAULT_MODEL, | ||
embeddingModel: DEFAULT_EMBEDDING_MODEL, | ||
dimensions: DEFAULT_DIMENSIONS, | ||
isConfigured(): boolean { | ||
return true; | ||
}, | ||
}; | ||
|
||
if (askModels) { | ||
const { model } = await prompts( | ||
{ | ||
type: "select", | ||
name: "model", | ||
message: "Which Hugging Face model would you like to use?", | ||
choices: MODELS.map(toChoice), | ||
initial: 0, | ||
}, | ||
questionHandlers, | ||
); | ||
config.model = model; | ||
|
||
const { embeddingModel } = await prompts( | ||
{ | ||
type: "select", | ||
name: "embeddingModel", | ||
message: "Which embedding model would you like to use?", | ||
choices: Object.keys(EMBEDDING_MODELS).map(toChoice), | ||
initial: 0, | ||
}, | ||
questionHandlers, | ||
); | ||
config.embeddingModel = embeddingModel; | ||
config.dimensions = EMBEDDING_MODELS[embeddingModel].dimensions; | ||
} | ||
|
||
return config; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters