diff --git a/app.py b/app.py index c1ec895..6c329c7 100644 --- a/app.py +++ b/app.py @@ -49,7 +49,7 @@ LLM_CONFIG = { 'vision_model': 'gpt-4-vision-preview', # 视觉模型(解析图片) } -# 默认网站配置 +# 默认网站配置(包含LLM配置) DEFAULT_CONFIG = { 'site_name': 'ParamHub', 'site_subtitle': '参数百科', @@ -58,12 +58,31 @@ DEFAULT_CONFIG = { 'copyright_year': '2024', 'contact_email': '', 'github_url': '', + # LLM配置 + 'llm_base_url': 'http://192.168.2.17:19007/v1', + 'llm_api_key': '', + 'llm_model': 'auto', + 'llm_vision_model': 'gpt-4-vision-preview', } +def get_llm_config(): + """获取LLM配置(从config.json动态读取)""" + config = load_config() + return { + 'base_url': config.get('llm_base_url', DEFAULT_CONFIG['llm_base_url']), + 'api_key': config.get('llm_api_key', DEFAULT_CONFIG['llm_api_key']), + 'model': config.get('llm_model', DEFAULT_CONFIG['llm_model']), + 'vision_model': config.get('llm_vision_model', DEFAULT_CONFIG['llm_vision_model']), + } + def load_config(): """加载网站配置""" if CONFIG_FILE.exists(): - return json.loads(CONFIG_FILE.read_text(encoding='utf-8')) + loaded = json.loads(CONFIG_FILE.read_text(encoding='utf-8')) + # 合并默认配置(确保新字段存在) + result = DEFAULT_CONFIG.copy() + result.update(loaded) + return result return DEFAULT_CONFIG.copy() def save_config(config): @@ -219,14 +238,17 @@ def parse_with_llm(text, category_type, images=None): }) try: - # 使用视觉模型解析 - model = LLM_CONFIG.get('vision_model', 'gpt-4-vision-preview') if images else LLM_CONFIG['model'] + # 动态获取LLM配置 + llm_config = get_llm_config() + + # 使用视觉模型解析(如果有图片) + model = llm_config.get('vision_model', 'gpt-4-vision-preview') if images else llm_config['model'] response = requests.post( - f"{LLM_CONFIG['base_url']}/chat/completions", + f"{llm_config['base_url']}/chat/completions", headers={ "Content-Type": "application/json", - "Authorization": f"Bearer {LLM_CONFIG['api_key']}" + "Authorization": f"Bearer {llm_config['api_key']}" }, json={ "model": model, diff --git a/templates/admin.html b/templates/admin.html index 0acba2c..cc8a32a 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -57,6 +57,8 @@

网站配置

+ +

网站基础配置

@@ -87,6 +89,33 @@
+ + +

大模型接口配置(用于智能解析)

+
+

配置用于智能解析产品参数的大模型API接口。文本解析使用普通模型,图片解析使用视觉模型。

+
+
+
+ + +
+
+ + +
+
+ + +

用于解析文本数据,如 deepseek-v3、qwen3.5 等

+
+
+ + +

用于解析图片,如 Qwen/Qwen2-VL-72B-Instruct、gpt-4-vision-preview 等

+
+
+
@@ -553,6 +582,7 @@ const res = await fetch('/api/config'); const config = await res.json(); + // 网站基础配置 document.getElementById('config_site_name').value = config.site_name || ''; document.getElementById('config_site_subtitle').value = config.site_subtitle || ''; document.getElementById('config_icp_number').value = config.icp_number || ''; @@ -560,11 +590,18 @@ document.getElementById('config_github_url').value = config.github_url || ''; document.getElementById('config_copyright_year').value = config.copyright_year || ''; document.getElementById('config_footer_text').value = config.footer_text || ''; + + // LLM配置 + document.getElementById('config_llm_base_url').value = config.llm_base_url || 'http://192.168.2.17:19007/v1'; + document.getElementById('config_llm_api_key').value = config.llm_api_key || ''; + document.getElementById('config_llm_model').value = config.llm_model || 'auto'; + document.getElementById('config_llm_vision_model').value = config.llm_vision_model || 'gpt-4-vision-preview'; } // 保存网站配置 async function saveSiteConfig() { const config = { + // 网站基础配置 site_name: document.getElementById('config_site_name').value, site_subtitle: document.getElementById('config_site_subtitle').value, icp_number: document.getElementById('config_icp_number').value, @@ -572,6 +609,11 @@ github_url: document.getElementById('config_github_url').value, copyright_year: document.getElementById('config_copyright_year').value, footer_text: document.getElementById('config_footer_text').value, + // LLM配置 + llm_base_url: document.getElementById('config_llm_base_url').value, + llm_api_key: document.getElementById('config_llm_api_key').value, + llm_model: document.getElementById('config_llm_model').value, + llm_vision_model: document.getElementById('config_llm_vision_model').value, }; try {