next try 2
This commit is contained in:
parent
d295f38355
commit
e48e6d9aef
8 changed files with 75 additions and 36 deletions
|
|
@ -9,6 +9,19 @@ class AIModel(models.Model):
|
||||||
_order = 'sequence, name'
|
_order = 'sequence, name'
|
||||||
_check_company = False # Disable automatic company checks
|
_check_company = False # Disable automatic company checks
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _has_provider_modules(self):
|
||||||
|
"""Check if any AI provider modules are installed."""
|
||||||
|
modules = ['ollama_ai_integration', 'chatgpt_ai_integration']
|
||||||
|
return any(self.env['ir.module.module'].search([('name', 'in', modules), ('state', '=', 'installed')]))
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def default_get(self, fields_list):
|
||||||
|
"""Override default_get to prevent creation if no provider modules are installed."""
|
||||||
|
if not self._has_provider_modules():
|
||||||
|
raise UserError(_('No AI provider modules are installed. Please install at least one provider module (e.g., Ollama or ChatGPT) before creating an AI model.'))
|
||||||
|
return super().default_get(fields_list)
|
||||||
|
|
||||||
active = fields.Boolean(
|
active = fields.Boolean(
|
||||||
string='Active',
|
string='Active',
|
||||||
default=True,
|
default=True,
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,19 @@ class AIModelStats(models.Model):
|
||||||
_description = 'AI Model Usage Statistics'
|
_description = 'AI Model Usage Statistics'
|
||||||
_order = 'date desc'
|
_order = 'date desc'
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _has_provider_modules(self):
|
||||||
|
"""Check if any AI provider modules are installed."""
|
||||||
|
modules = ['ollama_ai_integration', 'chatgpt_ai_integration']
|
||||||
|
return any(self.env['ir.module.module'].search([('name', 'in', modules), ('state', '=', 'installed')]))
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def default_get(self, fields_list):
|
||||||
|
"""Override default_get to prevent creation if no provider modules are installed."""
|
||||||
|
if not self._has_provider_modules():
|
||||||
|
raise UserError(_('No AI provider modules are installed. Please install at least one provider module (e.g., Ollama or ChatGPT) before creating model statistics.'))
|
||||||
|
return super().default_get(fields_list)
|
||||||
|
|
||||||
model_id = fields.Many2one('ai.model', string='Model', required=True, ondelete='cascade')
|
model_id = fields.Many2one('ai.model', string='Model', required=True, ondelete='cascade')
|
||||||
provider_instance_id = fields.Many2one(
|
provider_instance_id = fields.Many2one(
|
||||||
related='model_id.provider_instance_id',
|
related='model_id.provider_instance_id',
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,19 @@ class AIProviderInstance(models.Model):
|
||||||
_check_company = False # Disable automatic company checks
|
_check_company = False # Disable automatic company checks
|
||||||
_inherit = ['mail.thread', 'ai.base.mixin']
|
_inherit = ['mail.thread', 'ai.base.mixin']
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _has_provider_modules(self):
|
||||||
|
"""Check if any AI provider modules are installed."""
|
||||||
|
modules = ['ollama_ai_integration', 'chatgpt_ai_integration']
|
||||||
|
return any(self.env['ir.module.module'].search([('name', 'in', modules), ('state', '=', 'installed')]))
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def default_get(self, fields_list):
|
||||||
|
"""Override default_get to prevent creation if no provider modules are installed."""
|
||||||
|
if not self._has_provider_modules():
|
||||||
|
raise UserError(_('No AI provider modules are installed. Please install at least one provider module (e.g., Ollama or ChatGPT) before creating a provider instance.'))
|
||||||
|
return super().default_get(fields_list)
|
||||||
|
|
||||||
active = fields.Boolean(
|
active = fields.Boolean(
|
||||||
string='Active',
|
string='Active',
|
||||||
default=True,
|
default=True,
|
||||||
|
|
|
||||||
|
|
@ -114,10 +114,5 @@
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<!-- Menu Item -->
|
|
||||||
<menuitem id="menu_ai_model_stats"
|
|
||||||
name="Model Statistics"
|
|
||||||
parent="menu_ai_integration"
|
|
||||||
action="action_ai_model_stats"
|
|
||||||
sequence="30"/>
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
||||||
|
|
@ -92,19 +92,5 @@
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<!-- Menu Items -->
|
|
||||||
<menuitem id="ai_integration_menu_root"
|
|
||||||
name="AI Integration"
|
|
||||||
sequence="50"/>
|
|
||||||
|
|
||||||
<menuitem id="ai_integration_menu_config"
|
|
||||||
name="Configuration"
|
|
||||||
parent="ai_integration_menu_root"
|
|
||||||
sequence="100"/>
|
|
||||||
|
|
||||||
<menuitem id="ai_model_menu"
|
|
||||||
name="AI Models"
|
|
||||||
parent="ai_integration_menu_config"
|
|
||||||
action="ai_model_action"
|
|
||||||
sequence="10"/>
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
||||||
|
|
@ -103,10 +103,5 @@
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<!-- Menu Item -->
|
|
||||||
<menuitem id="ai_provider_instance_menu"
|
|
||||||
name="Provider Instances"
|
|
||||||
parent="ai_integration_menu_config"
|
|
||||||
action="ai_provider_instance_action"
|
|
||||||
sequence="5"/>
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,43 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<!-- Top level menu -->
|
<!-- Top level menu -->
|
||||||
<menuitem id="menu_ai_integration"
|
<menuitem id="menu_ai_root"
|
||||||
name="AI Integration"
|
name="AI Integration"
|
||||||
web_icon="ai_integration,static/description/icon.png"
|
web_icon="ai_integration,static/description/icon.png"
|
||||||
sequence="50"/>
|
sequence="50"/>
|
||||||
|
|
||||||
<!-- Configuration menu -->
|
<!-- Configuration menu -->
|
||||||
<menuitem id="ai_integration_menu_config"
|
<menuitem id="menu_ai_config"
|
||||||
name="Configuration"
|
name="Configuration"
|
||||||
parent="menu_ai_integration"
|
parent="menu_ai_root"
|
||||||
sequence="100"/>
|
sequence="10"/>
|
||||||
|
|
||||||
|
<!-- Settings menu -->
|
||||||
|
<menuitem id="menu_ai_settings"
|
||||||
|
name="Settings"
|
||||||
|
parent="menu_ai_config"
|
||||||
|
action="action_ai_integration_configuration"
|
||||||
|
sequence="10"
|
||||||
|
groups="base.group_system"/>
|
||||||
|
|
||||||
|
<!-- Provider Instances menu -->
|
||||||
|
<menuitem id="menu_ai_providers"
|
||||||
|
name="Provider Instances"
|
||||||
|
parent="menu_ai_config"
|
||||||
|
action="ai_provider_instance_action"
|
||||||
|
sequence="20"/>
|
||||||
|
|
||||||
|
<!-- AI Models menu -->
|
||||||
|
<menuitem id="menu_ai_models"
|
||||||
|
name="AI Models"
|
||||||
|
parent="menu_ai_config"
|
||||||
|
action="ai_model_action"
|
||||||
|
sequence="30"/>
|
||||||
|
|
||||||
|
<!-- Statistics menu -->
|
||||||
|
<menuitem id="menu_ai_stats"
|
||||||
|
name="Model Statistics"
|
||||||
|
parent="menu_ai_config"
|
||||||
|
action="action_ai_model_stats"
|
||||||
|
sequence="40"/>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,5 @@
|
||||||
<field name="context">{'module': 'ai_integration'}</field>
|
<field name="context">{'module': 'ai_integration'}</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<menuitem id="menu_ai_integration_configuration"
|
|
||||||
name="Settings"
|
|
||||||
parent="ai_integration_menu_config"
|
|
||||||
action="action_ai_integration_configuration"
|
|
||||||
sequence="0"
|
|
||||||
groups="base.group_system"/>
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue