mirror of
https://github.com/handsomezhuzhu/QQuiz.git
synced 2026-02-20 12:00:14 +00:00
主要功能: - 🎯 新增 Google Gemini AI 提供商支持 - 原生 PDF 理解能力(最多1000页) - 完整保留图片、表格、公式等内容 - 支持自定义 Base URL(用于代理/中转服务) - 🤖 实现 AI 参考答案自动生成 - 当题目缺少答案时自动调用 AI 生成参考答案 - 支持单选、多选、判断、简答等所有题型 - 答案标记为"AI参考答案:"便于识别 - 🔧 优化文档解析功能 - 改进中文 Prompt 提高识别准确度 - 自动修复 JSON 中的控制字符(换行符等) - 智能题目类型验证和自动转换(proof→short等) - 增加超时时间和重试机制 - 🎨 完善管理后台配置界面 - 新增 Gemini 配置区域 - 突出显示 PDF 原生支持特性 - 为其他提供商添加"仅文本"警告 - 支持 Gemini Base URL 自定义 技术改进: - 添加 google-genai 依赖 - 实现异步 API 调用适配 - 完善错误处理和日志输出 - 统一配置管理和数据库存储 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
"""
|
|
Configuration Service - Load system configuration from database
|
|
"""
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from sqlalchemy import select
|
|
from typing import Dict
|
|
from models import SystemConfig
|
|
|
|
|
|
async def load_llm_config(db: AsyncSession) -> Dict[str, str]:
|
|
"""
|
|
Load LLM configuration from database.
|
|
|
|
Returns a dictionary with all LLM-related configuration:
|
|
{
|
|
'ai_provider': 'openai',
|
|
'openai_api_key': 'sk-...',
|
|
'openai_base_url': 'https://api.openai.com/v1',
|
|
'openai_model': 'gpt-4o-mini',
|
|
...
|
|
}
|
|
"""
|
|
# Fetch all config from database
|
|
result = await db.execute(select(SystemConfig))
|
|
db_configs = {config.key: config.value for config in result.scalars().all()}
|
|
|
|
# Build configuration dictionary
|
|
config = {
|
|
'ai_provider': db_configs.get('ai_provider', 'gemini'),
|
|
# OpenAI
|
|
'openai_api_key': db_configs.get('openai_api_key'),
|
|
'openai_base_url': db_configs.get('openai_base_url', 'https://api.openai.com/v1'),
|
|
'openai_model': db_configs.get('openai_model', 'gpt-4o-mini'),
|
|
# Anthropic
|
|
'anthropic_api_key': db_configs.get('anthropic_api_key'),
|
|
'anthropic_model': db_configs.get('anthropic_model', 'claude-3-haiku-20240307'),
|
|
# Qwen
|
|
'qwen_api_key': db_configs.get('qwen_api_key'),
|
|
'qwen_base_url': db_configs.get('qwen_base_url', 'https://dashscope.aliyuncs.com/compatible-mode/v1'),
|
|
'qwen_model': db_configs.get('qwen_model', 'qwen-plus'),
|
|
# Gemini
|
|
'gemini_api_key': db_configs.get('gemini_api_key'),
|
|
'gemini_base_url': db_configs.get('gemini_base_url'), # Optional, defaults to Google's API
|
|
'gemini_model': db_configs.get('gemini_model', 'gemini-2.0-flash-exp')
|
|
}
|
|
|
|
return config
|