File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 2323"""
2424import os
2525import argparse
26+ from typing import Literal , Union
2627
2728import uvicorn
2829
2930from llama_cpp .server .app import create_app , Settings
3031
32+ def get_non_none_base_types (annotation ):
33+ if not hasattr (annotation , "__args__" ):
34+ return annotation
35+ return [arg for arg in annotation .__args__ if arg is not type (None )][0 ]
36+
37+ def get_base_type (annotation ):
38+ if getattr (annotation , '__origin__' , None ) is Literal :
39+ return type (annotation .__args__ [0 ])
40+ elif getattr (annotation , '__origin__' , None ) is Union :
41+ non_optional_args = [arg for arg in annotation .__args__ if arg is not type (None )]
42+ if non_optional_args :
43+ return get_base_type (non_optional_args [0 ])
44+ else :
45+ return annotation
46+
3147if __name__ == "__main__" :
3248 parser = argparse .ArgumentParser ()
3349 for name , field in Settings .model_fields .items ():
3753 parser .add_argument (
3854 f"--{ name } " ,
3955 dest = name ,
40- type = field .annotation if field .annotation is not None else str ,
56+ type = get_base_type ( field .annotation ) if field .annotation is not None else str ,
4157 help = description ,
4258 )
4359
You can’t perform that action at this time.
0 commit comments