refac
This commit is contained in:
@@ -490,19 +490,19 @@ async def get_embedding_config(request: Request, user=Depends(get_admin_user)):
|
|||||||
|
|
||||||
|
|
||||||
class OpenAIConfigForm(BaseModel):
|
class OpenAIConfigForm(BaseModel):
|
||||||
url: str
|
url: str | None = None
|
||||||
key: str
|
key: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class OllamaConfigForm(BaseModel):
|
class OllamaConfigForm(BaseModel):
|
||||||
url: str
|
url: str | None = None
|
||||||
key: str
|
key: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class AzureOpenAIConfigForm(BaseModel):
|
class AzureOpenAIConfigForm(BaseModel):
|
||||||
url: str
|
url: str | None = None
|
||||||
key: str
|
key: str | None = None
|
||||||
version: str
|
version: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class EmbeddingModelUpdateForm(BaseModel):
|
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.ENABLE_ASYNC_EMBEDDING = form_data.ENABLE_ASYNC_EMBEDDING
|
||||||
config.RAG_EMBEDDING_CONCURRENT_REQUESTS = form_data.RAG_EMBEDDING_CONCURRENT_REQUESTS
|
config.RAG_EMBEDDING_CONCURRENT_REQUESTS = form_data.RAG_EMBEDDING_CONCURRENT_REQUESTS
|
||||||
|
|
||||||
if config.RAG_EMBEDDING_ENGINE in [
|
if config.RAG_EMBEDDING_ENGINE == 'openai' and form_data.openai_config is not None:
|
||||||
'ollama',
|
config.RAG_OPENAI_API_BASE_URL = form_data.openai_config.url or ''
|
||||||
'openai',
|
config.RAG_OPENAI_API_KEY = form_data.openai_config.key or ''
|
||||||
'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 form_data.ollama_config is not None:
|
if config.RAG_EMBEDDING_ENGINE == 'ollama' and form_data.ollama_config is not None:
|
||||||
config.RAG_OLLAMA_BASE_URL = form_data.ollama_config.url
|
config.RAG_OLLAMA_BASE_URL = form_data.ollama_config.url or ''
|
||||||
config.RAG_OLLAMA_API_KEY = form_data.ollama_config.key
|
config.RAG_OLLAMA_API_KEY = form_data.ollama_config.key or ''
|
||||||
|
|
||||||
if form_data.azure_openai_config is not None:
|
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
|
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
|
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
|
config.RAG_AZURE_OPENAI_API_VERSION = form_data.azure_openai_config.version or ''
|
||||||
|
|
||||||
request.app.state.ef = get_ef(
|
request.app.state.ef = get_ef(
|
||||||
config.RAG_EMBEDDING_ENGINE,
|
config.RAG_EMBEDDING_ENGINE,
|
||||||
|
|||||||
@@ -188,6 +188,8 @@ type OpenAIConfigForm = {
|
|||||||
url: string;
|
url: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type OllamaConfigForm = OpenAIConfigForm;
|
||||||
|
|
||||||
type AzureOpenAIConfigForm = {
|
type AzureOpenAIConfigForm = {
|
||||||
key: string;
|
key: string;
|
||||||
url: string;
|
url: string;
|
||||||
@@ -196,10 +198,13 @@ type AzureOpenAIConfigForm = {
|
|||||||
|
|
||||||
type EmbeddingModelUpdateForm = {
|
type EmbeddingModelUpdateForm = {
|
||||||
openai_config?: OpenAIConfigForm;
|
openai_config?: OpenAIConfigForm;
|
||||||
|
ollama_config?: OllamaConfigForm;
|
||||||
azure_openai_config?: AzureOpenAIConfigForm;
|
azure_openai_config?: AzureOpenAIConfigForm;
|
||||||
embedding_engine: string;
|
RAG_EMBEDDING_ENGINE: string;
|
||||||
embedding_model: string;
|
RAG_EMBEDDING_MODEL: string;
|
||||||
embedding_batch_size?: number;
|
RAG_EMBEDDING_BATCH_SIZE?: number;
|
||||||
|
ENABLE_ASYNC_EMBEDDING?: boolean;
|
||||||
|
RAG_EMBEDDING_CONCURRENT_REQUESTS?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateEmbeddingConfig = async (token: string, payload: EmbeddingModelUpdateForm) => {
|
export const updateEmbeddingConfig = async (token: string, payload: EmbeddingModelUpdateForm) => {
|
||||||
|
|||||||
@@ -122,26 +122,33 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
updateEmbeddingModelLoading = true;
|
updateEmbeddingModelLoading = true;
|
||||||
const res = await updateEmbeddingConfig(localStorage.token, {
|
const payload: Parameters<typeof updateEmbeddingConfig>[1] = {
|
||||||
RAG_EMBEDDING_ENGINE: RAG_EMBEDDING_ENGINE,
|
RAG_EMBEDDING_ENGINE: RAG_EMBEDDING_ENGINE,
|
||||||
RAG_EMBEDDING_MODEL: RAG_EMBEDDING_MODEL,
|
RAG_EMBEDDING_MODEL: RAG_EMBEDDING_MODEL,
|
||||||
RAG_EMBEDDING_BATCH_SIZE: RAG_EMBEDDING_BATCH_SIZE,
|
RAG_EMBEDDING_BATCH_SIZE: RAG_EMBEDDING_BATCH_SIZE,
|
||||||
ENABLE_ASYNC_EMBEDDING: ENABLE_ASYNC_EMBEDDING,
|
ENABLE_ASYNC_EMBEDDING: ENABLE_ASYNC_EMBEDDING,
|
||||||
RAG_EMBEDDING_CONCURRENT_REQUESTS: RAG_EMBEDDING_CONCURRENT_REQUESTS,
|
RAG_EMBEDDING_CONCURRENT_REQUESTS: RAG_EMBEDDING_CONCURRENT_REQUESTS
|
||||||
ollama_config: {
|
};
|
||||||
|
|
||||||
|
if (RAG_EMBEDDING_ENGINE === 'ollama') {
|
||||||
|
payload.ollama_config = {
|
||||||
key: OllamaKey,
|
key: OllamaKey,
|
||||||
url: OllamaUrl
|
url: OllamaUrl
|
||||||
},
|
};
|
||||||
openai_config: {
|
} else if (RAG_EMBEDDING_ENGINE === 'openai') {
|
||||||
|
payload.openai_config = {
|
||||||
key: OpenAIKey,
|
key: OpenAIKey,
|
||||||
url: OpenAIUrl
|
url: OpenAIUrl
|
||||||
},
|
};
|
||||||
azure_openai_config: {
|
} else if (RAG_EMBEDDING_ENGINE === 'azure_openai') {
|
||||||
|
payload.azure_openai_config = {
|
||||||
key: AzureOpenAIKey,
|
key: AzureOpenAIKey,
|
||||||
url: AzureOpenAIUrl,
|
url: AzureOpenAIUrl,
|
||||||
version: AzureOpenAIVersion
|
version: AzureOpenAIVersion
|
||||||
}
|
};
|
||||||
}).catch(async (error) => {
|
}
|
||||||
|
|
||||||
|
const res = await updateEmbeddingConfig(localStorage.token, payload).catch(async (error) => {
|
||||||
toast.error(`${error}`);
|
toast.error(`${error}`);
|
||||||
await setEmbeddingConfig();
|
await setEmbeddingConfig();
|
||||||
return null;
|
return null;
|
||||||
@@ -300,15 +307,15 @@
|
|||||||
ENABLE_ASYNC_EMBEDDING = embeddingConfig.ENABLE_ASYNC_EMBEDDING ?? true;
|
ENABLE_ASYNC_EMBEDDING = embeddingConfig.ENABLE_ASYNC_EMBEDDING ?? true;
|
||||||
RAG_EMBEDDING_CONCURRENT_REQUESTS = embeddingConfig.RAG_EMBEDDING_CONCURRENT_REQUESTS ?? 0;
|
RAG_EMBEDDING_CONCURRENT_REQUESTS = embeddingConfig.RAG_EMBEDDING_CONCURRENT_REQUESTS ?? 0;
|
||||||
|
|
||||||
OpenAIKey = embeddingConfig.openai_config.key;
|
OpenAIKey = embeddingConfig.openai_config.key ?? '';
|
||||||
OpenAIUrl = embeddingConfig.openai_config.url;
|
OpenAIUrl = embeddingConfig.openai_config.url ?? '';
|
||||||
|
|
||||||
OllamaKey = embeddingConfig.ollama_config.key;
|
OllamaKey = embeddingConfig.ollama_config.key ?? '';
|
||||||
OllamaUrl = embeddingConfig.ollama_config.url;
|
OllamaUrl = embeddingConfig.ollama_config.url ?? '';
|
||||||
|
|
||||||
AzureOpenAIKey = embeddingConfig.azure_openai_config.key;
|
AzureOpenAIKey = embeddingConfig.azure_openai_config.key ?? '';
|
||||||
AzureOpenAIUrl = embeddingConfig.azure_openai_config.url;
|
AzureOpenAIUrl = embeddingConfig.azure_openai_config.url ?? '';
|
||||||
AzureOpenAIVersion = embeddingConfig.azure_openai_config.version;
|
AzureOpenAIVersion = embeddingConfig.azure_openai_config.version ?? '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user