Update: 更新ChatGPT插件,兼容/v1后仍有路径的API

This commit is contained in:
daizh
2025-02-20 15:18:19 +08:00
parent f4e5de2e11
commit 7d0938a6a8
6 changed files with 55 additions and 10 deletions

View File

@@ -260,7 +260,7 @@
"name": "ChatGPT", "name": "ChatGPT",
"description": "消息交互支持与ChatGPT对话。", "description": "消息交互支持与ChatGPT对话。",
"labels": "消息通知,识别", "labels": "消息通知,识别",
"version": "1.3", "version": "1.3.1",
"icon": "Chatgpt_A.png", "icon": "Chatgpt_A.png",
"author": "jxxghp", "author": "jxxghp",
"level": 1 "level": 1

View File

@@ -91,11 +91,12 @@
"name": "ChatGPT", "name": "ChatGPT",
"description": "消息交互支持与ChatGPT对话。", "description": "消息交互支持与ChatGPT对话。",
"labels": "消息通知,识别", "labels": "消息通知,识别",
"version": "2.1.0", "version": "2.1.1",
"icon": "Chatgpt_A.png", "icon": "Chatgpt_A.png",
"author": "jxxghp", "author": "jxxghp",
"level": 1, "level": 1,
"history": { "history": {
"v2.1.1": "兼容/v1后仍有路径的接口",
"v2.1.0": "优化辅助识别提示词", "v2.1.0": "优化辅助识别提示词",
"v2.0.1": "修复辅助识别", "v2.0.1": "修复辅助识别",
"v2.0": "适配MoviePilot V2 版本,采用链式事件机制" "v2.0": "适配MoviePilot V2 版本,采用链式事件机制"

View File

@@ -16,7 +16,7 @@ class ChatGPT(_PluginBase):
# 插件图标 # 插件图标
plugin_icon = "Chatgpt_A.png" plugin_icon = "Chatgpt_A.png"
# 插件版本 # 插件版本
plugin_version = "2.1.0" plugin_version = "2.1.1"
# 插件作者 # 插件作者
plugin_author = "jxxghp" plugin_author = "jxxghp"
# 作者主页 # 作者主页
@@ -32,6 +32,7 @@ class ChatGPT(_PluginBase):
openai = None openai = None
_enabled = False _enabled = False
_proxy = False _proxy = False
_compatible = False
_recognize = False _recognize = False
_openai_url = None _openai_url = None
_openai_key = None _openai_key = None
@@ -41,6 +42,7 @@ class ChatGPT(_PluginBase):
if config: if config:
self._enabled = config.get("enabled") self._enabled = config.get("enabled")
self._proxy = config.get("proxy") self._proxy = config.get("proxy")
self._compatible = config.get("compatible")
self._recognize = config.get("recognize") self._recognize = config.get("recognize")
self._openai_url = config.get("openai_url") self._openai_url = config.get("openai_url")
self._openai_key = config.get("openai_key") self._openai_key = config.get("openai_key")
@@ -48,7 +50,7 @@ class ChatGPT(_PluginBase):
if self._openai_url and self._openai_key: if self._openai_url and self._openai_key:
self.openai = OpenAi(api_key=self._openai_key, api_url=self._openai_url, self.openai = OpenAi(api_key=self._openai_key, api_url=self._openai_url,
proxy=settings.PROXY if self._proxy else None, proxy=settings.PROXY if self._proxy else None,
model=self._model) model=self._model, compatible=bool(self._compatible)
def get_state(self) -> bool: def get_state(self) -> bool:
return self._enabled return self._enabled
@@ -103,6 +105,22 @@ class ChatGPT(_PluginBase):
} }
] ]
}, },
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 4
},
'content': [
{
'component': 'VSwitch',
'props': {
'model': 'compatible',
'label': '兼容模式',
}
}
]
},
{ {
'component': 'VCol', 'component': 'VCol',
'props': { 'props': {
@@ -203,6 +221,7 @@ class ChatGPT(_PluginBase):
], { ], {
"enabled": False, "enabled": False,
"proxy": False, "proxy": False,
"compatible": False,
"recognize": False, "recognize": False,
"openai_url": "https://api.openai.com", "openai_url": "https://api.openai.com",
"openai_key": "", "openai_key": "",

View File

@@ -13,10 +13,13 @@ class OpenAi:
_api_url: str = None _api_url: str = None
_model: str = "gpt-3.5-turbo" _model: str = "gpt-3.5-turbo"
def __init__(self, api_key: str = None, api_url: str = None, proxy: dict = None, model: str = None): def __init__(self, api_key: str = None, api_url: str = None, proxy: dict = None, model: str = None, compatible: bool = False):
self._api_key = api_key self._api_key = api_key
self._api_url = api_url self._api_url = api_url
openai.api_base = self._api_url + "/v1" if compatible:
openai.api_base = self._api_url
else:
openai.api_base = self._api_url + "/v1"
openai.api_key = self._api_key openai.api_key = self._api_key
if proxy and proxy.get("https"): if proxy and proxy.get("https"):
openai.proxy = proxy.get("https") openai.proxy = proxy.get("https")

View File

@@ -16,7 +16,7 @@ class ChatGPT(_PluginBase):
# 插件图标 # 插件图标
plugin_icon = "Chatgpt_A.png" plugin_icon = "Chatgpt_A.png"
# 插件版本 # 插件版本
plugin_version = "1.3" plugin_version = "1.3.1"
# 插件作者 # 插件作者
plugin_author = "jxxghp" plugin_author = "jxxghp"
# 作者主页 # 作者主页
@@ -32,6 +32,7 @@ class ChatGPT(_PluginBase):
openai = None openai = None
_enabled = False _enabled = False
_proxy = False _proxy = False
_compatible = False
_recognize = False _recognize = False
_openai_url = None _openai_url = None
_openai_key = None _openai_key = None
@@ -41,6 +42,7 @@ class ChatGPT(_PluginBase):
if config: if config:
self._enabled = config.get("enabled") self._enabled = config.get("enabled")
self._proxy = config.get("proxy") self._proxy = config.get("proxy")
self._compatible = config.get("compatible")
self._recognize = config.get("recognize") self._recognize = config.get("recognize")
self._openai_url = config.get("openai_url") self._openai_url = config.get("openai_url")
self._openai_key = config.get("openai_key") self._openai_key = config.get("openai_key")
@@ -48,7 +50,7 @@ class ChatGPT(_PluginBase):
if self._openai_url and self._openai_key: if self._openai_url and self._openai_key:
self.openai = OpenAi(api_key=self._openai_key, api_url=self._openai_url, self.openai = OpenAi(api_key=self._openai_key, api_url=self._openai_url,
proxy=settings.PROXY if self._proxy else None, proxy=settings.PROXY if self._proxy else None,
model=self._model) model=self._model, compatible=bool(self._compatible))
def get_state(self) -> bool: def get_state(self) -> bool:
return self._enabled return self._enabled
@@ -103,6 +105,22 @@ class ChatGPT(_PluginBase):
} }
] ]
}, },
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 4
},
'content': [
{
'component': 'VSwitch',
'props': {
'model': 'compatible',
'label': '兼容模式',
}
}
]
},
{ {
'component': 'VCol', 'component': 'VCol',
'props': { 'props': {
@@ -203,6 +221,7 @@ class ChatGPT(_PluginBase):
], { ], {
"enabled": False, "enabled": False,
"proxy": False, "proxy": False,
"compatible": False,
"recognize": False, "recognize": False,
"openai_url": "https://api.openai.com", "openai_url": "https://api.openai.com",
"openai_key": "", "openai_key": "",

View File

@@ -13,10 +13,13 @@ class OpenAi:
_api_url: str = None _api_url: str = None
_model: str = "gpt-3.5-turbo" _model: str = "gpt-3.5-turbo"
def __init__(self, api_key: str = None, api_url: str = None, proxy: dict = None, model: str = None): def __init__(self, api_key: str = None, api_url: str = None, proxy: dict = None, model: str = None, compatible: bool = False):
self._api_key = api_key self._api_key = api_key
self._api_url = api_url self._api_url = api_url
openai.api_base = self._api_url + "/v1" if compatible:
openai.api_base = self._api_url
else:
openai.api_base = self._api_url + "/v1"
openai.api_key = self._api_key openai.api_key = self._api_key
if proxy and proxy.get("https"): if proxy and proxy.get("https"):
openai.proxy = proxy.get("https") openai.proxy = proxy.get("https")