chore: removed chinese comments to pass ruff checks and updated migration nos

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2025-10-13 20:07:32 -07:00
parent c99469bfdf
commit ba5bb91a7b
5 changed files with 41 additions and 58 deletions

View file

@ -21,7 +21,6 @@ from app.db import Base # Assuming your Base is defined in app.db
config = context.config
# Override SQLAlchemy URL from environment variables when available
# 如果环境变量提供了数据库连接字符串,则优先使用该配置
database_url = os.getenv("DATABASE_URL")
if database_url:
config.set_main_option("sqlalchemy.url", database_url)

View file

@ -1,8 +1,7 @@
"""Add Chinese LLM providers to LiteLLMProvider enum
添加国产 LLM 提供商到 LiteLLMProvider 枚举
Revision ID: 26
Revises: 25
Revision ID: 28
Revises: 27
"""
from collections.abc import Sequence
@ -10,8 +9,8 @@ from collections.abc import Sequence
from alembic import op
# revision identifiers, used by Alembic.
revision: str = "26"
down_revision: str | None = "25"
revision: str = "28"
down_revision: str | None = "27"
branch_labels: 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:
"""
Add Chinese LLM providers to LiteLLMProvider enum.
添加国产 LLM 提供商到 LiteLLMProvider 枚举
Adds support for:
- DEEPSEEK: DeepSeek AI models
- ALIBABA_QWEN: Alibaba Qwen (通义千问) models
- MOONSHOT: Moonshot AI (月之暗面 Kimi) models
- ZHIPU: Zhipu AI (智谱 GLM) models
- ALIBABA_QWEN: Alibaba Qwen models
- MOONSHOT: Moonshot AI models
- ZHIPU: Zhipu AI models
"""
# Add DEEPSEEK to the enum if it doesn't already exist
# 如果不存在则添加 DEEPSEEK 到枚举
op.execute(
"""
DO $$
@ -44,9 +41,8 @@ def upgrade() -> None:
END$$;
"""
)
# Add ALIBABA_QWEN to the enum if it doesn't already exist
# 如果不存在则添加 ALIBABA_QWEN 到枚举
op.execute(
"""
DO $$
@ -61,9 +57,8 @@ def upgrade() -> None:
END$$;
"""
)
# Add MOONSHOT to the enum if it doesn't already exist
# 如果不存在则添加 MOONSHOT 到枚举
op.execute(
"""
DO $$
@ -78,9 +73,8 @@ def upgrade() -> None:
END$$;
"""
)
# Add ZHIPU to the enum if it doesn't already exist
# 如果不存在则添加 ZHIPU 到枚举
op.execute(
"""
DO $$
@ -100,19 +94,14 @@ def upgrade() -> None:
def downgrade() -> None:
"""
Remove Chinese LLM providers from LiteLLMProvider enum.
LiteLLMProvider 枚举中移除国产 LLM 提供商
Note: PostgreSQL doesn't support removing enum values directly.
This would require recreating the enum type and updating all dependent objects.
For safety, this downgrade is a no-op.
注意PostgreSQL 不支持直接删除枚举值
这需要重建枚举类型并更新所有依赖对象
为了安全起见此降级操作为空操作
"""
# PostgreSQL doesn't support removing enum values directly
# This would require a complex migration recreating the enum
# PostgreSQL 不支持直接删除枚举值
# 这需要复杂的迁移来重建枚举
pass

View file

@ -83,6 +83,7 @@ class LiteLLMProvider(str, Enum):
Enum for LLM providers supported by LiteLLM.
LiteLLM 支持的 LLM 提供商枚举
"""
OPENAI = "OPENAI"
ANTHROPIC = "ANTHROPIC"
GROQ = "GROQ"
@ -106,11 +107,11 @@ class LiteLLMProvider(str, Enum):
ALEPH_ALPHA = "ALEPH_ALPHA"
PETALS = "PETALS"
COMETAPI = "COMETAPI"
# Chinese LLM Providers (OpenAI-compatible) / 国产 LLM 提供商OpenAI 兼容)
DEEPSEEK = "DEEPSEEK" # DeepSeek
ALIBABA_QWEN = "ALIBABA_QWEN" # 阿里通义千问
MOONSHOT = "MOONSHOT" # 月之暗面 (Kimi)
ZHIPU = "ZHIPU" # 智谱 AI (GLM)
# Chinese LLM Providers (OpenAI-compatible)
DEEPSEEK = "DEEPSEEK"
ALIBABA_QWEN = "ALIBABA_QWEN"
MOONSHOT = "MOONSHOT"
ZHIPU = "ZHIPU"
CUSTOM = "CUSTOM"

View file

@ -99,11 +99,11 @@ async def get_user_llm_instance(
"AZURE_OPENAI": "azure",
"OPENROUTER": "openrouter",
"COMETAPI": "cometapi",
# Chinese LLM providers (OpenAI-compatible) / 国产 LLMOpenAI 兼容)
"DEEPSEEK": "openai", # DeepSeek uses OpenAI-compatible API
"ALIBABA_QWEN": "openai", # Qwen uses OpenAI-compatible API
"MOONSHOT": "openai", # Moonshot (Kimi) uses OpenAI-compatible API
"ZHIPU": "openai", # Zhipu (GLM) uses OpenAI-compatible API
# Chinese LLM providers (OpenAI-compatible)
"DEEPSEEK": "openai", # DeepSeek uses OpenAI-compatible API
"ALIBABA_QWEN": "openai", # Qwen uses OpenAI-compatible API
"MOONSHOT": "openai", # Moonshot (Kimi) uses OpenAI-compatible API
"ZHIPU": "openai", # Zhipu (GLM) uses OpenAI-compatible API
# Add more mappings as needed
}
provider_prefix = provider_map.get(

View file

@ -1,3 +1,4 @@
import contextlib
import logging
from datetime import datetime
from typing import Any
@ -73,16 +74,14 @@ class TaskLoggingService:
Returns:
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:
await self.session.rollback()
# Refresh log_entry to avoid expired state / 刷新 log_entry 避免过期状态
try:
# Refresh log_entry to avoid expired state
with contextlib.suppress(Exception):
await self.session.refresh(log_entry)
except Exception:
pass
# Update the existing log entry
log_entry.status = LogStatus.SUCCESS
log_entry.message = message
@ -124,17 +123,14 @@ class TaskLoggingService:
Returns:
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:
await self.session.rollback()
# Refresh log_entry to avoid expired state / 刷新 log_entry 避免过期状态
try:
# Refresh log_entry to avoid expired state
with contextlib.suppress(Exception):
await self.session.refresh(log_entry)
except Exception:
# If refresh fails, the object might be detached / 如果刷新失败,对象可能已分离
pass
# Update the existing log entry
log_entry.status = LogStatus.FAILED
log_entry.level = LogLevel.ERROR
@ -182,16 +178,14 @@ class TaskLoggingService:
Returns:
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:
await self.session.rollback()
# Refresh log_entry to avoid expired state / 刷新 log_entry 避免过期状态
try:
# Refresh log_entry to avoid expired state
with contextlib.suppress(Exception):
await self.session.refresh(log_entry)
except Exception:
pass
log_entry.message = progress_message
if progress_metadata: