From a18c776e7be711db29114841f91238cd32936efe Mon Sep 17 00:00:00 2001 From: afafw <82748932+afafw@users.noreply.github.com> Date: Tue, 25 Jul 2023 22:01:47 +0800 Subject: [PATCH 1/5] Update app.py due to basesetting shifted to pydantic_settings --- whisper_cpp_python/server/app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/whisper_cpp_python/server/app.py b/whisper_cpp_python/server/app.py index 0efa5d8..acb3bc1 100644 --- a/whisper_cpp_python/server/app.py +++ b/whisper_cpp_python/server/app.py @@ -9,7 +9,9 @@ from fastapi import Depends, FastAPI, APIRouter, File, Body from fastapi.middleware.cors import CORSMiddleware -from pydantic import BaseModel, BaseSettings, Field + +from pydantic import BaseModel, Field +from pydantic_settings import BaseSettings from sse_starlette.sse import EventSourceResponse From 2fea501f2f6364628254b9e73d919e941b26663b Mon Sep 17 00:00:00 2001 From: afafw <82748932+afafw@users.noreply.github.com> Date: Tue, 25 Jul 2023 23:05:44 +0800 Subject: [PATCH 2/5] migrating to pydantic 3.0 --- whisper_cpp_python/server/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whisper_cpp_python/server/__main__.py b/whisper_cpp_python/server/__main__.py index ab88931..0359a98 100644 --- a/whisper_cpp_python/server/__main__.py +++ b/whisper_cpp_python/server/__main__.py @@ -24,7 +24,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser() - for name, field in Settings.__fields__.items(): + for name, field in Settings.model_fields.items(): description = field.field_info.description if field.default is not None and description is not None: description += f" (default: {field.default})" From e8577e7b442db6076db036c1f7b14b7c4fb6254a Mon Sep 17 00:00:00 2001 From: afafw <82748932+afafw@users.noreply.github.com> Date: Tue, 25 Jul 2023 23:14:17 +0800 Subject: [PATCH 3/5] Still migrating --- whisper_cpp_python/server/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whisper_cpp_python/server/__main__.py b/whisper_cpp_python/server/__main__.py index 0359a98..73734a5 100644 --- a/whisper_cpp_python/server/__main__.py +++ b/whisper_cpp_python/server/__main__.py @@ -25,7 +25,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser() for name, field in Settings.model_fields.items(): - description = field.field_info.description + description = field.description if field.default is not None and description is not None: description += f" (default: {field.default})" parser.add_argument( From a4da04b62340a73e777f164d7fc893a9973838d4 Mon Sep 17 00:00:00 2001 From: afafw <82748932+afafw@users.noreply.github.com> Date: Tue, 25 Jul 2023 23:18:57 +0800 Subject: [PATCH 4/5] same above --- whisper_cpp_python/server/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whisper_cpp_python/server/__main__.py b/whisper_cpp_python/server/__main__.py index 73734a5..ae64aa7 100644 --- a/whisper_cpp_python/server/__main__.py +++ b/whisper_cpp_python/server/__main__.py @@ -31,7 +31,7 @@ parser.add_argument( f"--{name}", dest=name, - type=field.type_, + type=field.type, help=description, ) From 4065d7f472c5f61f2d975dcdb060e71d342f03d8 Mon Sep 17 00:00:00 2001 From: afafw <82748932+afafw@users.noreply.github.com> Date: Tue, 25 Jul 2023 23:22:59 +0800 Subject: [PATCH 5/5] test --- whisper_cpp_python/server/__main__.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/whisper_cpp_python/server/__main__.py b/whisper_cpp_python/server/__main__.py index ae64aa7..dac8195 100644 --- a/whisper_cpp_python/server/__main__.py +++ b/whisper_cpp_python/server/__main__.py @@ -17,28 +17,40 @@ """ import os -import uvicorn +import uvicorn import argparse +from typing import get_type_hints from whisper_cpp_python.server.app import create_app, Settings if __name__ == "__main__": + parser = argparse.ArgumentParser() + for name, field in Settings.model_fields.items(): + + # Get field type + field_type = get_type_hints(Settings)[name] + description = field.description if field.default is not None and description is not None: description += f" (default: {field.default})" + parser.add_argument( f"--{name}", dest=name, - type=field.type, - help=description, + type=field_type, # Use field type here + help=description ) args = parser.parse_args() + settings = Settings(**{k: v for k, v in vars(args).items() if v is not None}) + app = create_app(settings=settings) uvicorn.run( - app, host=os.getenv("HOST", "localhost"), port=int(os.getenv("PORT", 8001)) - ) + app, + host=os.getenv("HOST", "localhost"), + port=int(os.getenv("PORT", 8001)) + ) \ No newline at end of file