diff --git a/app_chatgpt/__manifest__.py b/app_chatgpt/__manifest__.py index a458ef6f..5afa1073 100644 --- a/app_chatgpt/__manifest__.py +++ b/app_chatgpt/__manifest__.py @@ -10,7 +10,7 @@ { 'name': 'ChatGPT4, China Ali,AiGC Center.Ai服务中心,聚合全网Ai', - 'version': '24.03.29', + 'version': '24.04.01', 'author': 'odooai.cn', 'company': 'odooai.cn', 'maintainer': 'odooai.cn', diff --git a/app_chatgpt/models/ai_robot.py b/app_chatgpt/models/ai_robot.py index 781268c2..54059edc 100644 --- a/app_chatgpt/models/ai_robot.py +++ b/app_chatgpt/models/ai_robot.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import os from openai import OpenAI from openai import AzureOpenAI import requests, json @@ -23,7 +24,8 @@ class AiRobot(models.Model): # update ai_robot set ai_model=set_ai_model ai_model = fields.Char(string="AI Model", required=True, default='auto', help='Customize input') set_ai_model = fields.Selection(string="Quick Set Model", selection=[ - ('gpt-3.5-turbo-0613', 'gpt-3.5-turbo-0613(Default and Latest)'), + ('gpt-3.5-turbo-0125', 'gpt-3.5-turbo-0125(Default and Latest)'), + ('gpt-3.5-turbo-0613', 'gpt-3.5-turbo-0613'), ('gpt-3.5-turbo-16k-0613', 'gpt-3.5-turbo-16k-0613(Big text)'), ('gpt-4', 'Chatgpt 4'), ('gpt-4-32k', 'Chatgpt 4 32k'), @@ -33,7 +35,7 @@ class AiRobot(models.Model): ('code-davinci-002', 'Chatgpt 2 Code Optimized'), ('text-davinci-002', 'Chatgpt 2 Davinci'), ('dall-e2', 'Dall-E Image'), - ], default='gpt-3.5-turbo-0613', + ], default='gpt-3.5-turbo-0125', help=""" GPT-4: Can understand Image, generate natural language or code. GPT-3.5: A set of models that improve on GPT-3 and can understand as well as generate natural language or code @@ -257,56 +259,7 @@ GPT-3 A set of models that can understand and generate natural language else: stop = ["Human:", "AI:"] # 以下处理 open ai - if self.ai_model in ['gpt-3.5-turbo', 'gpt-3.5-turbo-0301']: - # 基本与 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': + if self.ai_model == 'dall-e2': # todo: 处理 图像引擎,主要是返回参数到聊天中 # image_url = response['data'][0]['url'] # https://platform.openai.com/docs/guides/images/introduction @@ -327,14 +280,17 @@ GPT-3 A set of models that can understand and generate natural language "presence_penalty": 0.1, "stop": stop } - client = OpenAI(api_key=self.openapi_api_key) + client = OpenAI( + api_key=self.openapi_api_key, + timeout=R_TIMEOUT + ) response = client.chat.completions.create( + messages=data, model=self.ai_model, - messages=data ) - # response = requests.post(o_url, data=json.dumps(pdata), headers=headers, timeout=R_TIMEOUT) - if 'choices' in response: - return response + res = response.model_dump() + if 'choices' in res: + return res else: _logger.warning('=====================openai output data: %s' % response.json()) diff --git a/app_chatgpt/models/discuss_channel.py b/app_chatgpt/models/discuss_channel.py index 4f8aeaa6..997b57b3 100644 --- a/app_chatgpt/models/discuss_channel.py +++ b/app_chatgpt/models/discuss_channel.py @@ -312,10 +312,11 @@ class Channel(models.Model): # if msg_len * 2 >= 8000: # messages = [{"role": "user", "content": msg}] - if sync_config == 'sync': - self.get_ai_response(ai, messages, channel, user_id, message) - else: - self.with_delay().get_ai_response(ai, messages, channel, user_id, message) + self.get_ai_response(ai, messages, channel, user_id, message) + # if sync_config == 'sync': + # self.get_ai_response(ai, messages, channel, user_id, message) + # else: + # self.with_delay().get_ai_response(ai, messages, channel, user_id, message) except Exception as e: raise UserError(_(e)) diff --git a/app_chatgpt/models/res_partner.py b/app_chatgpt/models/res_partner.py index 71e738d2..a7728aa3 100644 --- a/app_chatgpt/models/res_partner.py +++ b/app_chatgpt/models/res_partner.py @@ -11,7 +11,7 @@ class ResPartner(models.Model): is_chat_private = fields.Boolean('Allow Chat Private', default=False) @api.model - def im_search(self, name, limit=20): + def im_search(self, name, limit=20, excluded_ids=None): users = self.env['res.users'].search([ ('id', '!=', self.env.user.id), ('name', 'ilike', name), diff --git a/app_chatgpt/static/description/index.html b/app_chatgpt/static/description/index.html index 12c46513..e93e9250 100644 --- a/app_chatgpt/static/description/index.html +++ b/app_chatgpt/static/description/index.html @@ -4,14 +4,14 @@