feat: add standard Qwen settings checkbox to text provider
This commit is contained in:
1 parent
5dbe1427eb
commit
716002dcaf
2 files changed
+38
-11
No files matched your search
+12
-4
@@ -23,7 +23,7 @@ from ai_core.telegram_publisher import (
|
|||||||
)
|
)
|
||||||
from ai_core.tenchat_publisher import publish_post as publish_post_tenchat
|
from ai_core.tenchat_publisher import publish_post as publish_post_tenchat
|
||||||
from cabinet_service.brand_doc_generator import generate_brand_docx
|
from cabinet_service.brand_doc_generator import generate_brand_docx
|
||||||
from config import SECRET_KEY
|
from config import SECRET_KEY, QWEN_BASE_URL, QWEN_MODEL
|
||||||
from database import (
|
from database import (
|
||||||
add_post_revision,
|
add_post_revision,
|
||||||
count_user_tasks,
|
count_user_tasks,
|
||||||
@@ -461,20 +461,21 @@ def profile_edit_submit(
|
|||||||
def provider_form(request: Request, user: dict = Depends(current_user)):
|
def provider_form(request: Request, user: dict = Depends(current_user)):
|
||||||
provider = get_provider_settings(user["id"])
|
provider = get_provider_settings(user["id"])
|
||||||
return render(request, "provider.html", user=user,
|
return render(request, "provider.html", user=user,
|
||||||
provider=provider, provider_presets=PROVIDER_PRESETS)
|
provider=provider, provider_presets=PROVIDER_PRESETS,
|
||||||
|
default_text={"base_url": QWEN_BASE_URL or "", "model": QWEN_MODEL})
|
||||||
|
|
||||||
|
|
||||||
@app.post("/provider")
|
@app.post("/provider")
|
||||||
def provider_submit(
|
def provider_submit(
|
||||||
request: Request,
|
request: Request,
|
||||||
# Text provider
|
# Text provider
|
||||||
text_provider_type: str = Form(...),
|
text_provider_type: str = Form(""),
|
||||||
text_api_key: str = Form(""),
|
text_api_key: str = Form(""),
|
||||||
text_base_url: str = Form(""),
|
text_base_url: str = Form(""),
|
||||||
text_model: str = Form(""),
|
text_model: str = Form(""),
|
||||||
text_use_global: str = Form(""),
|
text_use_global: str = Form(""),
|
||||||
# Image provider
|
# Image provider
|
||||||
image_provider_type: str = Form(...),
|
image_provider_type: str = Form(""),
|
||||||
image_api_key: str = Form(""),
|
image_api_key: str = Form(""),
|
||||||
image_base_url: str = Form(""),
|
image_base_url: str = Form(""),
|
||||||
image_model: str = Form(""),
|
image_model: str = Form(""),
|
||||||
@@ -483,6 +484,10 @@ def provider_submit(
|
|||||||
):
|
):
|
||||||
errors = []
|
errors = []
|
||||||
|
|
||||||
|
# «Стандартные настройки» — это Qwen сервиса, отдельный провайдер выбирать не нужно
|
||||||
|
if text_use_global and text_provider_type not in PROVIDER_PRESETS:
|
||||||
|
text_provider_type = "qwen"
|
||||||
|
|
||||||
# Валидация text-провайдера
|
# Валидация text-провайдера
|
||||||
if text_provider_type not in PROVIDER_PRESETS:
|
if text_provider_type not in PROVIDER_PRESETS:
|
||||||
errors.append("Выберите провайдера для текста.")
|
errors.append("Выберите провайдера для текста.")
|
||||||
@@ -513,11 +518,14 @@ def provider_submit(
|
|||||||
return render(
|
return render(
|
||||||
request, "provider.html", status_code=400,
|
request, "provider.html", status_code=400,
|
||||||
user=user, provider_presets=PROVIDER_PRESETS, errors=errors,
|
user=user, provider_presets=PROVIDER_PRESETS, errors=errors,
|
||||||
|
default_text={"base_url": QWEN_BASE_URL or "", "model": QWEN_MODEL},
|
||||||
form={
|
form={
|
||||||
"text_provider_type": text_provider_type, "text_api_key": text_api_key,
|
"text_provider_type": text_provider_type, "text_api_key": text_api_key,
|
||||||
"text_base_url": text_base_url, "text_model": text_model,
|
"text_base_url": text_base_url, "text_model": text_model,
|
||||||
|
"text_use_global": text_use_global,
|
||||||
"image_provider_type": image_provider_type, "image_api_key": image_api_key,
|
"image_provider_type": image_provider_type, "image_api_key": image_api_key,
|
||||||
"image_base_url": image_base_url, "image_model": image_model,
|
"image_base_url": image_base_url, "image_model": image_model,
|
||||||
|
"image_use_global": image_use_global,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
{%- macro provider_fields(kind) -%}
|
{%- macro provider_fields(kind) -%}
|
||||||
{%- set p_type = provider[kind ~ '_provider_type'] if provider else '' -%}
|
{%- set p_type = provider[kind ~ '_provider_type'] if provider else '' -%}
|
||||||
|
{%- set use_global_checked = (kind == 'text') and ((form and form['text_use_global']) or (not form and (not provider or not provider['text_api_key']))) -%}
|
||||||
<div class="ps-field">
|
<div class="ps-field">
|
||||||
<label for="{{ kind }}ProviderType" class="ps-field-label">Провайдер</label>
|
<label for="{{ kind }}ProviderType" class="ps-field-label">Провайдер</label>
|
||||||
<div class="ps-select">
|
<div class="ps-select">
|
||||||
@@ -39,15 +40,15 @@
|
|||||||
value="{{ form[kind ~ '_base_url'] if form else (provider[kind ~ '_base_url'] if provider else '') }}" placeholder="https://…">
|
value="{{ form[kind ~ '_base_url'] if form else (provider[kind ~ '_base_url'] if provider else '') }}" placeholder="https://…">
|
||||||
</div>
|
</div>
|
||||||
<label class="app-check" style="grid-column: 1 / -1">
|
<label class="app-check" style="grid-column: 1 / -1">
|
||||||
<input type="checkbox" name="{{ kind }}_use_global" value="1" id="{{ kind }}UseGlobal" onchange="toggleGlobal('{{ kind }}')">
|
<input type="checkbox" name="{{ kind }}_use_global" value="1" id="{{ kind }}UseGlobal" onchange="toggleGlobal('{{ kind }}')" {% if use_global_checked %}checked{% endif %}>
|
||||||
<span>Использовать глобальные настройки (PiAPI)</span>
|
<span>{% if kind == 'text' %}Использовать стандартные настройки (Qwen){% else %}Использовать глобальные настройки (PiAPI){% endif %}</span>
|
||||||
</label>
|
</label>
|
||||||
{%- endmacro -%}
|
{%- endmacro -%}
|
||||||
|
|
||||||
<div class="ps-main-head">
|
<div class="ps-main-head">
|
||||||
<div>
|
<div>
|
||||||
<h1 class="ps-h1">ИИ-провайдеры</h1>
|
<h1 class="ps-h1">ИИ-провайдеры</h1>
|
||||||
<p class="ps-lead">Текст и картинки можно генерировать через разных провайдеров. Без своих настроек работают глобальные настройки сервиса (PiAPI).</p>
|
<p class="ps-lead">Текст и картинки можно генерировать через разных провайдеров. По умолчанию текст идёт через Qwen сервиса, картинки — через глобальные настройки (PiAPI).</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -60,16 +61,17 @@
|
|||||||
<h2 class="ps-provider-title">Текст</h2>
|
<h2 class="ps-provider-title">Текст</h2>
|
||||||
<span class="ps-provider-desc">Посты, правки в чате, контент-план, анализ соцсетей</span>
|
<span class="ps-provider-desc">Посты, правки в чате, контент-план, анализ соцсетей</span>
|
||||||
</span>
|
</span>
|
||||||
{% if provider %}
|
{% if provider and provider.text_api_key %}
|
||||||
<span class="ps-badge ps-badge--success">{{ ui.icon('check', 14) }}<span>Подключено</span></span>
|
<span class="ps-badge ps-badge--success">{{ ui.icon('check', 14) }}<span>Подключено</span></span>
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="ps-badge ps-badge--neutral">{{ ui.icon('info', 14) }}<span>Не настроено</span></span>
|
<span class="ps-badge ps-badge--neutral">{{ ui.icon('info', 14) }}<span>Стандартные (Qwen)</span></span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</header>
|
</header>
|
||||||
<div class="ps-provider-body" style="grid-template-columns: 1fr">{{ provider_fields('text') }}</div>
|
<div class="ps-provider-body" style="grid-template-columns: 1fr">{{ provider_fields('text') }}</div>
|
||||||
<details>
|
<details>
|
||||||
<summary>Популярные модели</summary>
|
<summary>Популярные модели</summary>
|
||||||
<ul class="form-hint" style="margin: 8px 0 0; padding-left: 18px">
|
<ul class="form-hint" style="margin: 8px 0 0; padding-left: 18px">
|
||||||
|
<li><code>{{ default_text.model }}</code> — стандартный Qwen сервиса</li>
|
||||||
<li><code>gpt-4o</code> — OpenAI, OpenRouter, PiAPI</li>
|
<li><code>gpt-4o</code> — OpenAI, OpenRouter, PiAPI</li>
|
||||||
<li><code>claude-sonnet-5</code> — Anthropic через OpenRouter</li>
|
<li><code>claude-sonnet-5</code> — Anthropic через OpenRouter</li>
|
||||||
<li><code>glm-5.2</code> — OpenCode Zen (платная)</li>
|
<li><code>glm-5.2</code> — OpenCode Zen (платная)</li>
|
||||||
@@ -129,6 +131,7 @@ const PRESETS = {
|
|||||||
"{{ key }}": {"base_url": "{{ preset.base_url }}", "text_model": "{{ preset.text_model }}", "image_model": "{{ preset.image_model }}"},
|
"{{ key }}": {"base_url": "{{ preset.base_url }}", "text_model": "{{ preset.text_model }}", "image_model": "{{ preset.image_model }}"},
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
};
|
};
|
||||||
|
const DEFAULT_TEXT = {"base_url": "{{ default_text.base_url }}", "model": "{{ default_text.model }}"};
|
||||||
|
|
||||||
function updatePresets(kind) {
|
function updatePresets(kind) {
|
||||||
var typeEl = document.getElementById(kind + "ProviderType");
|
var typeEl = document.getElementById(kind + "ProviderType");
|
||||||
@@ -149,18 +152,34 @@ function toggleGlobal(kind) {
|
|||||||
var key = document.getElementById(kind + "ApiKey");
|
var key = document.getElementById(kind + "ApiKey");
|
||||||
var baseUrl = document.getElementById(kind + "BaseUrl");
|
var baseUrl = document.getElementById(kind + "BaseUrl");
|
||||||
var model = document.getElementById(kind + "Model");
|
var model = document.getElementById(kind + "Model");
|
||||||
|
var typeEl = document.getElementById(kind + "ProviderType");
|
||||||
if (cb.checked) {
|
if (cb.checked) {
|
||||||
key.disabled = true;
|
key.disabled = true;
|
||||||
key.placeholder = "Используются глобальные настройки";
|
key.placeholder = "Используются стандартные настройки";
|
||||||
key.value = "";
|
key.value = "";
|
||||||
|
if (kind === "text") {
|
||||||
|
if (typeEl) typeEl.value = "qwen";
|
||||||
|
baseUrl.value = DEFAULT_TEXT.base_url;
|
||||||
|
model.value = DEFAULT_TEXT.model;
|
||||||
|
baseUrl.disabled = true;
|
||||||
|
model.disabled = true;
|
||||||
|
} else {
|
||||||
baseUrl.value = "https://api.piapi.ai/v1";
|
baseUrl.value = "https://api.piapi.ai/v1";
|
||||||
model.value = (kind === "text") ? "gpt-4o" : "gpt-image-1";
|
model.value = "gpt-image-1";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
key.disabled = false;
|
key.disabled = false;
|
||||||
key.placeholder = "Ваш API-ключ";
|
key.placeholder = "Ваш API-ключ";
|
||||||
|
baseUrl.disabled = false;
|
||||||
|
model.disabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
var cb = document.getElementById('textUseGlobal');
|
||||||
|
if (cb && cb.checked) toggleGlobal('text');
|
||||||
|
});
|
||||||
|
|
||||||
document.addEventListener('click', function (e) {
|
document.addEventListener('click', function (e) {
|
||||||
var b = e.target.closest('[data-secret-toggle]'); if (!b) return;
|
var b = e.target.closest('[data-secret-toggle]'); if (!b) return;
|
||||||
var input = b.parentNode.querySelector('input');
|
var input = b.parentNode.querySelector('input');
|
||||||
|
|||||||
Reference in new issue
Block a user