@ -0,0 +1,49 @@ |
|||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg |
|||
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html |
|||
:alt: License: AGPL-3 |
|||
|
|||
Generate Product Description/Tags Using OpenAI |
|||
============================================== |
|||
This module helps to create product tags from description and description from tags using OpenAI. |
|||
|
|||
Configuration |
|||
============= |
|||
* Fill OpenAI API key from settings. |
|||
|
|||
Company |
|||
------- |
|||
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
|||
|
|||
License |
|||
------- |
|||
Affero General Public License v3.0 (AGPL v3) |
|||
(https://www.gnu.org/licenses/agpl-3.0-standalone.html) |
|||
|
|||
Credits |
|||
------- |
|||
* Developers : (V16) Ranjith R, |
|||
(V17) Anagha S, |
|||
(V18) Aysha Shalin, |
|||
Contact : odoo@cybrosys.com |
|||
|
|||
Contacts |
|||
-------- |
|||
* Mail Contact : odoo@cybrosys.com |
|||
* Website : https://cybrosys.com |
|||
|
|||
Bug Tracker |
|||
----------- |
|||
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. |
|||
|
|||
Maintainer |
|||
========== |
|||
.. image:: https://cybrosys.com/images/logo.png |
|||
:target: https://cybrosys.com |
|||
|
|||
This module is maintained by Cybrosys Technologies. |
|||
|
|||
For support and more information, please visit `Our Website <https://cybrosys.com/>`__ |
|||
|
|||
Further information |
|||
=================== |
|||
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,23 @@ |
|||
"""Tag creation from description and description creation from tags""" |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC |
|||
# LICENSE (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
from . import models |
@ -0,0 +1,40 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC |
|||
# LICENSE (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
{ |
|||
'name': 'Generate Product Description/Tags Using OpenAI', |
|||
'version': '18.0.1.0.0', |
|||
'category': 'Extra Tools', |
|||
'summary': 'Automatically Generate Product Tags and Description.', |
|||
'description': """Automate Product Tag and Description Generation in Odoo |
|||
using OpenAI API.""", |
|||
'author': 'Cybrosys Techno Solutions', |
|||
'company': 'Cybrosys Techno Solutions', |
|||
'maintainer': 'Cybrosys Techno Solutions', |
|||
'website': 'https://www.cybrosys.com', |
|||
'depends': ['product', 'openai_odoo_base', 'stock'], |
|||
'data': ['data/ir_actions_server_data.xml'], |
|||
'images': ['static/description/banner.png'], |
|||
'license': 'AGPL-3', |
|||
'installable': True, |
|||
'auto_install': False, |
|||
'application': False, |
|||
} |
@ -0,0 +1,52 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<!--'Generate Tags from Description Using Openai' in action dropdown of product template form--> |
|||
<record id="action_product_template_tag_description" |
|||
model="ir.actions.server"> |
|||
<field name="name">Generate Tags from Description Using Openai |
|||
</field> |
|||
<field name="model_id" ref="product.model_product_template"/> |
|||
<field name="binding_model_id" |
|||
ref="product.model_product_template"/> |
|||
<field name="binding_view_types">list,form</field> |
|||
<field name="state">code</field> |
|||
<field name="code">action = model.action_create_tag_description() </field> |
|||
</record> |
|||
<!--'Generate Tags from Internal Note Using Openai' in action dropdown of product variant form--> |
|||
<record id="action_product_template_tag_internal_note" |
|||
model="ir.actions.server"> |
|||
<field name="name">Generate Tags from Internal Note Using Openai |
|||
</field> |
|||
<field name="model_id" ref="product.model_product_product"/> |
|||
<field name="binding_model_id" ref="product.model_product_product"/> |
|||
<field name="binding_view_types">list,form</field> |
|||
<field name="state">code</field> |
|||
<field name="code"> |
|||
action = model.action_create_tag_internal_note() |
|||
</field> |
|||
</record> |
|||
<!--'Generate Internal Note from Tags Using Openai' in action dropdown of product variant form--> |
|||
<record id="action_product_template_internal_note_tag" |
|||
model="ir.actions.server"> |
|||
<field name="name">Generate Internal Note from Tags Using Openai |
|||
</field> |
|||
<field name="model_id" ref="product.model_product_product"/> |
|||
<field name="binding_model_id" ref="product.model_product_product"/> |
|||
<field name="binding_view_types">list,form</field> |
|||
<field name="state">code</field> |
|||
<field name="code"> |
|||
action = model.generate_internal_notes_from_tags() |
|||
</field> |
|||
</record> |
|||
<!--'Generate Description Using Openai' in action dropdown of product template form--> |
|||
<record id="action_product_template_description_dalle" |
|||
model="ir.actions.server"> |
|||
<field name="name">Generate Description Using Openai</field> |
|||
<field name="model_id" ref="product.model_product_template"/> |
|||
<field name="binding_model_id" |
|||
ref="product.model_product_template"/> |
|||
<field name="binding_view_types">list,form</field> |
|||
<field name="state">code</field> |
|||
<field name="code">action = model.generate_description_from_tags()</field> |
|||
</record> |
|||
</odoo> |
@ -0,0 +1,6 @@ |
|||
## Module <openai_product_tag_description> |
|||
|
|||
#### 30.11.2024 |
|||
#### Version 18.0.1.0.0 |
|||
##### ADD |
|||
- Initial commit for Generate Product Description/Tags Using OpenAI |
@ -0,0 +1,23 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC |
|||
# LICENSE (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
from . import product_product |
|||
from . import product_template |
@ -0,0 +1,113 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC |
|||
# LICENSE (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
import requests |
|||
from odoo import models, _ |
|||
from odoo.exceptions import ValidationError |
|||
|
|||
|
|||
class ProductProduct(models.Model): |
|||
""" Inherit product.product model """ |
|||
_inherit = 'product.product' |
|||
|
|||
def action_create_tag_internal_note(self): |
|||
""" Action to create tags from Internal notes """ |
|||
api_key = self.env['ir.config_parameter'].sudo().get_param( |
|||
'openai_api_key') |
|||
if not api_key: |
|||
raise ValidationError( |
|||
_("Invalid API key provided. Please ensure that you have " |
|||
"entered the correct API key. ")) |
|||
product_id = self._context['active_id'] |
|||
product = self.env['product.product'].browse(product_id) |
|||
tags_list = [] |
|||
if product.description: |
|||
prompt = "Generate tags for the following description: \n" + str( |
|||
product.description) + "\n\nTags:" |
|||
response = requests.post( |
|||
"https://api.openai.com/v1/engines/text-davinci-002/completions", |
|||
headers={ |
|||
"Content-Type": "application/json", |
|||
"Authorization": f"Bearer {api_key}" |
|||
}, |
|||
json={ |
|||
"prompt": prompt, |
|||
"max_tokens": 60, |
|||
"n": 1, |
|||
"stop": None, |
|||
"temperature": 0.5 |
|||
} |
|||
) |
|||
tags = response.json()["choices"][0]["text"].split(",") |
|||
tags = [tag.strip() for tag in tags] |
|||
tags_list.extend(tags) |
|||
tags_exists = self.env['product.tag'].search([]).mapped('name') |
|||
for tag in tags_list: |
|||
if tag not in tags_exists: |
|||
tag_created = self.env['product.tag'].create({ |
|||
'name': tag}) |
|||
product.write({ |
|||
'product_tag_ids': [(4, tag_created.id)] |
|||
}) |
|||
else: |
|||
tags_exist = self.env['product.tag'].search( |
|||
[('name', '=', tag)]) |
|||
for tag_apply in tags_exist: |
|||
product.write({'product_tag_ids': [(4, tag_apply.id)]}) |
|||
else: |
|||
raise ValidationError( |
|||
_("No description for this product.")) |
|||
|
|||
def generate_internal_notes_from_tags(self): |
|||
""" Action to create Internal notes from tags """ |
|||
prompt = "Generate a description for a product based on " \ |
|||
"the following tags: \n" |
|||
api_key = self.env['ir.config_parameter'].sudo().get_param( |
|||
'openai_api_key') |
|||
if not api_key: |
|||
raise ValidationError( |
|||
_("Invalid API key provided. Please ensure that you have " |
|||
"entered the correct API key. ")) |
|||
product_id = self._context['active_id'] |
|||
product = self.env['product.product'].browse(product_id) |
|||
if product.product_tag_ids: |
|||
for tag in product.product_tag_ids: |
|||
prompt += f"- {tag}\n" |
|||
prompt += "\nDescription:" |
|||
response = requests.post( |
|||
"https://api.openai.com/v1/engines/text-davinci-002/completions", |
|||
headers={ |
|||
"Content-Type": "application/json", |
|||
"Authorization": f"Bearer {api_key}" |
|||
}, |
|||
json={ |
|||
"prompt": prompt, |
|||
"max_tokens": 200, |
|||
"n": 1, |
|||
"stop": None, |
|||
"temperature": 0.5 |
|||
} |
|||
) |
|||
description = response.json()["choices"][0]["text"].split('\n') |
|||
product.description = description[-1] |
|||
else: |
|||
raise ValidationError( |
|||
_("No tags for this product.")) |
@ -0,0 +1,120 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC |
|||
# LICENSE (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
from openai import OpenAI |
|||
|
|||
from odoo import models, _ |
|||
from odoo.exceptions import ValidationError |
|||
|
|||
|
|||
class ProductTemplate(models.Model): |
|||
""" Inherit product.template model """ |
|||
_inherit = 'product.template' |
|||
|
|||
def action_create_tag_description(self): |
|||
""" Function to create tags from description """ |
|||
api_key = self.env['ir.config_parameter'].sudo().get_param( |
|||
'openai_api_key') |
|||
if not api_key: |
|||
raise ValidationError( |
|||
_("Invalid API key provided. Please ensure that you have " |
|||
"entered the correct API key. ")) |
|||
product_id = self._context['active_id'] |
|||
product = self.env['product.template'].browse(product_id) |
|||
if product.description: |
|||
prompt = "Generate tags for the following description: \n" + str( |
|||
product.description) + "\n\nTags:" |
|||
client = OpenAI( |
|||
api_key=api_key) |
|||
response = client.chat.completions.create( |
|||
model="gpt-3.5-turbo", |
|||
messages=[ |
|||
{ |
|||
"role": "system", |
|||
"content": "You are an AI assistant" |
|||
}, |
|||
{ |
|||
"role": "user", |
|||
"content": prompt |
|||
} |
|||
], |
|||
temperature=0.8, |
|||
top_p=1 |
|||
) |
|||
tags = response.choices[0].message.content |
|||
tags = [tag.strip() for tag in tags.split(',')] |
|||
tags_exists = self.env['product.tag'].search([]).mapped('name') |
|||
for tag in tags: |
|||
if tag not in tags_exists: |
|||
tag_created = self.env['product.tag'].create({ |
|||
'name': tag, |
|||
'product_template_ids': [(4, product_id)]}) |
|||
product.write({ |
|||
'product_tag_ids': [(4, tag_created.id)] |
|||
}) |
|||
else: |
|||
tags_exist = self.env['product.tag'].search( |
|||
[('name', '=', tag)]) |
|||
tags_exist.write( |
|||
{'product_template_ids': [(4, product_id)]}) |
|||
for tag_apply in tags_exist: |
|||
product.write({'product_tag_ids': [(4, tag_apply.id)]}) |
|||
else: |
|||
raise ValidationError( |
|||
_("No description for this product")) |
|||
|
|||
def generate_description_from_tags(self): |
|||
""" Function to create description from tags """ |
|||
prompt = "Generate a description for a product based on" \ |
|||
" the following tags: \n" |
|||
api_key = self.env['ir.config_parameter'].sudo().get_param( |
|||
'openai_api_key') |
|||
product_id = self._context['active_id'] |
|||
product = self.env['product.template'].browse(product_id) |
|||
if not api_key: |
|||
raise ValidationError(_("Invalid API key provided. Please ensure" |
|||
" that you have entered the correct API " |
|||
"key. ")) |
|||
if product.product_tag_ids: |
|||
for tag in product.product_tag_ids: |
|||
prompt += f"- {tag.name}\n" |
|||
prompt += "\nDescription:" |
|||
client = OpenAI( |
|||
api_key=api_key) |
|||
response = client.chat.completions.create( |
|||
model="gpt-3.5-turbo", |
|||
messages=[ |
|||
{ |
|||
"role": "system", |
|||
"content": "You are an AI assistant" |
|||
}, |
|||
{ |
|||
"role": "user", |
|||
"content": prompt |
|||
} |
|||
], |
|||
temperature=0.8, |
|||
top_p=1 |
|||
) |
|||
description = response.choices[0].message.content |
|||
product.description = description |
|||
else: |
|||
raise ValidationError(_("No tags for this product.")) |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 628 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 495 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 624 B |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 929 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 738 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 600 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 926 B |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 875 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 757 KiB |
After Width: | Height: | Size: 95 KiB |
After Width: | Height: | Size: 85 KiB |
After Width: | Height: | Size: 126 KiB |
After Width: | Height: | Size: 146 KiB |
After Width: | Height: | Size: 83 KiB |
After Width: | Height: | Size: 78 KiB |
After Width: | Height: | Size: 73 KiB |
After Width: | Height: | Size: 102 KiB |
After Width: | Height: | Size: 126 KiB |
After Width: | Height: | Size: 117 KiB |
After Width: | Height: | Size: 84 KiB |
After Width: | Height: | Size: 226 KiB |
After Width: | Height: | Size: 880 KiB |
After Width: | Height: | Size: 95 KiB |
After Width: | Height: | Size: 13 KiB |