diff --git a/app_chatgpt/__manifest__.py b/app_chatgpt/__manifest__.py
index 58676d76..1156593a 100644
--- a/app_chatgpt/__manifest__.py
+++ b/app_chatgpt/__manifest__.py
@@ -41,7 +41,12 @@
12. Support Odoo 16,15,14,13,12, Enterprise and Community and odoo.sh Edition.
13. Full Open Source.
''',
- 'depends': ['base', 'base_setup', 'mail'],
+ 'depends': [
+ 'base',
+ 'base_setup',
+ 'mail',
+ 'queue_job',
+ ],
'data': [
'security/ir.model.access.csv',
'data/mail_channel_data.xml',
diff --git a/app_chatgpt/models/mail_channel.py b/app_chatgpt/models/mail_channel.py
index f9dd001f..54308e12 100644
--- a/app_chatgpt/models/mail_channel.py
+++ b/app_chatgpt/models/mail_channel.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import openai
-import requests,json
+import requests, json
import datetime
# from transformers import TextDavinciTokenizer, TextDavinciModel
from odoo import api, fields, models, _
@@ -44,6 +44,11 @@ class Channel(models.Model):
return '\n'.join(prompt[::-1])
+ def get_ai(self, ai, prompt, partner_name, channel, user_id, message):
+ res = ai.get_ai(prompt, partner_name)
+ res = res.replace('\n', '
')
+ channel.with_user(user_id).message_post(body=res, message_type='comment', subtype_xmlid='mail.mt_comment', parent_id=message.id)
+
def _notify_thread(self, message, msg_vals=False, **kwargs):
rdata = super(Channel, self)._notify_thread(message, msg_vals=msg_vals, **kwargs)
# print(f'rdata:{rdata}')
@@ -110,11 +115,12 @@ class Channel(models.Model):
# if ai_model not in ['gpt-3.5-turbo', 'gpt-3.5-turbo-0301']:
prompt = self.get_openai_context(channel.id, to_partner_id.id, prompt, openapi_context_timeout)
print(prompt)
- res = ai.get_ai(prompt, partner_name)
- res = res.replace('\n', '
')
+ self.with_delay().get_ai(ai, prompt, partner_name, channel, user_id, message)
+ # res = ai.get_ai(prompt, partner_name)
+ # res = res.replace('\n', '
')
# print('res:',res)
# print('channel:',channel)
- channel.with_user(user_id).message_post(body=res, message_type='comment',subtype_xmlid='mail.mt_comment', parent_id=message.id)
+ # channel.with_user(user_id).message_post(body=res, message_type='comment',subtype_xmlid='mail.mt_comment', parent_id=message.id)
# channel.with_user(user_chatgpt).message_post(body=res, message_type='notification', subtype_xmlid='mail.mt_comment')
# channel.sudo().message_post(
# body=res,
@@ -129,10 +135,12 @@ class Channel(models.Model):
_logger.info(f'频道群聊:author_id:{author_id},partner_chatgpt.id:{to_partner_id.id}')
try:
prompt = self.get_openai_context(chatgpt_channel_id.id, to_partner_id.id, prompt, openapi_context_timeout)
- res = ai.get_ai(prompt, 'odoo')
- res = res.replace('\n', '
')
- chatgpt_channel_id.with_user(user_id).message_post(body=res, message_type='comment', subtype_xmlid='mail.mt_comment', parent_id=message.id)
+ self.with_delay().get_ai(ai, prompt, 'odoo', chatgpt_channel_id, user_id, message)
+ # res = ai.get_ai(prompt, 'odoo')
+ # res = res.replace('\n', '
')
+ # chatgpt_channel_id.with_user(user_id).message_post(body=res, message_type='comment', subtype_xmlid='mail.mt_comment', parent_id=message.id)
except Exception as e:
raise UserError(_(e))
return rdata
+