mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-30 11:26:24 +02:00
Merge pull request #398 from MODSetter/dev
chore: removed chinese comments to pass ruff checks and updated migration nos
This commit is contained in:
commit
cbabc2bb4d
6 changed files with 63 additions and 83 deletions
|
|
@ -21,7 +21,6 @@ from app.db import Base # Assuming your Base is defined in app.db
|
||||||
config = context.config
|
config = context.config
|
||||||
|
|
||||||
# Override SQLAlchemy URL from environment variables when available
|
# Override SQLAlchemy URL from environment variables when available
|
||||||
# 如果环境变量提供了数据库连接字符串,则优先使用该配置
|
|
||||||
database_url = os.getenv("DATABASE_URL")
|
database_url = os.getenv("DATABASE_URL")
|
||||||
if database_url:
|
if database_url:
|
||||||
config.set_main_option("sqlalchemy.url", database_url)
|
config.set_main_option("sqlalchemy.url", database_url)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
"""Add Chinese LLM providers to LiteLLMProvider enum
|
"""Add Chinese LLM providers to LiteLLMProvider enum
|
||||||
添加国产 LLM 提供商到 LiteLLMProvider 枚举
|
|
||||||
|
|
||||||
Revision ID: 26
|
Revision ID: 28
|
||||||
Revises: 25
|
Revises: 27
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
|
|
@ -10,8 +9,8 @@ from collections.abc import Sequence
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision: str = "26"
|
revision: str = "28"
|
||||||
down_revision: str | None = "25"
|
down_revision: str | None = "27"
|
||||||
branch_labels: str | Sequence[str] | None = None
|
branch_labels: str | Sequence[str] | None = None
|
||||||
depends_on: str | Sequence[str] | None = None
|
depends_on: str | Sequence[str] | None = None
|
||||||
|
|
||||||
|
|
@ -19,17 +18,15 @@ depends_on: str | Sequence[str] | None = None
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
"""
|
"""
|
||||||
Add Chinese LLM providers to LiteLLMProvider enum.
|
Add Chinese LLM providers to LiteLLMProvider enum.
|
||||||
添加国产 LLM 提供商到 LiteLLMProvider 枚举。
|
|
||||||
|
|
||||||
Adds support for:
|
Adds support for:
|
||||||
- DEEPSEEK: DeepSeek AI models
|
- DEEPSEEK: DeepSeek AI models
|
||||||
- ALIBABA_QWEN: Alibaba Qwen (通义千问) models
|
- ALIBABA_QWEN: Alibaba Qwen models
|
||||||
- MOONSHOT: Moonshot AI (月之暗面 Kimi) models
|
- MOONSHOT: Moonshot AI models
|
||||||
- ZHIPU: Zhipu AI (智谱 GLM) models
|
- ZHIPU: Zhipu AI models
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Add DEEPSEEK to the enum if it doesn't already exist
|
# Add DEEPSEEK to the enum if it doesn't already exist
|
||||||
# 如果不存在则添加 DEEPSEEK 到枚举
|
|
||||||
op.execute(
|
op.execute(
|
||||||
"""
|
"""
|
||||||
DO $$
|
DO $$
|
||||||
|
|
@ -44,9 +41,8 @@ def upgrade() -> None:
|
||||||
END$$;
|
END$$;
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add ALIBABA_QWEN to the enum if it doesn't already exist
|
# Add ALIBABA_QWEN to the enum if it doesn't already exist
|
||||||
# 如果不存在则添加 ALIBABA_QWEN 到枚举
|
|
||||||
op.execute(
|
op.execute(
|
||||||
"""
|
"""
|
||||||
DO $$
|
DO $$
|
||||||
|
|
@ -61,9 +57,8 @@ def upgrade() -> None:
|
||||||
END$$;
|
END$$;
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add MOONSHOT to the enum if it doesn't already exist
|
# Add MOONSHOT to the enum if it doesn't already exist
|
||||||
# 如果不存在则添加 MOONSHOT 到枚举
|
|
||||||
op.execute(
|
op.execute(
|
||||||
"""
|
"""
|
||||||
DO $$
|
DO $$
|
||||||
|
|
@ -78,9 +73,8 @@ def upgrade() -> None:
|
||||||
END$$;
|
END$$;
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add ZHIPU to the enum if it doesn't already exist
|
# Add ZHIPU to the enum if it doesn't already exist
|
||||||
# 如果不存在则添加 ZHIPU 到枚举
|
|
||||||
op.execute(
|
op.execute(
|
||||||
"""
|
"""
|
||||||
DO $$
|
DO $$
|
||||||
|
|
@ -100,19 +94,14 @@ def upgrade() -> None:
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
"""
|
"""
|
||||||
Remove Chinese LLM providers from LiteLLMProvider enum.
|
Remove Chinese LLM providers from LiteLLMProvider enum.
|
||||||
从 LiteLLMProvider 枚举中移除国产 LLM 提供商。
|
|
||||||
|
|
||||||
Note: PostgreSQL doesn't support removing enum values directly.
|
Note: PostgreSQL doesn't support removing enum values directly.
|
||||||
This would require recreating the enum type and updating all dependent objects.
|
This would require recreating the enum type and updating all dependent objects.
|
||||||
For safety, this downgrade is a no-op.
|
For safety, this downgrade is a no-op.
|
||||||
|
|
||||||
注意:PostgreSQL 不支持直接删除枚举值。
|
|
||||||
这需要重建枚举类型并更新所有依赖对象。
|
|
||||||
为了安全起见,此降级操作为空操作。
|
|
||||||
"""
|
"""
|
||||||
# PostgreSQL doesn't support removing enum values directly
|
# PostgreSQL doesn't support removing enum values directly
|
||||||
# This would require a complex migration recreating the enum
|
# This would require a complex migration recreating the enum
|
||||||
# PostgreSQL 不支持直接删除枚举值
|
# PostgreSQL 不支持直接删除枚举值
|
||||||
# 这需要复杂的迁移来重建枚举
|
# 这需要复杂的迁移来重建枚举
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -83,6 +83,7 @@ class LiteLLMProvider(str, Enum):
|
||||||
Enum for LLM providers supported by LiteLLM.
|
Enum for LLM providers supported by LiteLLM.
|
||||||
LiteLLM 支持的 LLM 提供商枚举。
|
LiteLLM 支持的 LLM 提供商枚举。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
OPENAI = "OPENAI"
|
OPENAI = "OPENAI"
|
||||||
ANTHROPIC = "ANTHROPIC"
|
ANTHROPIC = "ANTHROPIC"
|
||||||
GROQ = "GROQ"
|
GROQ = "GROQ"
|
||||||
|
|
@ -106,11 +107,11 @@ class LiteLLMProvider(str, Enum):
|
||||||
ALEPH_ALPHA = "ALEPH_ALPHA"
|
ALEPH_ALPHA = "ALEPH_ALPHA"
|
||||||
PETALS = "PETALS"
|
PETALS = "PETALS"
|
||||||
COMETAPI = "COMETAPI"
|
COMETAPI = "COMETAPI"
|
||||||
# Chinese LLM Providers (OpenAI-compatible) / 国产 LLM 提供商(OpenAI 兼容)
|
# Chinese LLM Providers (OpenAI-compatible)
|
||||||
DEEPSEEK = "DEEPSEEK" # DeepSeek
|
DEEPSEEK = "DEEPSEEK"
|
||||||
ALIBABA_QWEN = "ALIBABA_QWEN" # 阿里通义千问
|
ALIBABA_QWEN = "ALIBABA_QWEN"
|
||||||
MOONSHOT = "MOONSHOT" # 月之暗面 (Kimi)
|
MOONSHOT = "MOONSHOT"
|
||||||
ZHIPU = "ZHIPU" # 智谱 AI (GLM)
|
ZHIPU = "ZHIPU"
|
||||||
CUSTOM = "CUSTOM"
|
CUSTOM = "CUSTOM"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,11 +99,11 @@ async def get_user_llm_instance(
|
||||||
"AZURE_OPENAI": "azure",
|
"AZURE_OPENAI": "azure",
|
||||||
"OPENROUTER": "openrouter",
|
"OPENROUTER": "openrouter",
|
||||||
"COMETAPI": "cometapi",
|
"COMETAPI": "cometapi",
|
||||||
# Chinese LLM providers (OpenAI-compatible) / 国产 LLM(OpenAI 兼容)
|
# Chinese LLM providers (OpenAI-compatible)
|
||||||
"DEEPSEEK": "openai", # DeepSeek uses OpenAI-compatible API
|
"DEEPSEEK": "openai", # DeepSeek uses OpenAI-compatible API
|
||||||
"ALIBABA_QWEN": "openai", # Qwen uses OpenAI-compatible API
|
"ALIBABA_QWEN": "openai", # Qwen uses OpenAI-compatible API
|
||||||
"MOONSHOT": "openai", # Moonshot (Kimi) uses OpenAI-compatible API
|
"MOONSHOT": "openai", # Moonshot (Kimi) uses OpenAI-compatible API
|
||||||
"ZHIPU": "openai", # Zhipu (GLM) uses OpenAI-compatible API
|
"ZHIPU": "openai", # Zhipu (GLM) uses OpenAI-compatible API
|
||||||
# Add more mappings as needed
|
# Add more mappings as needed
|
||||||
}
|
}
|
||||||
provider_prefix = provider_map.get(
|
provider_prefix = provider_map.get(
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
@ -73,16 +74,14 @@ class TaskLoggingService:
|
||||||
Returns:
|
Returns:
|
||||||
Log: The updated log entry
|
Log: The updated log entry
|
||||||
"""
|
"""
|
||||||
# Ensure session is in a valid state / 确保 session 处于有效状态
|
# Ensure session is in a valid state
|
||||||
if not self.session.is_active:
|
if not self.session.is_active:
|
||||||
await self.session.rollback()
|
await self.session.rollback()
|
||||||
|
|
||||||
# Refresh log_entry to avoid expired state / 刷新 log_entry 避免过期状态
|
# Refresh log_entry to avoid expired state
|
||||||
try:
|
with contextlib.suppress(Exception):
|
||||||
await self.session.refresh(log_entry)
|
await self.session.refresh(log_entry)
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Update the existing log entry
|
# Update the existing log entry
|
||||||
log_entry.status = LogStatus.SUCCESS
|
log_entry.status = LogStatus.SUCCESS
|
||||||
log_entry.message = message
|
log_entry.message = message
|
||||||
|
|
@ -124,17 +123,14 @@ class TaskLoggingService:
|
||||||
Returns:
|
Returns:
|
||||||
Log: The updated log entry
|
Log: The updated log entry
|
||||||
"""
|
"""
|
||||||
# Ensure session is in a valid state / 确保 session 处于有效状态
|
# Ensure session is in a valid state
|
||||||
if not self.session.is_active:
|
if not self.session.is_active:
|
||||||
await self.session.rollback()
|
await self.session.rollback()
|
||||||
|
|
||||||
# Refresh log_entry to avoid expired state / 刷新 log_entry 避免过期状态
|
# Refresh log_entry to avoid expired state
|
||||||
try:
|
with contextlib.suppress(Exception):
|
||||||
await self.session.refresh(log_entry)
|
await self.session.refresh(log_entry)
|
||||||
except Exception:
|
|
||||||
# If refresh fails, the object might be detached / 如果刷新失败,对象可能已分离
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Update the existing log entry
|
# Update the existing log entry
|
||||||
log_entry.status = LogStatus.FAILED
|
log_entry.status = LogStatus.FAILED
|
||||||
log_entry.level = LogLevel.ERROR
|
log_entry.level = LogLevel.ERROR
|
||||||
|
|
@ -182,16 +178,14 @@ class TaskLoggingService:
|
||||||
Returns:
|
Returns:
|
||||||
Log: The updated log entry
|
Log: The updated log entry
|
||||||
"""
|
"""
|
||||||
# Ensure session is in a valid state / 确保 session 处于有效状态
|
# Ensure session is in a valid state
|
||||||
if not self.session.is_active:
|
if not self.session.is_active:
|
||||||
await self.session.rollback()
|
await self.session.rollback()
|
||||||
|
|
||||||
# Refresh log_entry to avoid expired state / 刷新 log_entry 避免过期状态
|
# Refresh log_entry to avoid expired state
|
||||||
try:
|
with contextlib.suppress(Exception):
|
||||||
await self.session.refresh(log_entry)
|
await self.session.refresh(log_entry)
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
log_entry.message = progress_message
|
log_entry.message = progress_message
|
||||||
|
|
||||||
if progress_metadata:
|
if progress_metadata:
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,8 @@ import {
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
import { LLM_PROVIDERS } from "@/contracts/enums/llm-providers";
|
|
||||||
import { LANGUAGES } from "@/contracts/enums/languages";
|
import { LANGUAGES } from "@/contracts/enums/languages";
|
||||||
|
import { LLM_PROVIDERS } from "@/contracts/enums/llm-providers";
|
||||||
import { type CreateLLMConfig, type LLMConfig, useLLMConfigs } from "@/hooks/use-llm-configs";
|
import { type CreateLLMConfig, type LLMConfig, useLLMConfigs } from "@/hooks/use-llm-configs";
|
||||||
import InferenceParamsEditor from "../inference-params-editor";
|
import InferenceParamsEditor from "../inference-params-editor";
|
||||||
|
|
||||||
|
|
@ -489,10 +489,7 @@ export function ModelConfigManager({ searchSpaceId }: ModelConfigManagerProps) {
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="provider">Provider *</Label>
|
<Label htmlFor="provider">Provider *</Label>
|
||||||
<Select
|
<Select value={formData.provider} onValueChange={handleProviderChange}>
|
||||||
value={formData.provider}
|
|
||||||
onValueChange={handleProviderChange}
|
|
||||||
>
|
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Select a provider">
|
<SelectValue placeholder="Select a provider">
|
||||||
{formData.provider && (
|
{formData.provider && (
|
||||||
|
|
@ -548,23 +545,23 @@ export function ModelConfigManager({ searchSpaceId }: ModelConfigManagerProps) {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="language">Language (Optional)</Label>
|
<Label htmlFor="language">Language (Optional)</Label>
|
||||||
<Select
|
<Select
|
||||||
value={formData.language || "English"}
|
value={formData.language || "English"}
|
||||||
onValueChange={(value) => handleInputChange("language", value)}
|
onValueChange={(value) => handleInputChange("language", value)}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Select language" />
|
<SelectValue placeholder="Select language" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{LANGUAGES.map((language) => (
|
{LANGUAGES.map((language) => (
|
||||||
<SelectItem key={language.value} value={language.value}>
|
<SelectItem key={language.value} value={language.value}>
|
||||||
{language.label}
|
{language.label}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="api_key">API Key *</Label>
|
<Label htmlFor="api_key">API Key *</Label>
|
||||||
|
|
@ -580,7 +577,7 @@ export function ModelConfigManager({ searchSpaceId }: ModelConfigManagerProps) {
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="api_base">
|
<Label htmlFor="api_base">
|
||||||
API Base URL
|
API Base URL
|
||||||
{selectedProvider?.apiBase && (
|
{selectedProvider?.apiBase && (
|
||||||
<span className="text-xs font-normal text-muted-foreground ml-2">
|
<span className="text-xs font-normal text-muted-foreground ml-2">
|
||||||
(Auto-filled for {selectedProvider.label})
|
(Auto-filled for {selectedProvider.label})
|
||||||
|
|
@ -602,8 +599,8 @@ export function ModelConfigManager({ searchSpaceId }: ModelConfigManagerProps) {
|
||||||
{selectedProvider?.apiBase && !formData.api_base && (
|
{selectedProvider?.apiBase && !formData.api_base && (
|
||||||
<p className="text-xs text-amber-600 flex items-center gap-1">
|
<p className="text-xs text-amber-600 flex items-center gap-1">
|
||||||
<AlertCircle className="h-3 w-3" />
|
<AlertCircle className="h-3 w-3" />
|
||||||
⚠️ API Base URL is required for {selectedProvider.label}. Click to auto-fill:
|
⚠️ API Base URL is required for {selectedProvider.label}. Click to auto-fill:
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="underline font-medium"
|
className="underline font-medium"
|
||||||
onClick={() => handleInputChange("api_base", selectedProvider.apiBase || "")}
|
onClick={() => handleInputChange("api_base", selectedProvider.apiBase || "")}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue