Commit ae567796 authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

refac

parent 9220fdc4
...@@ -130,7 +130,9 @@ async def get_pipe_models(): ...@@ -130,7 +130,9 @@ async def get_pipe_models():
manifold_pipe_name = p["name"] manifold_pipe_name = p["name"]
if hasattr(function_module, "name"): if hasattr(function_module, "name"):
manifold_pipe_name = f"{pipe.name}{manifold_pipe_name}" manifold_pipe_name = (
f"{function_module.name}{manifold_pipe_name}"
)
pipe_models.append( pipe_models.append(
{ {
......
...@@ -389,26 +389,31 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware): ...@@ -389,26 +389,31 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
if hasattr(function_module, "inlet"): if hasattr(function_module, "inlet"):
inlet = function_module.inlet inlet = function_module.inlet
if inspect.iscoroutinefunction(inlet): # Get the signature of the function
data = await inlet( sig = inspect.signature(inlet)
data, param = {"body": data}
{
if "__user__" in sig.parameters:
param = {
**param,
"__user__": {
"id": user.id, "id": user.id,
"email": user.email, "email": user.email,
"name": user.name, "name": user.name,
"role": user.role, "role": user.role,
}, },
) }
if "__id__" in sig.parameters:
param = {
**param,
"__id__": filter_id,
}
if inspect.iscoroutinefunction(inlet):
data = await inlet(**param)
else: else:
data = inlet( data = inlet(**param)
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}")
...@@ -1031,26 +1036,32 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)): ...@@ -1031,26 +1036,32 @@ async def chat_completed(form_data: dict, user=Depends(get_verified_user)):
try: try:
if hasattr(function_module, "outlet"): if hasattr(function_module, "outlet"):
outlet = function_module.outlet outlet = function_module.outlet
if inspect.iscoroutinefunction(outlet):
data = await outlet( # Get the signature of the function
data, sig = inspect.signature(outlet)
{ param = {"body": data}
if "__user__" in sig.parameters:
param = {
**param,
"__user__": {
"id": user.id, "id": user.id,
"email": user.email, "email": user.email,
"name": user.name, "name": user.name,
"role": user.role, "role": user.role,
}, },
) }
if "__id__" in sig.parameters:
param = {
**param,
"__id__": filter_id,
}
if inspect.iscoroutinefunction(outlet):
data = await outlet(**param)
else: else:
data = outlet( data = outlet(**param)
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}")
......
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