#I9JAI9 [app_ai_seo]让15版本正常

This commit is contained in:
Chill
2024-06-19 17:32:29 +08:00
parent 9f556055c2
commit 0452876365
6 changed files with 38 additions and 79 deletions

View File

@@ -10,7 +10,7 @@
{ {
'name': 'ChatGPT4, China Ali,AiGC Center.Ai服务中心聚合全网Ai', 'name': 'ChatGPT4, China Ali,AiGC Center.Ai服务中心聚合全网Ai',
'version': '15.24.04.26', 'version': '15.24.06.19',
'author': 'odooai.cn', 'author': 'odooai.cn',
'company': 'odooai.cn', 'company': 'odooai.cn',
'maintainer': 'odooai.cn', 'maintainer': 'odooai.cn',

View File

@@ -319,56 +319,7 @@ GPT-3 A set of models that can understand and generate natural language
else: else:
stop = ["Human:", "AI:"] stop = ["Human:", "AI:"]
# 以下处理 open ai # 以下处理 open ai
if self.ai_model in ['gpt-3.5-turbo', 'gpt-3.5-turbo-0301']: if self.ai_model == 'dall-e2':
# 基本与 azure 同,要处理 api_base
openai.api_key = self.openapi_api_key
openai.api_base = o_url.replace('/chat/completions', '')
if isinstance(data, list):
messages = data
else:
messages = [{"role": "user", "content": data}]
# Ai角色设定如果没设定则再处理
if messages[0].get('role') != 'system':
sys_content = self.get_ai_system(param.get('sys_content'))
if sys_content:
messages.insert(0, sys_content)
# todo: 当前反向代理方式不通,要调整为 远程主机中接受请求post到openai再将结果返回给请求者
# response = openai.ChatCompletion.create(
# model=self.ai_model,
# messages=messages,
# # 返回的回答数量
# n=1,
# max_tokens=max_tokens,
# temperature=temperature,
# top_p=top_p,
# frequency_penalty=frequency_penalty,
# presence_penalty=presence_penalty,
# stop=stop,
# request_timeout=request_timeout,
# )
# if 'choices' in response:
# return response
# todo: 两种方式一样,要调整 v 服务器的二次处理 /root/toai.py
pdata = {
"model": self.ai_model,
"messages": messages,
"max_tokens": max_tokens,
"temperature": temperature,
"top_p": top_p,
"frequency_penalty": frequency_penalty,
"presence_penalty": presence_penalty,
"stop": stop
}
response = requests.post(o_url, data=json.dumps(pdata), headers=headers, timeout=R_TIMEOUT)
try:
res = response.json()
if 'choices' in res:
return res
except Exception as e:
_logger.warning("Get Response Json failed: %s", e)
else:
_logger.warning('=====================Openai output data: %s' % response.json())
elif self.ai_model == 'dall-e2':
# todo: 处理 图像引擎,主要是返回参数到聊天中 # todo: 处理 图像引擎,主要是返回参数到聊天中
# image_url = response['data'][0]['url'] # image_url = response['data'][0]['url']
# https://platform.openai.com/docs/guides/images/introduction # https://platform.openai.com/docs/guides/images/introduction
@@ -389,25 +340,31 @@ GPT-3 A set of models that can understand and generate natural language
"presence_penalty": 0.1, "presence_penalty": 0.1,
"stop": stop "stop": stop
} }
response = requests.post(o_url, data=json.dumps(pdata), headers=headers, timeout=R_TIMEOUT) client = OpenAI(
res = response.json() api_key=self.openapi_api_key,
timeout=R_TIMEOUT
)
response = client.chat.completions.create(
messages=data,
model=self.ai_model,
)
res = response.model_dump()
if 'choices' in res: if 'choices' in res:
res = '\n'.join([x['text'] for x in res['choices']])
return res return res
else:
_logger.warning('=====================openai output data: %s' % response.json())
return _("Response Timeout, please speak again.") return _("Response Timeout, please speak again.")
def get_azure(self, data, author_id, answer_id, param={}): def get_azure(self, data, author_id, answer_id, param={}):
self.ensure_one() self.ensure_one()
# only for azure # only for azure
openai.api_type = self.provider
if not self.endpoint: if not self.endpoint:
raise UserError(_("Please Set your AI robot's endpoint first.")) raise UserError(_("Please Set your AI robot's endpoint first."))
openai.api_base = self.endpoint
if not self.api_version: if not self.api_version:
raise UserError(_("Please Set your AI robot's API Version first.")) raise UserError(_("Please Set your AI robot's API Version first."))
openai.api_version = self.api_version
openai.api_key = self.openapi_api_key
if self.stop: if self.stop:
stop = self.stop.split(',') stop = self.stop.split(',')
else: else:
@@ -431,8 +388,15 @@ GPT-3 A set of models that can understand and generate natural language
if sys_content: if sys_content:
messages.insert(0, sys_content) messages.insert(0, sys_content)
# 暂时不变 # 暂时不变
response = openai.ChatCompletion.create(
engine=self.engine, client = AzureOpenAI(
api_version=self.api_version,
azure_endpoint=self.endpoint,
api_key=self.openapi_api_key,
timeout=request_timeout
)
response = client.chat.completions.create(
model=self.engine,
messages=messages, messages=messages,
# 返回的回答数量 # 返回的回答数量
n=1, n=1,
@@ -442,10 +406,10 @@ GPT-3 A set of models that can understand and generate natural language
frequency_penalty=frequency_penalty, frequency_penalty=frequency_penalty,
presence_penalty=presence_penalty, presence_penalty=presence_penalty,
stop=None, stop=None,
request_timeout=request_timeout,
) )
if 'choices' in response: res = response.model_dump()
return response if 'choices' in res:
return res
else: else:
_logger.warning('=====================azure output data: %s' % response.json()) _logger.warning('=====================azure output data: %s' % response.json())
return _("Response Timeout, please speak again.") return _("Response Timeout, please speak again.")

