- Ensure correct editing of additional Agent configuration possiblities when editing a specialist.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from flask import session
|
from flask import session, current_app
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import (StringField, BooleanField, SelectField, TextAreaField)
|
from wtforms import (StringField, BooleanField, SelectField, TextAreaField)
|
||||||
from wtforms.fields.datetime import DateField
|
from wtforms.fields.datetime import DateField
|
||||||
@@ -95,12 +95,54 @@ class EditEveAIAgentForm(BaseEditComponentForm):
|
|||||||
llm_model = SelectField('LLM Model', validators=[Optional()])
|
llm_model = SelectField('LLM Model', validators=[Optional()])
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
obj = kwargs.get('obj')
|
||||||
|
agent_type = None
|
||||||
|
agent_type_version = None
|
||||||
|
if obj:
|
||||||
|
agent_type = obj.type
|
||||||
|
agent_type_version = obj.type_version
|
||||||
|
current_llm_model = obj.llm_model
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
agent_config = cache_manager.agents_config_cache.get_config(self.type, self.type_version)
|
|
||||||
if agent_config.get('allowed_models', None):
|
# Choices instellen
|
||||||
self.llm_model.choices = agent_config.allowed_models
|
if agent_type and agent_type_version:
|
||||||
|
current_app.logger.info(f"Loading agent config for {agent_type} {agent_type_version}")
|
||||||
|
self._agent_config = cache_manager.agents_config_cache.get_config(agent_type, agent_type_version)
|
||||||
|
allowed_models = self._agent_config.get('allowed_models', None)
|
||||||
|
full_model_name = self._agent_config.get('full_model_name', 'mistral.mistral-medium-latest')
|
||||||
|
if allowed_models:
|
||||||
|
# Converteer lijst van strings naar lijst van tuples (value, label)
|
||||||
|
self.llm_model.choices = [(model, model) for model in allowed_models]
|
||||||
|
# Als er een waarde in de database staat, voeg die dan toe als die niet in de lijst zou voorkomen
|
||||||
|
if current_llm_model and current_llm_model not in allowed_models:
|
||||||
|
current_app.logger.warning(
|
||||||
|
f"Current model {current_llm_model} not in allowed models, adding it to choices"
|
||||||
|
)
|
||||||
|
self.llm_model.choices.append((current_llm_model, f"{current_llm_model} (legacy)"))
|
||||||
else:
|
else:
|
||||||
self.llm_model.choices = agent_config.get('full_model_name', 'mistral.mistral-medium-latest')
|
# Gebruik full_model_name als fallback
|
||||||
|
self.llm_model.choices = [(full_model_name, full_model_name)]
|
||||||
|
|
||||||
|
# Als er GEEN waarde in de database staat, toon dan de default uit de config
|
||||||
|
if not current_llm_model:
|
||||||
|
self.llm_model.data = full_model_name
|
||||||
|
else:
|
||||||
|
self.llm_model.choices = [('mistral.mistral-medium-latest', 'mistral.mistral-medium-latest')]
|
||||||
|
|
||||||
|
def populate_obj(self, obj):
|
||||||
|
"""Override populate_obj om de None waarde te behouden indien nodig"""
|
||||||
|
original_llm_model = obj.llm_model
|
||||||
|
|
||||||
|
# Roep de parent populate_obj aan
|
||||||
|
super().populate_obj(obj)
|
||||||
|
|
||||||
|
# Als de originele waarde None was EN de nieuwe waarde gelijk is aan de config default,
|
||||||
|
# herstel dan de None waarde
|
||||||
|
if original_llm_model is None and self._agent_config:
|
||||||
|
full_model_name = self._agent_config.get('full_model_name', 'mistral.mistral-medium-latest')
|
||||||
|
if obj.llm_model == full_model_name:
|
||||||
|
obj.llm_model = None
|
||||||
|
|
||||||
|
|
||||||
class EditEveAITaskForm(BaseEditComponentForm):
|
class EditEveAITaskForm(BaseEditComponentForm):
|
||||||
|
|||||||
Reference in New Issue
Block a user