File tree 1 file changed +17
-1
lines changed 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 23
23
"""
24
24
import os
25
25
import argparse
26
+ from typing import Literal , Union
26
27
27
28
import uvicorn
28
29
29
30
from llama_cpp .server .app import create_app , Settings
30
31
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
+
31
47
if __name__ == "__main__" :
32
48
parser = argparse .ArgumentParser ()
33
49
for name , field in Settings .model_fields .items ():
37
53
parser .add_argument (
38
54
f"--{ name } " ,
39
55
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 ,
41
57
help = description ,
42
58
)
43
59
You can’t perform that action at this time.
0 commit comments