mirror of
https://github.com/d0zingcat/MoviePilot-Plugins.git
synced 2026-05-13 23:16:47 +00:00
Merge pull request #763 from Seed680/main
This commit is contained in:
@@ -94,11 +94,12 @@
|
||||
"name": "ChatGPT",
|
||||
"description": "消息交互支持与ChatGPT对话。",
|
||||
"labels": "消息通知,识别",
|
||||
"version": "2.1.4",
|
||||
"version": "2.1.5",
|
||||
"icon": "Chatgpt_A.png",
|
||||
"author": "jxxghp",
|
||||
"level": 1,
|
||||
"history": {
|
||||
"v2.1.5": "兼容一些模型返回json数据信息用markdown语法包裹的情况",
|
||||
"v2.1.4": "不处理http链接",
|
||||
"v2.1.3": "修复通知异常",
|
||||
"v2.1.2": "支持传入多个api key",
|
||||
|
||||
@@ -17,7 +17,7 @@ class ChatGPT(_PluginBase):
|
||||
# 插件图标
|
||||
plugin_icon = "Chatgpt_A.png"
|
||||
# 插件版本
|
||||
plugin_version = "2.1.4"
|
||||
plugin_version = "2.1.5"
|
||||
# 插件作者
|
||||
plugin_author = "jxxghp"
|
||||
# 作者主页
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import re
|
||||
import time
|
||||
from typing import List, Union
|
||||
|
||||
@@ -127,6 +128,14 @@ class OpenAi:
|
||||
_filename_prompt = '接下来我会给你一个电影或电视剧的文件名,你需要识别文件名中的名称、版本、分段、年份、分瓣率、季集等信息,并按以下JSON格式返回:{"name":string,"version":string,"part":string,"year":string,"resolution":string,"season":number|null,"episode":number|null},特别注意返回结果需要严格附合JSON格式,不需要有任何其它的字符。如果中文电影或电视剧的文件名中存在谐音字或字母替代的情况,请还原最有可能的结果。'
|
||||
completion = self.__get_model(prompt=_filename_prompt, message=filename)
|
||||
result = completion.choices[0].message.content
|
||||
# 有些模型返回json数据时会使用 ```json ``` 包裹json对象 所以需要进行提取
|
||||
# 定义正则表达式模式,匹配```json开头和```结尾的内容
|
||||
pattern = r'^```json\s*([\s\S]*?)\s*```$'
|
||||
# 使用正则表达式进行匹配
|
||||
match = re.match(pattern, result.strip())
|
||||
if match:
|
||||
# 提取中间的JSON部分
|
||||
result = match.group(1)
|
||||
return json.loads(result)
|
||||
except Exception as e:
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user