mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-09-05 07:26:39 +08:00
feat(config): 添加模型助手功能以选择和管理模型
本次提交主要包含以下更改: 1. **后端更新**: - 在 `app/service/config/config_service.py` 中新增 `fetch_ui_models` 方法,用于获取可用于 UI 的模型列表,并处理相关的错误情况。 - 在 `app/router/config_routes.py` 中新增 `/ui/models` 路由,提供模型列表的 API 接口,并添加身份验证逻辑。 2. **前端更新**: - 在 `app/static/js/config_editor.js` 中实现模型助手的功能,包括模型列表的加载、搜索和选择。 - 在 `app/templates/config_editor.html` 中添加模型助手的模态框和相关的 UI 元素,允许用户从列表中选择模型。 这些更改旨在增强用户体验,使用户能够更方便地选择和管理模型,提高配置界面的交互性和功能性。
This commit is contained in:
@@ -557,13 +557,23 @@ endblock %} {% block head_extra_styles %}
|
||||
<label for="TEST_MODEL" class="block font-semibold mb-2 text-gray-700"
|
||||
>测试模型</label
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
id="TEST_MODEL"
|
||||
name="TEST_MODEL"
|
||||
placeholder="gemini-1.5-flash"
|
||||
class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:border-primary-500 focus:ring focus:ring-primary-200 focus:ring-opacity-50 form-input-themed"
|
||||
/>
|
||||
<div class="flex items-center gap-2">
|
||||
<input
|
||||
type="text"
|
||||
id="TEST_MODEL"
|
||||
name="TEST_MODEL"
|
||||
placeholder="gemini-1.5-flash"
|
||||
class="flex-grow px-4 py-3 rounded-lg border border-gray-300 focus:border-primary-500 focus:ring focus:ring-primary-200 focus:ring-opacity-50 form-input-themed"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
title="选择模型"
|
||||
class="model-helper-trigger-btn p-2 rounded-md text-violet-300 hover:bg-violet-700 transition-colors"
|
||||
data-target-input-id="TEST_MODEL"
|
||||
>
|
||||
<i class="fas fa-list-ul"></i>
|
||||
</button>
|
||||
</div>
|
||||
<small class="text-gray-500 mt-1 block">用于测试API密钥的模型</small>
|
||||
</div>
|
||||
|
||||
@@ -577,7 +587,15 @@ endblock %} {% block head_extra_styles %}
|
||||
<div class="array-container" id="IMAGE_MODELS_container">
|
||||
<!-- 数组项将在这里动态添加 -->
|
||||
</div>
|
||||
<div class="flex justify-end">
|
||||
<div class="flex justify-end gap-2 mt-2">
|
||||
<button
|
||||
type="button"
|
||||
title="从列表选择模型添加到下方"
|
||||
class="model-helper-trigger-btn p-2 rounded-md text-violet-300 hover:bg-violet-700 transition-colors"
|
||||
data-target-array-key="IMAGE_MODELS"
|
||||
>
|
||||
<i class="fas fa-list-ul"></i>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="bg-violet-600 hover:bg-violet-700 text-white px-4 py-2 rounded-lg font-medium transition-all duration-200 flex items-center gap-2"
|
||||
@@ -599,7 +617,15 @@ endblock %} {% block head_extra_styles %}
|
||||
<div class="array-container" id="SEARCH_MODELS_container">
|
||||
<!-- 数组项将在这里动态添加 -->
|
||||
</div>
|
||||
<div class="flex justify-end">
|
||||
<div class="flex justify-end gap-2 mt-2">
|
||||
<button
|
||||
type="button"
|
||||
title="从列表选择模型添加到下方"
|
||||
class="model-helper-trigger-btn p-2 rounded-md text-violet-300 hover:bg-violet-700 transition-colors"
|
||||
data-target-array-key="SEARCH_MODELS"
|
||||
>
|
||||
<i class="fas fa-list-ul"></i>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="bg-violet-600 hover:bg-violet-700 text-white px-4 py-2 rounded-lg font-medium transition-all duration-200 flex items-center gap-2"
|
||||
@@ -621,7 +647,15 @@ endblock %} {% block head_extra_styles %}
|
||||
<div class="array-container" id="FILTERED_MODELS_container">
|
||||
<!-- 数组项将在这里动态添加 -->
|
||||
</div>
|
||||
<div class="flex justify-end">
|
||||
<div class="flex justify-end gap-2 mt-2">
|
||||
<button
|
||||
type="button"
|
||||
title="从列表选择模型添加到下方"
|
||||
class="model-helper-trigger-btn p-2 rounded-md text-violet-300 hover:bg-violet-700 transition-colors"
|
||||
data-target-array-key="FILTERED_MODELS"
|
||||
>
|
||||
<i class="fas fa-list-ul"></i>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="bg-violet-600 hover:bg-violet-700 text-white px-4 py-2 rounded-lg font-medium transition-all duration-200 flex items-center gap-2"
|
||||
@@ -708,7 +742,15 @@ endblock %} {% block head_extra_styles %}
|
||||
<div class="array-container" id="THINKING_MODELS_container">
|
||||
<!-- 数组项将在这里动态添加 -->
|
||||
</div>
|
||||
<div class="flex justify-end">
|
||||
<div class="flex justify-end gap-2 mt-2">
|
||||
<button
|
||||
type="button"
|
||||
title="从列表选择模型添加到下方"
|
||||
class="model-helper-trigger-btn p-2 rounded-md text-violet-300 hover:bg-violet-700 transition-colors"
|
||||
data-target-array-key="THINKING_MODELS"
|
||||
>
|
||||
<i class="fas fa-list-ul"></i>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="bg-violet-600 hover:bg-violet-700 text-white px-4 py-2 rounded-lg font-medium transition-all duration-200 flex items-center gap-2"
|
||||
@@ -829,13 +871,23 @@ endblock %} {% block head_extra_styles %}
|
||||
class="block font-semibold mb-2 text-gray-700"
|
||||
>图像生成模型</label
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
id="CREATE_IMAGE_MODEL"
|
||||
name="CREATE_IMAGE_MODEL"
|
||||
placeholder="imagen-3.0-generate-002"
|
||||
class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:border-primary-500 focus:ring focus:ring-primary-200 focus:ring-opacity-50 form-input-themed"
|
||||
/>
|
||||
<div class="flex items-center gap-2">
|
||||
<input
|
||||
type="text"
|
||||
id="CREATE_IMAGE_MODEL"
|
||||
name="CREATE_IMAGE_MODEL"
|
||||
placeholder="imagen-3.0-generate-002"
|
||||
class="flex-grow px-4 py-3 rounded-lg border border-gray-300 focus:border-primary-500 focus:ring focus:ring-primary-200 focus:ring-opacity-50 form-input-themed"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
title="选择模型"
|
||||
class="model-helper-trigger-btn p-2 rounded-md text-violet-300 hover:bg-violet-700 transition-colors"
|
||||
data-target-input-id="CREATE_IMAGE_MODEL"
|
||||
>
|
||||
<i class="fas fa-list-ul"></i>
|
||||
</button>
|
||||
</div>
|
||||
<small class="text-gray-500 mt-1 block">用于图像生成的模型</small>
|
||||
</div>
|
||||
|
||||
@@ -1505,6 +1557,55 @@ endblock %} {% block head_extra_styles %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Model Helper Modal -->
|
||||
<div id="modelHelperModal" class="modal">
|
||||
<div
|
||||
class="w-full max-w-lg mx-auto rounded-2xl shadow-2xl overflow-hidden animate-fade-in"
|
||||
style="
|
||||
background-color: rgba(70, 50, 150, 0.95);
|
||||
color: #ffffff;
|
||||
border: 1px solid rgba(120, 100, 200, 0.4);
|
||||
"
|
||||
>
|
||||
<div class="p-6">
|
||||
<div class="flex justify-between items-center mb-4">
|
||||
<h2 id="modelHelperTitle" class="text-xl font-bold text-gray-100">
|
||||
选择模型
|
||||
</h2>
|
||||
<button
|
||||
id="closeModelHelperModalBtn"
|
||||
class="text-gray-300 hover:text-gray-100 text-xl"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
<input
|
||||
type="text"
|
||||
id="modelHelperSearchInput"
|
||||
placeholder="搜索模型..."
|
||||
class="w-full px-4 py-3 mb-4 rounded-lg border font-mono text-sm form-input-themed"
|
||||
/>
|
||||
<div
|
||||
id="modelHelperListContainer"
|
||||
class="array-container"
|
||||
style="max-height: 300px; overflow-y: auto"
|
||||
>
|
||||
<!-- Model items will be populated here -->
|
||||
<p class="text-gray-400 text-sm italic">正在加载模型列表...</p>
|
||||
</div>
|
||||
<div class="flex justify-end gap-3 mt-6">
|
||||
<button
|
||||
type="button"
|
||||
id="cancelModelHelperBtn"
|
||||
class="bg-gray-500 bg-opacity-50 hover:bg-opacity-70 text-gray-200 px-6 py-2 rounded-lg font-medium transition"
|
||||
>
|
||||
关闭
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %} {% block body_scripts %}
|
||||
<script src="/static/js/config_editor.js"></script>
|
||||
<!-- 增强下拉框样式和交互性 -->
|
||||
|
||||
Reference in New Issue
Block a user