This commit is contained in:
Timothy Jaeryang Baek
2026-08-17 00:51:04 -07:00
parent 6e468c5b95
commit 87d9b7e84e
3 changed files with 48 additions and 41 deletions
+17 -22
View File
@@ -490,19 +490,19 @@ async def get_embedding_config(request: Request, user=Depends(get_admin_user)):
class OpenAIConfigForm(BaseModel):
url: str
key: str
url: str | None = None
key: str | None = None
class OllamaConfigForm(BaseModel):
url: str
key: str
url: str | None = None
key: str | None = None
class AzureOpenAIConfigForm(BaseModel):
url: str
key: str
version: str
url: str | None = None
key: str | None = None
version: str | None = None
class EmbeddingModelUpdateForm(BaseModel):
@@ -544,23 +544,18 @@ async def update_embedding_config(request: Request, form_data: EmbeddingModelUpd
config.ENABLE_ASYNC_EMBEDDING = form_data.ENABLE_ASYNC_EMBEDDING
config.RAG_EMBEDDING_CONCURRENT_REQUESTS = form_data.RAG_EMBEDDING_CONCURRENT_REQUESTS
if config.RAG_EMBEDDING_ENGINE in [
'ollama',
'openai',
'azure_openai',
]:
if form_data.openai_config is not None:
config.RAG_OPENAI_API_BASE_URL = form_data.openai_config.url
config.RAG_OPENAI_API_KEY = form_data.openai_config.key
if config.RAG_EMBEDDING_ENGINE == 'openai' and form_data.openai_config is not None:
config.RAG_OPENAI_API_BASE_URL = form_data.openai_config.url or ''
config.RAG_OPENAI_API_KEY = form_data.openai_config.key or ''
if form_data.ollama_config is not None:
config.RAG_OLLAMA_BASE_URL = form_data.ollama_config.url
config.RAG_OLLAMA_API_KEY = form_data.ollama_config.key
if config.RAG_EMBEDDING_ENGINE == 'ollama' and form_data.ollama_config is not None:
config.RAG_OLLAMA_BASE_URL = form_data.ollama_config.url or ''
config.RAG_OLLAMA_API_KEY = form_data.ollama_config.key or ''
if form_data.azure_openai_config is not None:
config.RAG_AZURE_OPENAI_BASE_URL = form_data.azure_openai_config.url
config.RAG_AZURE_OPENAI_API_KEY = form_data.azure_openai_config.key
config.RAG_AZURE_OPENAI_API_VERSION = form_data.azure_openai_config.version
if config.RAG_EMBEDDING_ENGINE == 'azure_openai' and form_data.azure_openai_config is not None:
config.RAG_AZURE_OPENAI_BASE_URL = form_data.azure_openai_config.url or ''
config.RAG_AZURE_OPENAI_API_KEY = form_data.azure_openai_config.key or ''
config.RAG_AZURE_OPENAI_API_VERSION = form_data.azure_openai_config.version or ''
request.app.state.ef = get_ef(
config.RAG_EMBEDDING_ENGINE,
+8 -3
View File
@@ -188,6 +188,8 @@ type OpenAIConfigForm = {
url: string;
};
type OllamaConfigForm = OpenAIConfigForm;
type AzureOpenAIConfigForm = {
key: string;
url: string;
@@ -196,10 +198,13 @@ type AzureOpenAIConfigForm = {
type EmbeddingModelUpdateForm = {
openai_config?: OpenAIConfigForm;
ollama_config?: OllamaConfigForm;
azure_openai_config?: AzureOpenAIConfigForm;
embedding_engine: string;
embedding_model: string;
embedding_batch_size?: number;
RAG_EMBEDDING_ENGINE: string;
RAG_EMBEDDING_MODEL: string;
RAG_EMBEDDING_BATCH_SIZE?: number;
ENABLE_ASYNC_EMBEDDING?: boolean;
RAG_EMBEDDING_CONCURRENT_REQUESTS?: number;
};
export const updateEmbeddingConfig = async (token: string, payload: EmbeddingModelUpdateForm) => {
@@ -122,26 +122,33 @@
});
updateEmbeddingModelLoading = true;
const res = await updateEmbeddingConfig(localStorage.token, {
const payload: Parameters<typeof updateEmbeddingConfig>[1] = {
RAG_EMBEDDING_ENGINE: RAG_EMBEDDING_ENGINE,
RAG_EMBEDDING_MODEL: RAG_EMBEDDING_MODEL,
RAG_EMBEDDING_BATCH_SIZE: RAG_EMBEDDING_BATCH_SIZE,
ENABLE_ASYNC_EMBEDDING: ENABLE_ASYNC_EMBEDDING,
RAG_EMBEDDING_CONCURRENT_REQUESTS: RAG_EMBEDDING_CONCURRENT_REQUESTS,
ollama_config: {
RAG_EMBEDDING_CONCURRENT_REQUESTS: RAG_EMBEDDING_CONCURRENT_REQUESTS
};
if (RAG_EMBEDDING_ENGINE === 'ollama') {
payload.ollama_config = {
key: OllamaKey,
url: OllamaUrl
},
openai_config: {
};
} else if (RAG_EMBEDDING_ENGINE === 'openai') {
payload.openai_config = {
key: OpenAIKey,
url: OpenAIUrl
},
azure_openai_config: {
};
} else if (RAG_EMBEDDING_ENGINE === 'azure_openai') {
payload.azure_openai_config = {
key: AzureOpenAIKey,
url: AzureOpenAIUrl,
version: AzureOpenAIVersion
}
}).catch(async (error) => {
};
}
const res = await updateEmbeddingConfig(localStorage.token, payload).catch(async (error) => {
toast.error(`${error}`);
await setEmbeddingConfig();
return null;
@@ -300,15 +307,15 @@
ENABLE_ASYNC_EMBEDDING = embeddingConfig.ENABLE_ASYNC_EMBEDDING ?? true;
RAG_EMBEDDING_CONCURRENT_REQUESTS = embeddingConfig.RAG_EMBEDDING_CONCURRENT_REQUESTS ?? 0;
OpenAIKey = embeddingConfig.openai_config.key;
OpenAIUrl = embeddingConfig.openai_config.url;
OpenAIKey = embeddingConfig.openai_config.key ?? '';
OpenAIUrl = embeddingConfig.openai_config.url ?? '';
OllamaKey = embeddingConfig.ollama_config.key;
OllamaUrl = embeddingConfig.ollama_config.url;
OllamaKey = embeddingConfig.ollama_config.key ?? '';
OllamaUrl = embeddingConfig.ollama_config.url ?? '';
AzureOpenAIKey = embeddingConfig.azure_openai_config.key;
AzureOpenAIUrl = embeddingConfig.azure_openai_config.url;
AzureOpenAIVersion = embeddingConfig.azure_openai_config.version;
AzureOpenAIKey = embeddingConfig.azure_openai_config.key ?? '';
AzureOpenAIUrl = embeddingConfig.azure_openai_config.url ?? '';
AzureOpenAIVersion = embeddingConfig.azure_openai_config.version ?? '';
}
};
onMount(async () => {