Files
links/jbot/models.py
T
junvandCopilot a47ea316c7 feat(jbot): UI-configurable API keys + fix Dockerfile
- Add JbotApiConfig Django model (DB singleton) for storing
  Volcengine/OpenRouter credentials set via Settings UI
- New endpoint GET/POST /api/jbot/api-config/ — tokens masked as ***
  on read; only non-placeholder values are updated on write
- views.py: _get_cfg() helper reads DB first, env vars as fallback
- Settings.jsx: new 🔑 API 配置 section with show/hide token fields
  for VOLC App ID, Access Token, OpenRouter API Key, LLM Model, ASR Resource
- api.js: apiGetApiConfig() / apiSaveApiConfig() client helpers
- Dockerfile: COPY jbot/ in both builder + production stages (was missing)
- entrypoint.sh: runs migrate --noinput before gunicorn (auto-creates table)
- k8s/manifest.yaml: remove jbot-credentials secretKeyRef (no Secret needed);
  keep LLM_MODEL/VOLC_TTS_VOICE/VOLC_ASR_RESOURCE as optional env defaults

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-17 14:13:37 +10:00

28 lines
1.2 KiB
Python

from django.db import models
class JbotApiConfig(models.Model):
"""Singleton model storing JBOT API credentials and runtime defaults.
Configured via the Settings UI at /jbot/settings — env vars are fallback only.
"""
volc_app_id = models.CharField(max_length=200, blank=True, default='')
volc_access_token = models.CharField(max_length=500, blank=True, default='')
openrouter_api_key = models.CharField(max_length=200, blank=True, default='')
llm_model = models.CharField(max_length=200, blank=True, default='deepseek/deepseek-chat')
volc_tts_voice = models.CharField(max_length=200, blank=True, default='zh_female_vv_uranus_bigtts')
volc_asr_resource = models.CharField(max_length=200, blank=True, default='volc.bigasr.sauc.duration')
updated_at = models.DateTimeField(auto_now=True)
class Meta:
verbose_name = 'JBOT API Config'
@classmethod
def load(cls):
"""Return the singleton row, creating it if needed."""
obj, _ = cls.objects.get_or_create(pk=1)
return obj
def save(self, *args, **kwargs):
self.pk = 1
super().save(*args, **kwargs)