"vscode:/vscode.git/clone" did not exist on "6d2e19f7466b70574209d3da4488e16610c4fac6"
Commit 5621025c authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

feat: async filter support

parent 6bb2f418
...@@ -384,15 +384,29 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware): ...@@ -384,15 +384,29 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
try: try:
if hasattr(function_module, "inlet"): if hasattr(function_module, "inlet"):
data = function_module.inlet( inlet = function_module.inlet
data,
{ if inspect.iscoroutinefunction(inlet):
"id": user.id, data = await inlet(
"email": user.email, data,
"name": user.name, {
"role": user.role, "id": user.id,
}, "email": user.email,
) "name": user.name,
"role": user.role,
},
)
else:
data = inlet(
data,
{
"id": user.id,
"email": user.email,
"name": user.name,
"role": user.role,
},
)
except Exception as e: except Exception as e:
print(f"Error: {e}") print(f"Error: {e}")
return JSONResponse( return JSONResponse(
...@@ -1007,15 +1021,28 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)): ...@@ -1007,15 +1021,28 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)):
try: try:
if hasattr(function_module, "outlet"): if hasattr(function_module, "outlet"):
data = function_module.outlet( outlet = function_module.outlet
data, if inspect.iscoroutinefunction(outlet):
{ data = await outlet(
"id": user.id, data,
"email": user.email, {
"name": user.name, "id": user.id,
"role": user.role, "email": user.email,
}, "name": user.name,
) "role": user.role,
},
)
else:
data = outlet(
data,
{
"id": user.id,
"email": user.email,
"name": user.name,
"role": user.role,
},
)
except Exception as e: except Exception as e:
print(f"Error: {e}") print(f"Error: {e}")
return JSONResponse( return JSONResponse(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment