mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
用odoo queue队列处理chatgpt ai
This commit is contained in:
@@ -41,7 +41,12 @@
|
|||||||
12. Support Odoo 16,15,14,13,12, Enterprise and Community and odoo.sh Edition.
|
12. Support Odoo 16,15,14,13,12, Enterprise and Community and odoo.sh Edition.
|
||||||
13. Full Open Source.
|
13. Full Open Source.
|
||||||
''',
|
''',
|
||||||
'depends': ['base', 'base_setup', 'mail'],
|
'depends': [
|
||||||
|
'base',
|
||||||
|
'base_setup',
|
||||||
|
'mail',
|
||||||
|
'queue_job',
|
||||||
|
],
|
||||||
'data': [
|
'data': [
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'data/mail_channel_data.xml',
|
'data/mail_channel_data.xml',
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import openai
|
import openai
|
||||||
import requests,json
|
import requests, json
|
||||||
import datetime
|
import datetime
|
||||||
# from transformers import TextDavinciTokenizer, TextDavinciModel
|
# from transformers import TextDavinciTokenizer, TextDavinciModel
|
||||||
from odoo import api, fields, models, _
|
from odoo import api, fields, models, _
|
||||||
@@ -44,6 +44,11 @@ class Channel(models.Model):
|
|||||||
|
|
||||||
return '\n'.join(prompt[::-1])
|
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', '<br/>')
|
||||||
|
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):
|
def _notify_thread(self, message, msg_vals=False, **kwargs):
|
||||||
rdata = super(Channel, self)._notify_thread(message, msg_vals=msg_vals, **kwargs)
|
rdata = super(Channel, self)._notify_thread(message, msg_vals=msg_vals, **kwargs)
|
||||||
# print(f'rdata:{rdata}')
|
# 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']:
|
# 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)
|
prompt = self.get_openai_context(channel.id, to_partner_id.id, prompt, openapi_context_timeout)
|
||||||
print(prompt)
|
print(prompt)
|
||||||
res = ai.get_ai(prompt, partner_name)
|
self.with_delay().get_ai(ai, prompt, partner_name, channel, user_id, message)
|
||||||
res = res.replace('\n', '<br/>')
|
# res = ai.get_ai(prompt, partner_name)
|
||||||
|
# res = res.replace('\n', '<br/>')
|
||||||
# print('res:',res)
|
# print('res:',res)
|
||||||
# print('channel:',channel)
|
# 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.with_user(user_chatgpt).message_post(body=res, message_type='notification', subtype_xmlid='mail.mt_comment')
|
||||||
# channel.sudo().message_post(
|
# channel.sudo().message_post(
|
||||||
# body=res,
|
# body=res,
|
||||||
@@ -129,10 +135,12 @@ class Channel(models.Model):
|
|||||||
_logger.info(f'频道群聊:author_id:{author_id},partner_chatgpt.id:{to_partner_id.id}')
|
_logger.info(f'频道群聊:author_id:{author_id},partner_chatgpt.id:{to_partner_id.id}')
|
||||||
try:
|
try:
|
||||||
prompt = self.get_openai_context(chatgpt_channel_id.id, to_partner_id.id, prompt, openapi_context_timeout)
|
prompt = self.get_openai_context(chatgpt_channel_id.id, to_partner_id.id, prompt, openapi_context_timeout)
|
||||||
res = ai.get_ai(prompt, 'odoo')
|
self.with_delay().get_ai(ai, prompt, 'odoo', chatgpt_channel_id, user_id, message)
|
||||||
res = res.replace('\n', '<br/>')
|
# res = ai.get_ai(prompt, 'odoo')
|
||||||
chatgpt_channel_id.with_user(user_id).message_post(body=res, message_type='comment', subtype_xmlid='mail.mt_comment', parent_id=message.id)
|
# res = res.replace('\n', '<br/>')
|
||||||
|
# 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:
|
except Exception as e:
|
||||||
raise UserError(_(e))
|
raise UserError(_(e))
|
||||||
|
|
||||||
return rdata
|
return rdata
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user