View File

@@ -17,6 +17,7 @@
<field name="gpt_policy"/> <field name="gpt_policy"/>
<field name="gpt_wl_partners" widget="many2many_tags" attrs="{'invisible': [('gpt_policy', '=', 'all')]}"/> <field name="gpt_wl_partners" widget="many2many_tags" attrs="{'invisible': [('gpt_policy', '=', 'all')]}"/>
<field name="gpt_demo_time"/> <field name="gpt_demo_time"/>
<field name="is_chat_private"/>
</group> </group>
</group> </group>
</page> </page>

View File

@@ -39,7 +39,7 @@
{ {
'name': "Website Product Editor in Backend", 'name': "Website Product Editor in Backend",
'version': '15.23.08.03', 'version': '15.24.06.19',
'author': 'odooai.cn', 'author': 'odooai.cn',
'category': 'Base', 'category': 'Base',
'website': 'https://www.odooai.cn', 'website': 'https://www.odooai.cn',

View File

@@ -18,7 +18,7 @@ class ProductTemplate(models.Model):
def action_product_code_view(self): def action_product_code_view(self):
self.ensure_one() self.ensure_one()
action = self.env.ref('website_sale.action_product_pages_list').read()[0] action = self.env.ref('website_sale.product_template_action_website').read()[0]
action['views'] = [(self.env.ref('app_website_sale_editor.app_product_template_form_view_code').id, 'form')] action['views'] = [(self.env.ref('app_website_sale_editor.app_product_template_form_view_code').id, 'form')]
action['res_id'] = self.id action['res_id'] = self.id

View File

@@ -4,28 +4,22 @@
<record id="app_product_template_tree_view" model="ir.ui.view"> <record id="app_product_template_tree_view" model="ir.ui.view">
<field name="name">app.product.template.tree</field> <field name="name">app.product.template.tree</field>
<field name="model">product.template</field> <field name="model">product.template</field>
<field name="inherit_id" ref="website_sale.product_pages_tree_view"/> <field name="inherit_id" ref="website_sale.product_template_view_tree_website_sale"/>
<field name="type">tree</field> <field name="type">tree</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//field[@name='is_seo_optimized']" position="before">
<button name="action_product_debug_view" type="object" title="Content Set" icon="fa-bug fa-lg" groups="base.group_no_one"/>
<button name="action_product_code_view" type="object" title="Source Code" icon="fa-code fa-lg" groups="base.group_no_one"/>
</xpath>
<xpath expr="//field[@name='website_url']" position="attributes">
<attribute name="optional">hide</attribute>
</xpath>
<xpath expr="//field[@name='is_published']" position="attributes">
<attribute name="optional">show</attribute>
</xpath>
<xpath expr="//field[@name='is_seo_optimized']" position="attributes">
<attribute name="optional">show</attribute>
</xpath>
<xpath expr="//field[@name='is_published']" position="after"> <xpath expr="//field[@name='is_published']" position="after">
<button name="action_product_debug_view" type="object" title="Content Set" icon="fa-bug fa-lg" groups="base.group_no_one"/>
<button name="action_product_code_view" type="object" title="Source Code" icon="fa-code fa-lg" groups="base.group_no_one"/>
<field name="website_url" optional="hide"/>
<field name="is_seo_optimized" optional="show"/>
<field name="seo_name" optional="hide"/> <field name="seo_name" optional="hide"/>
<field name="website_meta_keywords" optional="hide"/> <field name="website_meta_keywords" optional="hide"/>
<field name="website_meta_title" optional="hide"/> <field name="website_meta_title" optional="hide"/>
<field name="website_meta_description" optional="hide"/> <field name="website_meta_description" optional="hide"/>
</xpath> </xpath>
<xpath expr="//field[@name='is_published']" position="attributes">
<attribute name="optional">show</attribute>
</xpath>
</field> </field>
</record> </record>