mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
[18] app_chatgpt
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
import openai
|
import openai
|
||||||
import requests, json
|
import requests, json
|
||||||
import datetime
|
import datetime
|
||||||
|
from markupsafe import Markup
|
||||||
# from transformers import TextDavinciTokenizer, TextDavinciModel
|
# from transformers import TextDavinciTokenizer, TextDavinciModel
|
||||||
from odoo import api, fields, models, tools, _
|
from odoo import api, fields, models, tools, _
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
@@ -126,7 +127,7 @@ class Channel(models.Model):
|
|||||||
'content': ai_content,
|
'content': ai_content,
|
||||||
})
|
})
|
||||||
if not user_msg.author_id.gpt_id:
|
if not user_msg.author_id.gpt_id:
|
||||||
user_content = user_msg.description.replace("<p>", "").replace("</p>", "").replace('@%s' % answer_id.name, '').lstrip()
|
user_content = user_msg.body.replace("<p>", "").replace("</p>", "").replace('@%s' % answer_id.name, '').lstrip()
|
||||||
context_history.insert(0, {
|
context_history.insert(0, {
|
||||||
'role': 'user',
|
'role': 'user',
|
||||||
'content': user_content,
|
'content': user_content,
|
||||||
@@ -147,6 +148,7 @@ class Channel(models.Model):
|
|||||||
if get_ua_type() != 'wxweb':
|
if get_ua_type() != 'wxweb':
|
||||||
# 处理当微信语音返回时,是直接回文本信息,不需要转换回车
|
# 处理当微信语音返回时,是直接回文本信息,不需要转换回车
|
||||||
res = res.replace('\n', '<br/>')
|
res = res.replace('\n', '<br/>')
|
||||||
|
res = Markup(res)
|
||||||
new_msg = channel.with_user(user_id).message_post(body=res, message_type='comment', subtype_xmlid='mail.mt_comment', parent_id=message.id)
|
new_msg = channel.with_user(user_id).message_post(body=res, message_type='comment', subtype_xmlid='mail.mt_comment', parent_id=message.id)
|
||||||
if usage:
|
if usage:
|
||||||
if ai.provider == 'ali':
|
if ai.provider == 'ali':
|
||||||
@@ -318,7 +320,7 @@ class Channel(models.Model):
|
|||||||
# else:
|
# else:
|
||||||
# self.with_delay().get_ai_response(ai, messages, channel, user_id, message)
|
# self.with_delay().get_ai_response(ai, messages, channel, user_id, message)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise UserError(_(e))
|
raise UserError(e)
|
||||||
|
|
||||||
return rdata
|
return rdata
|
||||||
|
|
||||||
|
|||||||
@@ -31,19 +31,12 @@
|
|||||||
<field name="image_avatar"/>
|
<field name="image_avatar"/>
|
||||||
<field name="active"/>
|
<field name="active"/>
|
||||||
<templates>
|
<templates>
|
||||||
<t t-name="card">
|
<t t-name="card" class="flex-row">
|
||||||
<div class="oe_kanban_card oe_kanban_global_click">
|
<aside class="col-2 my-auto">
|
||||||
<div class="o_kanban_image me-1">
|
<field name="image_avatar" widget="image" options="{'size': [50, 50]}" alt="Channel"/>
|
||||||
<img t-att-src="kanban_image('ai.robot', 'image_avatar', record.id.raw_value)" alt="Robot Provider" class="o_image_64_contain"/>
|
</aside>
|
||||||
</div>
|
<main class="col me-4 ms-2">
|
||||||
<div class="oe_kanban_details">
|
<span class="fw-bold fs-5"><field name="name"/></span>
|
||||||
<div class="o_kanban_record_top mb-0">
|
|
||||||
<div class="o_kanban_record_headings">
|
|
||||||
<strong class="o_kanban_record_title">
|
|
||||||
<field name="name"/>
|
|
||||||
</strong>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
Model:
|
Model:
|
||||||
<field name="ai_model"/>
|
<field name="ai_model"/>
|
||||||
@@ -54,8 +47,7 @@
|
|||||||
</strong>
|
</strong>
|
||||||
Bind Partner
|
Bind Partner
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</main>
|
||||||
</div>
|
|
||||||
</t>
|
</t>
|
||||||
</templates>
|
</templates>
|
||||||
</kanban>
|
</kanban>
|
||||||
|
|||||||
Reference in New Issue
Block a user