Files
eveAI/eveai_app/views/interaction_forms.py
Josako 1fdbd2ff45 - Move global config files to globals iso global folder, as the name global conflicts with python language
- Creation of Traicie Vancancy Definition specialist
- Allow to invoke non-interaction specialists from withing Evie's mgmt interface (eveai_app)
- Improvements to crewai specialized classes
- Introduction to json editor for showing specialists arguments and results in a better way
- Introduction of more complex pagination (adding extra arguments) by adding a global 'get_pagination_html'
- Allow follow-up of ChatSession / Specialist execution
- Improvement in logging of Specialists (but needs to be finished)
2025-05-26 11:26:03 +02:00

136 lines
5.7 KiB
Python

from flask_wtf import FlaskForm
from wtforms import (StringField, BooleanField, SelectField, TextAreaField)
from wtforms.fields.datetime import DateField
from wtforms.fields.numeric import IntegerField
from wtforms.validators import DataRequired, Length, Optional
from wtforms_sqlalchemy.fields import QuerySelectMultipleField
from common.models.document import Retriever
from common.models.interaction import EveAITool
from common.extensions import cache_manager
from .dynamic_form_base import DynamicFormBase
def get_retrievers():
return Retriever.query.all()
def get_tools():
return EveAITool.query.all()
class SpecialistForm(FlaskForm):
name = StringField('Name', validators=[DataRequired(), Length(max=50)])
retrievers = QuerySelectMultipleField(
'Retrievers',
query_factory=get_retrievers,
get_label='name', # Assuming your Retriever model has a 'name' field
allow_blank=True,
description='Select one or more retrievers to associate with this specialist'
)
type = SelectField('Specialist Type', validators=[DataRequired()])
tuning = BooleanField('Enable Specialist Tuning', default=False)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
types_dict = cache_manager.specialists_types_cache.get_types()
# Dynamically populate the 'type' field using the constructor
self.type.choices = [(key, value['name']) for key, value in types_dict.items()]
class EditSpecialistForm(DynamicFormBase):
name = StringField('Name', validators=[DataRequired()])
description = TextAreaField('Description', validators=[Optional()])
retrievers = QuerySelectMultipleField(
'Retrievers',
query_factory=get_retrievers,
get_label='name',
allow_blank=True,
description='Select one or more retrievers to associate with this specialist'
)
type = StringField('Specialist Type', validators=[DataRequired()], render_kw={'readonly': True})
type_version = StringField('Type Version', validators=[DataRequired()], render_kw={'readonly': True})
tuning = BooleanField('Enable Specialist Tuning', default=False)
class BaseComponentForm(DynamicFormBase):
"""Base form for all processing components"""
name = StringField('Name', validators=[DataRequired(), Length(max=50)])
description = TextAreaField('Description', validators=[Optional()])
type = SelectField('Type', validators=[DataRequired()])
tuning = BooleanField('Enable Tuning', default=False)
def __init__(self, *args, type_config=None, **kwargs):
super().__init__(*args, **kwargs)
if type_config:
self.type.choices = [(key, value['name']) for key, value in type_config.items()]
# Edit forms that support dynamic fields
class BaseEditComponentForm(DynamicFormBase):
name = StringField('Name', validators=[DataRequired()])
description = TextAreaField('Description', validators=[Optional()])
type = StringField('Type', validators=[DataRequired()], render_kw={'readonly': True})
type_version = StringField('Type Version', validators=[DataRequired()], render_kw={'readonly': True})
tuning = BooleanField('Enable Tuning', default=False)
class EditEveAIAgentForm(BaseEditComponentForm):
role = TextAreaField('Role', validators=[Optional()])
goal = TextAreaField('Goal', validators=[Optional()])
backstory = TextAreaField('Backstory', validators=[Optional()])
class EditEveAITaskForm(BaseEditComponentForm):
task_description = StringField('Task Description', validators=[Optional()])
expected_outcome = StringField('Expected Outcome', validators=[Optional()])
class EditEveAIToolForm(BaseEditComponentForm):
pass
class AddEveAIAssetForm(FlaskForm):
name = StringField('Name', validators=[DataRequired(), Length(max=50)])
description = TextAreaField('Description', validators=[Optional()])
type = SelectField('Type', validators=[DataRequired()])
valid_from = DateField('Valid From', id='form-control datepicker', validators=[Optional()])
valid_to = DateField('Valid To', id='form-control datepicker', validators=[Optional()])
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
types_dict = cache_manager.assets_types_cache.get_types()
self.type.choices = [(key, value['name']) for key, value in types_dict.items()]
class EditEveAIAssetForm(FlaskForm):
name = StringField('Name', validators=[DataRequired(), Length(max=50)])
description = TextAreaField('Description', validators=[Optional()])
type = SelectField('Type', validators=[DataRequired()], render_kw={'readonly': True})
type_version = StringField('Type Version', validators=[DataRequired()], render_kw={'readonly': True})
valid_from = DateField('Valid From', id='form-control datepicker', validators=[Optional()])
valid_to = DateField('Valid To', id='form-control datepicker', validators=[Optional()])
class EditEveAIAssetVersionForm(DynamicFormBase):
asset_name = StringField('Asset Name', validators=[DataRequired()], render_kw={'readonly': True})
asset_type = StringField('Asset Type', validators=[DataRequired()], render_kw={'readonly': True})
asset_type_version = StringField('Asset Type Version', validators=[DataRequired()], render_kw={'readonly': True})
bucket_name = StringField('Bucket Name', validators=[DataRequired()], render_kw={'readonly': True})
class ExecuteSpecialistForm(DynamicFormBase):
id = IntegerField('Specialist ID', validators=[DataRequired()], render_kw={'readonly': True})
name = StringField('Specialist Name', validators=[DataRequired()], render_kw={'readonly': True})
description = TextAreaField('Specialist Description', validators=[Optional()], render_kw={'readonly': True})