mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-24 02:20:38 +08:00
refactor: flatten openai configuration options
This commit is contained in:
@@ -81,11 +81,13 @@ class Notification(BaseModel):
|
||||
return expandvars(self.chat_id_)
|
||||
|
||||
|
||||
class Experimental(BaseModel):
|
||||
openai_enable: bool = Field(False, description="Enable experimental OpenAI")
|
||||
openai_api_key: str = Field("", description="OpenAI api key")
|
||||
openai_api_base: str = Field("https://api.openai.com/v1", description="OpenAI api base url")
|
||||
openai_model: str = Field("gpt-3.5-turbo", description="OpenAI model")
|
||||
class ExperimentalOpenAI(BaseModel):
|
||||
enable: bool = Field(False, description="Enable experimental OpenAI")
|
||||
api_key: str = Field("", description="OpenAI api key")
|
||||
api_base: str = Field(
|
||||
"https://api.openai.com/v1", description="OpenAI api base url"
|
||||
)
|
||||
model: str = Field("gpt-3.5-turbo", description="OpenAI model")
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
@@ -96,7 +98,7 @@ class Config(BaseModel):
|
||||
log: Log = Log()
|
||||
proxy: Proxy = Proxy()
|
||||
notification: Notification = Notification()
|
||||
experimental: Experimental = Experimental()
|
||||
experimental_openai: ExperimentalOpenAI = ExperimentalOpenAI()
|
||||
|
||||
def dict(self, *args, by_alias=True, **kwargs):
|
||||
return super().dict(*args, by_alias=by_alias, **kwargs)
|
||||
|
||||
@@ -55,12 +55,9 @@ class TitleParser:
|
||||
language = settings.rss_parser.language
|
||||
try:
|
||||
# use OpenAI ChatGPT to parse raw title and get structured data
|
||||
if settings.experimental.openai_enable:
|
||||
gpt = OpenAIParser(
|
||||
api_key=settings.experimental.openai_api_key,
|
||||
api_base=settings.experimental.openai_api_base,
|
||||
model=settings.experimental.openai_model,
|
||||
)
|
||||
if settings.experimental_openai.enable:
|
||||
kwargs = settings.experimental_openai.dict(exclude={"enable"})
|
||||
gpt = OpenAIParser(**kwargs)
|
||||
episode_dict = gpt.parse(raw, asdict=True)
|
||||
episode = Episode(**episode_dict)
|
||||
else:
|
||||
|
||||
@@ -22,4 +22,9 @@ class TestOpenAIParser:
|
||||
"resolution": "1080P",
|
||||
"episode": 747,
|
||||
"season": 1,
|
||||
"title_zh": "哆啦A梦新番",
|
||||
"sub": "GB_JP",
|
||||
"title_jp": "",
|
||||
"season_raw": "2023.02.25",
|
||||
"source": "AVC",
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class TestTitleParser:
|
||||
assert result.subtitle == "GB_JP"
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not settings.experimental.openai_enable,
|
||||
not settings.experimental_openai.enable,
|
||||
reason="OpenAI is not enabled in settings",
|
||||
)
|
||||
def test_parse_with_openai(self):
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
<script lang="ts" setup>
|
||||
import { Caution } from '@icon-park/vue-next';
|
||||
import type { SettingItem } from '#/components';
|
||||
import type { Experimental } from '#/config';
|
||||
import type { ExperimentalOpenAI } from '#/config';
|
||||
|
||||
const { t } = useMyI18n();
|
||||
const { getSettingGroup } = useConfigStore();
|
||||
|
||||
const experimentalFeatures = getSettingGroup('experimental');
|
||||
const experimentalFeatures = getSettingGroup('experimental_openai');
|
||||
|
||||
const items: SettingItem<Experimental>[] = [
|
||||
const items: SettingItem<ExperimentalOpenAI>[] = [
|
||||
{
|
||||
configKey: 'openai_enable',
|
||||
label: () => t('config.experimental_set.openai_enable'),
|
||||
configKey: 'enable',
|
||||
label: () => t('config.experimental_openai_set.enable'),
|
||||
type: 'switch',
|
||||
},
|
||||
{
|
||||
configKey: 'openai_api_key',
|
||||
label: () => t('config.experimental_set.openai_api_key'),
|
||||
configKey: 'api_key',
|
||||
label: () => t('config.experimental_openai_set.api_key'),
|
||||
type: 'input',
|
||||
prop: {
|
||||
type: 'password',
|
||||
@@ -24,8 +24,8 @@ const items: SettingItem<Experimental>[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
configKey: 'openai_api_base',
|
||||
label: () => t('config.experimental_set.openai_api_base'),
|
||||
configKey: 'api_base',
|
||||
label: () => t('config.experimental_openai_set.api_base'),
|
||||
type: 'input',
|
||||
prop: {
|
||||
type: 'url',
|
||||
@@ -33,18 +33,18 @@ const items: SettingItem<Experimental>[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
configKey: 'openai_model',
|
||||
label: () => t('config.experimental_set.openai_model'),
|
||||
configKey: 'model',
|
||||
label: () => t('config.experimental_openai_set.model'),
|
||||
type: 'select',
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ab-fold-panel :title="$t('config.experimental_set.title')">
|
||||
<ab-fold-panel :title="$t('config.experimental_openai_set.title')">
|
||||
<div fx-cer gap-2 mb-4 p-2 bg-amber-300 rounded-4px>
|
||||
<Caution />
|
||||
<span>{{ $t('config.experimental_set.warning') }}</span>
|
||||
<span>{{ $t('config.experimental_openai_set.warning') }}</span>
|
||||
</div>
|
||||
<div space-y-12px>
|
||||
<ab-setting
|
||||
|
||||
@@ -137,13 +137,13 @@
|
||||
"username": "Username",
|
||||
"password": "Password"
|
||||
},
|
||||
"experimental_set": {
|
||||
"experimental_openai_set": {
|
||||
"title": "Experimental Setting",
|
||||
"warning": "Warning: Experimental feature is not yet stable. Please use with caution.",
|
||||
"openai_enable": "Enable OpenAI",
|
||||
"openai_api_key": "OpenAI API Key",
|
||||
"openai_api_base": "OpenAI API Base URL",
|
||||
"openai_model": "OpenAI Model"
|
||||
"enable": "Enable OpenAI",
|
||||
"api_key": "OpenAI API Key",
|
||||
"api_base": "OpenAI API Base URL",
|
||||
"model": "OpenAI Model"
|
||||
},
|
||||
"media_player_set": {
|
||||
"title": "Media Player Setting",
|
||||
|
||||
@@ -137,13 +137,13 @@
|
||||
"username": "用户名",
|
||||
"password": "密码"
|
||||
},
|
||||
"experimental_set": {
|
||||
"experimental_openai_set": {
|
||||
"title": "实验功能设置",
|
||||
"warning": "警告:实验功能尚未稳定,请谨慎使用",
|
||||
"openai_enable": "启用 OpenAI",
|
||||
"openai_api_key": "OpenAI API Key",
|
||||
"openai_api_base": "OpenAI API Base URL",
|
||||
"openai_model": "OpenAI 模型"
|
||||
"enable": "启用 OpenAI",
|
||||
"api_key": "OpenAI API Key",
|
||||
"api_base": "OpenAI API Base URL",
|
||||
"model": "OpenAI 模型"
|
||||
},
|
||||
"media_player_set": {
|
||||
"title": "播放器设置",
|
||||
|
||||
@@ -47,11 +47,11 @@ export interface Config {
|
||||
token: string;
|
||||
chat_id: string;
|
||||
};
|
||||
experimental: {
|
||||
openai_enable: boolean;
|
||||
openai_api_key: string;
|
||||
openai_api_base: string;
|
||||
openai_model: string;
|
||||
experimental_openai: {
|
||||
enable: boolean;
|
||||
api_key: string;
|
||||
api_base: string;
|
||||
model: string;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -102,11 +102,11 @@ export const initConfig: Config = {
|
||||
token: '',
|
||||
chat_id: '',
|
||||
},
|
||||
experimental: {
|
||||
openai_enable: false,
|
||||
openai_api_key: '',
|
||||
openai_api_base: 'https://api.openai.com/v1/',
|
||||
openai_model: 'gpt-3.5-turbo',
|
||||
experimental_openai: {
|
||||
enable: false,
|
||||
api_key: '',
|
||||
api_base: 'https://api.openai.com/v1/',
|
||||
model: 'gpt-3.5-turbo',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -119,7 +119,7 @@ export type BangumiManage = getItem<'bangumi_manage'>;
|
||||
export type Log = getItem<'log'>;
|
||||
export type Proxy = getItem<'proxy'>;
|
||||
export type Notification = getItem<'notification'>;
|
||||
export type Experimental = getItem<'experimental'>;
|
||||
export type ExperimentalOpenAI = getItem<'experimental_openai'>;
|
||||
|
||||
/** 下载方式 */
|
||||
export type DownloaderType = UnionToTuple<Downloader['type']>;
|
||||
|
||||
Reference in New Issue
Block a user