mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-08 22:21:35 +00:00
refactor(ui): pick the vector store id placeholder from a map
The chain had grown to four nested ternaries with a fifth level inside the Vertex Search branch, which no-nested-ternary had two suppressions for. A lookup keyed by provider drops both suppressions and leaves one condition, the Vertex Search case that depends on whether an engine id has been entered. Also hoists the MongoDB form fixtures in the tests, which the inline-object budget counts.
This commit is contained in:
parent
9434e563f3
commit
5d7bf187a4
3 changed files with 38 additions and 39 deletions
|
|
@ -1208,11 +1208,6 @@
|
|||
"count": 1
|
||||
}
|
||||
},
|
||||
"src/app/(dashboard)/vector-stores/_components/VectorStoreForm.tsx": {
|
||||
"no-nested-ternary": {
|
||||
"count": 2
|
||||
}
|
||||
},
|
||||
"src/app/(dashboard)/vector-stores/_components/index.tsx": {
|
||||
"local/filename-pascal-case": {
|
||||
"count": 1
|
||||
|
|
|
|||
|
|
@ -69,6 +69,15 @@ describe("VectorStoreForm", () => {
|
|||
});
|
||||
});
|
||||
|
||||
const MONGODB_URI = "mongodb+srv://user:pass@cluster0.mongodb.net";
|
||||
|
||||
const MONGODB_REQUIRED_FORM_VALUES = {
|
||||
mongodb_connection_string: MONGODB_URI,
|
||||
mongodb_database: "sample_mflix",
|
||||
mongodb_collection: "embedded_movies",
|
||||
embedding_model: "text-embedding-ada-002",
|
||||
};
|
||||
|
||||
describe("buildVectorStoreLitellmParams", () => {
|
||||
it("renames embedding_model to litellm_embedding_model for valkey", () => {
|
||||
const valkeyFormValues = {
|
||||
|
|
@ -111,51 +120,43 @@ describe("buildVectorStoreLitellmParams", () => {
|
|||
});
|
||||
|
||||
it("renames embedding_model to litellm_embedding_model for mongodb", () => {
|
||||
const params = buildVectorStoreLitellmParams("mongodb", {
|
||||
mongodb_connection_string: "mongodb+srv://user:pass@cluster0.mongodb.net",
|
||||
mongodb_database: "sample_mflix",
|
||||
mongodb_collection: "embedded_movies",
|
||||
const formValues = {
|
||||
...MONGODB_REQUIRED_FORM_VALUES,
|
||||
mongodb_embedding_field: "plot_embedding",
|
||||
mongodb_text_field: "plot",
|
||||
mongodb_num_candidates: "200",
|
||||
embedding_model: "text-embedding-ada-002",
|
||||
});
|
||||
|
||||
expect(params).toEqual({
|
||||
mongodb_connection_string: "mongodb+srv://user:pass@cluster0.mongodb.net",
|
||||
};
|
||||
const expected = {
|
||||
mongodb_connection_string: MONGODB_URI,
|
||||
mongodb_database: "sample_mflix",
|
||||
mongodb_collection: "embedded_movies",
|
||||
mongodb_embedding_field: "plot_embedding",
|
||||
mongodb_text_field: "plot",
|
||||
mongodb_num_candidates: "200",
|
||||
litellm_embedding_model: "text-embedding-ada-002",
|
||||
});
|
||||
};
|
||||
|
||||
expect(buildVectorStoreLitellmParams("mongodb", formValues)).toEqual(expected);
|
||||
});
|
||||
|
||||
it("sends only mongodb fields when an earlier provider left values in the form", () => {
|
||||
const params = buildVectorStoreLitellmParams("mongodb", {
|
||||
mongodb_connection_string: "mongodb+srv://user:pass@cluster0.mongodb.net",
|
||||
mongodb_database: "sample_mflix",
|
||||
mongodb_collection: "embedded_movies",
|
||||
embedding_model: "text-embedding-ada-002",
|
||||
const formValues = {
|
||||
...MONGODB_REQUIRED_FORM_VALUES,
|
||||
valkey_host: "left-over-from-valkey.example.com",
|
||||
valkey_port: "6379",
|
||||
aws_region_name: "us-west-2",
|
||||
});
|
||||
};
|
||||
|
||||
const params = buildVectorStoreLitellmParams("mongodb", formValues);
|
||||
|
||||
expect(params).not.toHaveProperty("valkey_host");
|
||||
expect(params).not.toHaveProperty("valkey_port");
|
||||
expect(params).not.toHaveProperty("aws_region_name");
|
||||
expect(params.mongodb_connection_string).toBe("mongodb+srv://user:pass@cluster0.mongodb.net");
|
||||
expect(params.mongodb_connection_string).toBe(MONGODB_URI);
|
||||
});
|
||||
|
||||
it("omits a blank mongodb_num_candidates so litellm picks its own candidate count", () => {
|
||||
const params = buildVectorStoreLitellmParams("mongodb", {
|
||||
mongodb_connection_string: "mongodb+srv://user:pass@cluster0.mongodb.net",
|
||||
mongodb_database: "sample_mflix",
|
||||
mongodb_collection: "embedded_movies",
|
||||
embedding_model: "text-embedding-ada-002",
|
||||
});
|
||||
const params = buildVectorStoreLitellmParams("mongodb", MONGODB_REQUIRED_FORM_VALUES);
|
||||
|
||||
expect(params.mongodb_num_candidates).toBeUndefined();
|
||||
expect(JSON.parse(JSON.stringify(params))).not.toHaveProperty("mongodb_num_candidates");
|
||||
|
|
|
|||
|
|
@ -138,6 +138,17 @@ const vectorStoreSchema = z.object(vectorStoreShape).superRefine((values, ctx) =
|
|||
|
||||
type VectorStoreFormValues = z.output<typeof vectorStoreSchema>;
|
||||
|
||||
const VECTOR_STORE_ID_PLACEHOLDERS: Record<string, string> = {
|
||||
vertex_rag_engine: '6917529027641081856 (corpus ID from Vertex AI / "RAG Engine" console)',
|
||||
"vertex_ai/search_api": 'my-datastore_1234567890 (data store ID from Vertex AI / "Agent Search" console)',
|
||||
valkey: "my-search-index (FT index name in Valkey)",
|
||||
mongodb: "my-vector-index (Atlas Vector Search index name)",
|
||||
};
|
||||
|
||||
const VERTEX_SEARCH_API_WITH_ENGINE_PLACEHOLDER = "Any identifier you'll use to reference this in LiteLLM";
|
||||
|
||||
const DEFAULT_VECTOR_STORE_ID_PLACEHOLDER = "Enter vector store ID from your provider";
|
||||
|
||||
const EMPTY_VALUES: VectorStoreFormValues = {
|
||||
custom_llm_provider: "bedrock",
|
||||
vector_store_id: "",
|
||||
|
|
@ -268,17 +279,9 @@ const VectorStoreForm: React.FC<VectorStoreFormProps> = ({
|
|||
};
|
||||
|
||||
const vectorStoreIdPlaceholder =
|
||||
selectedProvider === "vertex_rag_engine"
|
||||
? '6917529027641081856 (corpus ID from Vertex AI / "RAG Engine" console)'
|
||||
: selectedProvider === "vertex_ai/search_api"
|
||||
? vertexEngineId
|
||||
? "Any identifier you'll use to reference this in LiteLLM"
|
||||
: 'my-datastore_1234567890 (data store ID from Vertex AI / "Agent Search" console)'
|
||||
: selectedProvider === "valkey"
|
||||
? "my-search-index (FT index name in Valkey)"
|
||||
: selectedProvider === "mongodb"
|
||||
? "my-vector-index (Atlas Vector Search index name)"
|
||||
: "Enter vector store ID from your provider";
|
||||
selectedProvider === "vertex_ai/search_api" && vertexEngineId
|
||||
? VERTEX_SEARCH_API_WITH_ENGINE_PLACEHOLDER
|
||||
: VECTOR_STORE_ID_PLACEHOLDERS[selectedProvider] ?? DEFAULT_VECTOR_STORE_ID_PLACEHOLDER;
|
||||
|
||||
return (
|
||||
<Dialog open={isVisible} onOpenChange={(open) => !open && handleCancel()}>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue