Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseLibraryInfoモデル(+α)の追加と、LibraryManagerクラスがあるファイルのリネーム #776

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@

from voicevox_engine import __version__
from voicevox_engine.cancellable_engine import CancellableEngine
from voicevox_engine.downloadable_library import LibraryManager
from voicevox_engine.engine_manifest import EngineManifestLoader
from voicevox_engine.engine_manifest.EngineManifest import EngineManifest
from voicevox_engine.kana_parser import create_kana, parse_kana
from voicevox_engine.library_manager import LibraryManager
from voicevox_engine.metas.MetasStore import MetasStore, construct_lookup
from voicevox_engine.model import (
AccentPhrase,
AudioQuery,
DownloadableLibrary,
InstalledLibrary,
BaseLibraryInfo,
DownloadableLibraryInfo,
InstalledLibraryInfo,
MorphableTargetInfo,
ParseKanaBadRequest,
ParseKanaError,
Expand Down Expand Up @@ -845,10 +846,10 @@ def speaker_info(

@app.get(
"/downloadable_libraries",
response_model=list[DownloadableLibrary],
response_model=list[DownloadableLibraryInfo],
tags=["音声ライブラリ管理"],
)
def downloadable_libraries() -> list[DownloadableLibrary]:
def downloadable_libraries() -> list[DownloadableLibraryInfo]:
"""
ダウンロード可能な音声ライブラリの情報を返します。

Expand All @@ -862,10 +863,10 @@ def downloadable_libraries() -> list[DownloadableLibrary]:

@app.get(
"/installed_libraries",
response_model=dict[str, InstalledLibrary],
response_model=dict[str, InstalledLibraryInfo],
tags=["音声ライブラリ管理"],
)
def installed_libraries() -> dict[str, InstalledLibrary]:
def installed_libraries() -> dict[str, InstalledLibraryInfo]:
"""
インストールした音声ライブラリの情報を返します。

Expand Down Expand Up @@ -1226,7 +1227,7 @@ def setting_post(
},
)

# VvlibManifestモデルはAPIとして表には出ないが、エディタ側で利用したいので、手動で追加する
# BaseLibraryInfo/VvlibManifestモデルはAPIとして表には出ないが、エディタ側で利用したいので、手動で追加する
# ref: https://fastapi.tiangolo.com/advanced/extending-openapi/#modify-the-openapi-schema
def custom_openapi():
if app.openapi_schema:
Expand All @@ -1245,6 +1246,13 @@ def custom_openapi():
openapi_schema["components"]["schemas"][
"VvlibManifest"
] = VvlibManifest.schema()
# ref_templateを指定しない場合、definitionsを参照してしまうので、手動で指定する
base_library_info = BaseLibraryInfo.schema(
ref_template="#/components/schemas/{model}"
)
# definitionsは既存のモデルを重複して定義するため、不要なので削除
del base_library_info["definitions"]
openapi_schema["components"]["schemas"]["BaseLibraryInfo"] = base_library_info
app.openapi_schema = openapi_schema
return openapi_schema

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from fastapi import HTTPException

from voicevox_engine.downloadable_library import LibraryManager
from voicevox_engine.library_manager import LibraryManager

vvlib_manifest_name = "vvlib_manifest.json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from pydantic import ValidationError
from semver.version import Version

from voicevox_engine.model import DownloadableLibrary, InstalledLibrary, VvlibManifest
from voicevox_engine.model import (
DownloadableLibraryInfo,
InstalledLibraryInfo,
VvlibManifest,
)

__all__ = ["LibraryManager"]

Expand Down Expand Up @@ -76,9 +80,9 @@ def downloadable_libraries(self):
)
for i in range(1, 4)
]
return list(map(DownloadableLibrary.parse_obj, libraries))
return list(map(DownloadableLibraryInfo.parse_obj, libraries))

def installed_libraries(self) -> Dict[str, InstalledLibrary]:
def installed_libraries(self) -> Dict[str, InstalledLibraryInfo]:
library = {}
for library_dir in self.library_root_dir.iterdir():
if library_dir.is_dir():
Expand Down
15 changes: 12 additions & 3 deletions voicevox_engine/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ class LibrarySpeaker(BaseModel):
speaker_info: SpeakerInfo = Field(title="話者の追加情報")


class DownloadableLibrary(BaseModel):
class BaseLibraryInfo(BaseModel):
"""
ダウンロード可能な音声ライブラリの情報
音声ライブラリの情報
"""

name: str = Field(title="音声ライブラリの名前")
Expand All @@ -140,7 +140,16 @@ class DownloadableLibrary(BaseModel):
speakers: List[LibrarySpeaker] = Field(title="音声ライブラリに含まれる話者のリスト")


class InstalledLibrary(DownloadableLibrary):
# 今後InstalledLibraryInfo同様に拡張する可能性を考え、モデルを分けている
class DownloadableLibraryInfo(BaseLibraryInfo):
"""
ダウンロード可能な音声ライブラリの情報
"""

pass


class InstalledLibraryInfo(BaseLibraryInfo):
"""
インストール済み音声ライブラリの情報
"""
Expand Down