Skip to content

Commit

Permalink
feature: dashboard makes call to /embedding_models route
Browse files Browse the repository at this point in the history
  • Loading branch information
cdxker committed Aug 24, 2024
1 parent 3243b68 commit 12b91fd
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 116 deletions.
120 changes: 76 additions & 44 deletions frontends/dashboard/src/components/NewDatasetModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Accessor, createMemo, createSignal, useContext, For } from "solid-js";
import { Accessor, createMemo, createSignal, createEffect, useContext, For } from "solid-js";
import { AiOutlineWarning } from "solid-icons/ai";
import {
Dialog,
DialogPanel,
Expand All @@ -12,7 +13,6 @@ import { useNavigate } from "@solidjs/router";
import {
ServerEnvsConfiguration,
availableDistanceMetrics,
availableEmbeddingModels,
} from "shared/types";
import { defaultServerEnvsConfiguration } from "../pages/Dashboard/Dataset/DatasetSettingsPage";
import { createToast } from "./ShowToasts";
Expand All @@ -35,6 +35,20 @@ export const NewDatasetModal = (props: NewDatasetModalProps) => {
const [isLoading, setIsLoading] = createSignal(false);
const [fillWithExampleData, setFillWithExampleData] = createSignal(false);

const api_host = import.meta.env.VITE_API_HOST as unknown as string;

const [availableEmbeddingModels, setAvailableEmbeddingModels] =
createSignal<any>([]);

createEffect(() => {
fetch(`${api_host}/embedding_models`)
.then((resp) => resp.json())
.then((json) => {
console.log(json.models);
setAvailableEmbeddingModels(json.models)
})
});

const selectedOrgnaization = createMemo(() => {
const selectedOrgId = userContext.selectedOrganizationId?.();
if (!selectedOrgId) return null;
Expand Down Expand Up @@ -186,51 +200,69 @@ export const NewDatasetModal = (props: NewDatasetModalProps) => {
>
Embedding Model
</label>
<select
id="embeddingSize"
name="embeddingSize"
class="col-span-2 block w-full rounded-md border-[0.5px] border-neutral-300 bg-white px-3 py-1.5 shadow-sm placeholder:text-neutral-400 focus:outline-magenta-500 sm:text-sm sm:leading-6"
value={
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
availableEmbeddingModels.find(
(model) =>
<Show when={availableEmbeddingModels().length > 0}>
<select
id="embeddingSize"
name="embeddingSize"
class="col-span-2 block w-full rounded-md border-[0.5px] border-neutral-300 bg-white px-3 py-1.5 shadow-sm placeholder:text-neutral-400 focus:outline-magenta-500 sm:text-sm sm:leading-6"
value={
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
availableEmbeddingModels().find(
(model) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
model.id ===
serverConfig().EMBEDDING_MODEL_NAME,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
model.id ===
serverConfig().EMBEDDING_MODEL_NAME,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
)?.name ?? availableEmbeddingModels[0].name
}
onChange={(e) => {
const selectedModel = availableEmbeddingModels.find(
(model) => model.name === e.currentTarget.value,
);
)?.display_name ??
availableEmbeddingModels()[0]?.display_name
}
onChange={(e) => {
const selectedModel =
availableEmbeddingModels()?.find(
(model) =>
model.display_name === e.currentTarget.value,
);

const embeddingSize =
selectedModel?.dimension ?? 1536;
const embeddingSize =
selectedModel?.dimension ?? 1536;

setServerConfig((prev) => {
return {
...prev,
EMBEDDING_SIZE: embeddingSize,
EMBEDDING_MODEL_NAME:
selectedModel?.id ?? "jina-base-en",
EMBEDDING_QUERY_PREFIX:
selectedModel?.id === "jina-base-en"
? "Search for:"
: "",
EMBEDDING_BASE_URL:
selectedModel?.url ??
"https://api.openai.com/v1",
};
});
}}
>
<For each={availableEmbeddingModels}>
{(model) => (
<option value={model.name}>{model.name}</option>
)}
</For>
</select>
setServerConfig((prev) => {
return {
...prev,
EMBEDDING_SIZE: embeddingSize,
EMBEDDING_MODEL_NAME:
selectedModel?.id ?? "jina-base-en",
EMBEDDING_QUERY_PREFIX:
selectedModel?.id === "jina-base-en"
? "Search for:"
: "",
EMBEDDING_BASE_URL:
selectedModel?.url ??
"https://api.openai.com/v1",
};
});
}}
>
<For each={availableEmbeddingModels()}>
{(model) => (
<option value={model.display_name}>{model.display_name}</option>
)}
</For>
</select>
</Show>
<Show when={availableEmbeddingModels().length == 0}>
<div class="col-span-2 flex items-center space-x-2">
<AiOutlineWarning class="h-5 w-5 text-yellow-400" />
<div class="flex flex-col space-y-1">
<div class="w-full text-base text-neutral-800 sm:text-sm sm:leading-6">
No Embedding Models available
</div>
<div class="w-full text-xs">
Check server settings
</div>
</div>
</div>
</Show>
</div>

<div class="content-center py-4 sm:grid sm:grid-cols-3 sm:items-start sm:gap-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { DatasetContext } from "../../../contexts/DatasetContext";
import {
ServerEnvsConfiguration,
availableDistanceMetrics,
availableEmbeddingModels,
} from "shared/types";
import { createToast } from "../../../components/ShowToasts";
import { AiOutlineInfoCircle } from "solid-icons/ai";
Expand Down Expand Up @@ -56,6 +55,21 @@ export const ServerSettingsForm = (props: {
config: (prev: ServerEnvsConfiguration) => ServerEnvsConfiguration,
) => void;
}) => {

const api_host = import.meta.env.VITE_API_HOST as unknown as string;

const [availableEmbeddingModels, setAvailableEmbeddingModels] =
createSignal<any>([]);

createEffect(() => {
fetch(`${api_host}/embedding_models`)
.then((resp) => resp.json())
.then((json) => {
console.log(json.models);
setAvailableEmbeddingModels(json.models)
})
});

return (
<form class="flex flex-col gap-3">
{/* General LLM Settings */}
Expand Down Expand Up @@ -554,14 +568,14 @@ export const ServerSettingsForm = (props: {
name="embeddingSize"
class="col-span-2 block w-full cursor-not-allowed rounded-md border-[0.5px] border-neutral-300 bg-white px-3 py-1.5 shadow-sm placeholder:text-neutral-400 focus:outline-magenta-500 sm:text-sm sm:leading-6"
value={
availableEmbeddingModels.find(
availableEmbeddingModels().find(
(model) =>
model.id === props.serverConfig().EMBEDDING_MODEL_NAME,
)?.name ?? availableEmbeddingModels[0].name
)?.display_name ?? availableEmbeddingModels()[0]?.display_name
}
>
<For each={availableEmbeddingModels}>
{(model) => <option value={model.name}>{model.name}</option>}
<For each={availableEmbeddingModels()}>
{(model) => <option value={model.display_name}>{model.display_name}</option>}
</For>
</select>
</div>
Expand Down Expand Up @@ -622,7 +636,7 @@ export const ServerSettingsForm = (props: {
availableDistanceMetrics.find(
(metric) =>
metric.id === props.serverConfig().DISTANCE_METRIC,
)?.name ?? availableEmbeddingModels[0].name
)?.name ?? availableDistanceMetrics[0].name
}
>
<For each={availableDistanceMetrics}>
Expand Down
33 changes: 0 additions & 33 deletions frontends/dashboard/src/types/apiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,39 +256,6 @@ export interface ApiKeyRespBody {
updated_at: string;
}

export const availableEmbeddingModels = [
{
id: "jina-base-en",
name: "jina-base-en (securely hosted by Trieve)",
url: "https://embedding.trieve.ai",
dimension: 768,
},
{
id: "bge-m3",
name: "bge-m3 (securely hosted by Trieve)",
url: "https://embedding.trieve.ai/bge-m3",
dimension: 1024,
},
{
id: "jina-embeddings-v2-base-code",
name: "jina-embeddings-v2-base-code (securely hosted by Trieve)",
url: "https://embedding.trieve.ai/jina-code",
dimension: 768,
},
{
id: "text-embedding-3-small",
name: "text-embedding-3-small (hosted by OpenAI)",
url: "https://api.openai.com/v1",
dimension: 1536,
},
{
id: "text-embedding-3-large",
name: "text-embedding-3-large (hosted by OpenAI)",
url: "https://api.openai.com/v1",
dimension: 3072,
},
];

export interface EventDTO {
events: Event[];
page_count: number;
Expand Down
33 changes: 0 additions & 33 deletions frontends/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,39 +266,6 @@ export interface ApiKeyRespBody {
updated_at: string;
}

export const availableEmbeddingModels = [
{
id: "jina-base-en",
name: "jina-base-en (securely hosted by Trieve)",
url: "https://embedding.trieve.ai",
dimension: 768,
},
{
id: "bge-m3",
name: "bge-m3 (securely hosted by Trieve)",
url: "https://embedding.trieve.ai/bge-m3",
dimension: 1024,
},
{
id: "jina-embeddings-v2-base-code",
name: "jina-embeddings-v2-base-code (securely hosted by Trieve)",
url: "https://embedding.trieve.ai/jina-code",
dimension: 768,
},
{
id: "text-embedding-3-small",
name: "text-embedding-3-small (hosted by OpenAI)",
url: "https://api.openai.com/v1",
dimension: 1536,
},
{
id: "text-embedding-3-large",
name: "text-embedding-3-large (hosted by OpenAI)",
url: "https://api.openai.com/v1",
dimension: 3072,
},
];

export const availableDistanceMetrics = [
{
id: "cosine",
Expand Down
52 changes: 52 additions & 0 deletions server/src/handlers/chunk_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2634,3 +2634,55 @@ pub fn check_completion_param_validity(

Ok(())
}

#[derive(Serialize, Deserialize, Debug, Clone, ToSchema)]
pub struct AvailableModelResponse {
models: Vec<EmbeddingModel>,
}

#[derive(Serialize, Deserialize, Debug, Clone, ToSchema)]
pub struct EmbeddingModel {
id: String,
display_name: String,
url: String,
dimension: u32,
}

pub async fn get_available_models() -> Result<HttpResponse, ServiceError> {
let avail_models = AvailableModelResponse {
models: vec![
EmbeddingModel {
id: "jina-base-en".into(),
display_name: "jina-base-en (securely hosted by Trieve)".into(),
url: "https://embedding.trieve.ai".into(),
dimension: 768,
},
EmbeddingModel {
id: "bge-m3".into(),
display_name: "bge-m3 (securely hosted by Trieve)".into(),
url: "https://embedding.trieve.ai/bge-m3".into(),
dimension: 1024,
},
EmbeddingModel {
id: "jina-embeddings-v2-base-code".into(),
display_name: "jina-embeddings-v2-base-code (securely hosted by Trieve)".into(),
url: "https://embedding.trieve.ai/jina-code".into(),
dimension: 768,
},
EmbeddingModel {
id: "text-embedding-3-small".into(),
display_name: "text-embedding-3-small (hosted by OpenAI)".into(),
url: "https://api.openai.com/v1".into(),
dimension: 1536,
},
EmbeddingModel {
id: "text-embedding-3-large".into(),
display_name: "text-embedding-3-large (hosted by OpenAI)".into(),
url: "https://api.openai.com/v1".into(),
dimension: 3072,
},
],
};

Ok(HttpResponse::Ok().json(avail_models))
}
3 changes: 3 additions & 0 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,9 @@ pub fn main() -> std::io::Result<()> {
.route(web::put().to(handlers::analytics_handler::send_ctr_data))
.route(web::post().to(handlers::analytics_handler::get_ctr_analytics)),
)
).service(
web::resource("/embedding_models")
.route(web::get().to(handlers::chunk_handler::get_available_models))
),
)
})
Expand Down

0 comments on commit 12b91fd

Please sign in to comment.