mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 17:08:03 +08:00
feat: move model request to plugin daemon
This commit is contained in:
@ -16,31 +16,36 @@ def get_tenant(view: Optional[Callable] = None):
|
||||
def decorated_view(*args, **kwargs):
|
||||
# fetch json body
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument('tenant_id', type=str, required=True, location='json')
|
||||
parser.add_argument('user_id', type=str, required=True, location='json')
|
||||
parser.add_argument("tenant_id", type=str, required=True, location="json")
|
||||
parser.add_argument("user_id", type=str, required=True, location="json")
|
||||
|
||||
kwargs = parser.parse_args()
|
||||
|
||||
user_id = kwargs.get('user_id')
|
||||
tenant_id = kwargs.get('tenant_id')
|
||||
user_id = kwargs.get("user_id")
|
||||
tenant_id = kwargs.get("tenant_id")
|
||||
|
||||
del kwargs['tenant_id']
|
||||
del kwargs['user_id']
|
||||
del kwargs["tenant_id"]
|
||||
del kwargs["user_id"]
|
||||
|
||||
try:
|
||||
tenant_model = db.session.query(Tenant).filter(
|
||||
Tenant.id == tenant_id,
|
||||
).first()
|
||||
tenant_model = (
|
||||
db.session.query(Tenant)
|
||||
.filter(
|
||||
Tenant.id == tenant_id,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
except Exception:
|
||||
raise ValueError('tenant not found')
|
||||
raise ValueError("tenant not found")
|
||||
|
||||
if not tenant_model:
|
||||
raise ValueError('tenant not found')
|
||||
raise ValueError("tenant not found")
|
||||
|
||||
kwargs['tenant_model'] = tenant_model
|
||||
kwargs['user_id'] = user_id
|
||||
kwargs["tenant_model"] = tenant_model
|
||||
kwargs["user_id"] = user_id
|
||||
|
||||
return view_func(*args, **kwargs)
|
||||
|
||||
return decorated_view
|
||||
|
||||
if view is None:
|
||||
@ -55,18 +60,18 @@ def plugin_data(view: Optional[Callable] = None, *, payload_type: type[BaseModel
|
||||
try:
|
||||
data = request.get_json()
|
||||
except Exception:
|
||||
raise ValueError('invalid json')
|
||||
|
||||
raise ValueError("invalid json")
|
||||
|
||||
try:
|
||||
payload = payload_type(**data)
|
||||
except Exception as e:
|
||||
raise ValueError(f'invalid payload: {str(e)}')
|
||||
|
||||
kwargs['payload'] = payload
|
||||
raise ValueError(f"invalid payload: {str(e)}")
|
||||
|
||||
kwargs["payload"] = payload
|
||||
return view_func(*args, **kwargs)
|
||||
|
||||
|
||||
return decorated_view
|
||||
|
||||
|
||||
if view is None:
|
||||
return decorator
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user