@@ -67,30 +67,11 @@ def check_precheck_func(precheck_func: Callable):
67
67
raise ValueError (f"no output should exist for precheck function, found: { outputs } " )
68
68
69
69
70
- def generate_fast_api (
71
- app : str ,
72
- method_name : Optional [str ] = None ,
73
- id_str : Optional [str ] = None ,
74
- id_method : Optional [str ] = None ,
75
- precheck_str : Optional [str ] = None ,
76
- precheck_method : Optional [str ] = None ,
77
- ) -> FastAPI :
78
- instance = import_from_string (app )
79
- func = get_func (instance , method_name )
80
- if id_str :
81
- id_ref = import_from_string (id_str )
82
- plugin_id = get_plugin_id (instance = id_ref , method_name = id_method )
83
- else :
84
- plugin_id = hashlib .sha256 (
85
- json .dumps (get_schema_dict (func ), sort_keys = True ).encode ()
86
- ).hexdigest ()[:32 ]
87
-
88
- precheck_func = None
89
- if precheck_str :
90
- precheck_instance = import_from_string (precheck_str )
91
- precheck_func = get_func (precheck_instance , precheck_method )
92
- elif precheck_method :
93
- precheck_func = get_func (instance , precheck_method )
70
+ def wrap_in_fastapi (
71
+ func : Callable ,
72
+ plugin_id : str ,
73
+ precheck_func : Optional [Callable ] = None ,
74
+ ):
94
75
if precheck_func is not None :
95
76
check_precheck_func (precheck_func = precheck_func )
96
77
@@ -210,3 +191,31 @@ async def get_id() -> str:
210
191
)
211
192
212
193
return fastapi_app
194
+
195
+
196
+ def generate_fast_api (
197
+ app : str ,
198
+ method_name : Optional [str ] = None ,
199
+ id_str : Optional [str ] = None ,
200
+ id_method : Optional [str ] = None ,
201
+ precheck_str : Optional [str ] = None ,
202
+ precheck_method : Optional [str ] = None ,
203
+ ) -> FastAPI :
204
+ instance = import_from_string (app )
205
+ func = get_func (instance , method_name )
206
+ if id_str :
207
+ id_ref = import_from_string (id_str )
208
+ plugin_id = get_plugin_id (instance = id_ref , method_name = id_method )
209
+ else :
210
+ plugin_id = hashlib .sha256 (
211
+ json .dumps (get_schema_dict (func ), sort_keys = True ).encode ()
212
+ ).hexdigest ()[:32 ]
213
+
214
+ precheck_func = None
215
+ if precheck_str :
216
+ precheck_instance = import_from_string (precheck_str )
217
+ precheck_func = get_func (precheck_instance , precheck_method )
218
+ elif precheck_method :
219
+ precheck_func = get_func (instance , precheck_method )
220
+
221
+ return wrap_in_fastapi (func = func , plugin_id = plugin_id , precheck_func = precheck_func )
0 commit comments