[18] app_chatgpt

This commit is contained in:
Chill
2025-01-06 17:50:59 +08:00
parent 732b29d349
commit efc9bae678
2 changed files with 19 additions and 25 deletions

View File

@@ -3,6 +3,7 @@
import openai
import requests, json
import datetime
from markupsafe import Markup
# from transformers import TextDavinciTokenizer, TextDavinciModel
from odoo import api, fields, models, tools, _
from odoo.exceptions import UserError
@@ -126,7 +127,7 @@ class Channel(models.Model):
'content': ai_content,
})
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, {
'role': 'user',
'content': user_content,
@@ -147,6 +148,7 @@ class Channel(models.Model):
if get_ua_type() != 'wxweb':
# 处理当微信语音返回时,是直接回文本信息,不需要转换回车
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)
if usage:
if ai.provider == 'ali':
@@ -318,7 +320,7 @@ class Channel(models.Model):
# else:
# self.with_delay().get_ai_response(ai, messages, channel, user_id, message)
except Exception as e:
raise UserError(_(e))
raise UserError(e)
return rdata

View File

@@ -31,31 +31,23 @@
<field name="image_avatar"/>
<field name="active"/>
<templates>
<t t-name="card">
<div class="oe_kanban_card oe_kanban_global_click">
<div class="o_kanban_image me-1">
<img t-att-src="kanban_image('ai.robot', 'image_avatar', record.id.raw_value)" alt="Robot Provider" class="o_image_64_contain"/>
<t t-name="card" class="flex-row">
<aside class="col-2 my-auto">
<field name="image_avatar" widget="image" options="{'size': [50, 50]}" alt="Channel"/>
</aside>
<main class="col me-4 ms-2">
<span class="fw-bold fs-5"><field name="name"/></span>
<div class="mt-3">
Model:
<field name="ai_model"/>
</div>
<div class="oe_kanban_details">
<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">
Model:
<field name="ai_model"/>
</div>
<div class="mt-1">
<strong>
<t t-esc="record.partner_count.value"/>
</strong>
Bind Partner
</div>
<div class="mt-1">
<strong>
<t t-esc="record.partner_count.value"/>
</strong>
Bind Partner
</div>
</div>
</main>
</t>
</templates>
</kanban>