mirror of
https://github.com/Zippland/Snap-Solver.git
synced 2026-03-05 08:06:59 +08:00
fix bugs
This commit is contained in:
27
app.py
27
app.py
@@ -132,6 +132,31 @@ def create_model_instance(model_id, settings, is_reasoning=False):
|
|||||||
elif "gemini" in model_id.lower() or "google" in model_id.lower():
|
elif "gemini" in model_id.lower() or "google" in model_id.lower():
|
||||||
base_url = proxy_api_config.get('apis', {}).get('google', '')
|
base_url = proxy_api_config.get('apis', {}).get('google', '')
|
||||||
|
|
||||||
|
# 从前端设置获取自定义API基础URL (apiBaseUrls)
|
||||||
|
api_base_urls = settings.get('apiBaseUrls', {})
|
||||||
|
if api_base_urls:
|
||||||
|
# 根据模型类型选择对应的自定义API基础URL
|
||||||
|
if "claude" in model_id.lower() or "anthropic" in model_id.lower():
|
||||||
|
custom_base_url = api_base_urls.get('anthropic')
|
||||||
|
if custom_base_url:
|
||||||
|
base_url = custom_base_url
|
||||||
|
elif any(keyword in model_id.lower() for keyword in ["gpt", "openai"]):
|
||||||
|
custom_base_url = api_base_urls.get('openai')
|
||||||
|
if custom_base_url:
|
||||||
|
base_url = custom_base_url
|
||||||
|
elif "deepseek" in model_id.lower():
|
||||||
|
custom_base_url = api_base_urls.get('deepseek')
|
||||||
|
if custom_base_url:
|
||||||
|
base_url = custom_base_url
|
||||||
|
elif "qvq" in model_id.lower() or "alibaba" in model_id.lower() or "qwen" in model_id.lower():
|
||||||
|
custom_base_url = api_base_urls.get('alibaba')
|
||||||
|
if custom_base_url:
|
||||||
|
base_url = custom_base_url
|
||||||
|
elif "gemini" in model_id.lower() or "google" in model_id.lower():
|
||||||
|
custom_base_url = api_base_urls.get('google')
|
||||||
|
if custom_base_url:
|
||||||
|
base_url = custom_base_url
|
||||||
|
|
||||||
# 创建模型实例
|
# 创建模型实例
|
||||||
model_instance = ModelFactory.create_model(
|
model_instance = ModelFactory.create_model(
|
||||||
model_name=model_id,
|
model_name=model_id,
|
||||||
@@ -139,7 +164,7 @@ def create_model_instance(model_id, settings, is_reasoning=False):
|
|||||||
temperature=None if is_reasoning else float(settings.get('temperature', 0.7)),
|
temperature=None if is_reasoning else float(settings.get('temperature', 0.7)),
|
||||||
system_prompt=settings.get('systemPrompt'),
|
system_prompt=settings.get('systemPrompt'),
|
||||||
language=settings.get('language', '中文'),
|
language=settings.get('language', '中文'),
|
||||||
base_url=base_url # 添加中转API URL
|
api_base_url=base_url # 现在BaseModel支持api_base_url参数
|
||||||
)
|
)
|
||||||
|
|
||||||
# 设置最大输出Token,但不为阿里巴巴模型设置(它们有自己内部的处理逻辑)
|
# 设置最大输出Token,但不为阿里巴巴模型设置(它们有自己内部的处理逻辑)
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ from abc import ABC, abstractmethod
|
|||||||
from typing import Generator, Any
|
from typing import Generator, Any
|
||||||
|
|
||||||
class BaseModel(ABC):
|
class BaseModel(ABC):
|
||||||
def __init__(self, api_key: str, temperature: float = 0.7, system_prompt: str = None, language: str = None):
|
def __init__(self, api_key: str, temperature: float = 0.7, system_prompt: str = None, language: str = None, api_base_url: str = None):
|
||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
self.temperature = temperature
|
self.temperature = temperature
|
||||||
self.language = language
|
self.language = language
|
||||||
self.system_prompt = system_prompt or self.get_default_system_prompt()
|
self.system_prompt = system_prompt or self.get_default_system_prompt()
|
||||||
|
self.api_base_url = api_base_url
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def analyze_image(self, image_data: str, proxies: dict = None) -> Generator[dict, None, None]:
|
def analyze_image(self, image_data: str, proxies: dict = None) -> Generator[dict, None, None]:
|
||||||
|
|||||||
@@ -547,6 +547,13 @@ class SettingsManager {
|
|||||||
await this.refreshApiKeyStatus();
|
await this.refreshApiKeyStatus();
|
||||||
console.log('已自动刷新API密钥状态');
|
console.log('已自动刷新API密钥状态');
|
||||||
|
|
||||||
|
// 加载 API 基础 URL 设置
|
||||||
|
if (settings.apiBaseUrlValues) {
|
||||||
|
this.apiBaseUrlValues = settings.apiBaseUrlValues;
|
||||||
|
await this.refreshApiBaseUrlStatus();
|
||||||
|
console.log('已加载 API 基础 URL 设置');
|
||||||
|
}
|
||||||
|
|
||||||
// 加载其他设置
|
// 加载其他设置
|
||||||
// Load model selection
|
// Load model selection
|
||||||
if (settings.model && this.modelExists(settings.model)) {
|
if (settings.model && this.modelExists(settings.model)) {
|
||||||
@@ -764,6 +771,7 @@ class SettingsManager {
|
|||||||
// 保存UI设置到localStorage(不包含API密钥)
|
// 保存UI设置到localStorage(不包含API密钥)
|
||||||
const settings = {
|
const settings = {
|
||||||
apiKeys: this.apiKeyValues, // 保存到localStorage(向后兼容)
|
apiKeys: this.apiKeyValues, // 保存到localStorage(向后兼容)
|
||||||
|
apiBaseUrlValues: this.apiBaseUrlValues, // 添加API基础URL保存到localStorage
|
||||||
model: this.modelSelect.value,
|
model: this.modelSelect.value,
|
||||||
maxTokens: this.maxTokens.value,
|
maxTokens: this.maxTokens.value,
|
||||||
reasoningDepth: this.reasoningDepthSelect?.value || 'standard',
|
reasoningDepth: this.reasoningDepthSelect?.value || 'standard',
|
||||||
@@ -879,7 +887,8 @@ class SettingsManager {
|
|||||||
provider: modelInfo.provider || 'unknown'
|
provider: modelInfo.provider || 'unknown'
|
||||||
},
|
},
|
||||||
reasoningConfig: reasoningConfig,
|
reasoningConfig: reasoningConfig,
|
||||||
apiBaseUrls: apiBaseUrls
|
apiBaseUrls: apiBaseUrls,
|
||||||
|
apiKeys: this.apiKeyValues // 确保传递API密钥
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user