File size: 1,531 Bytes
02f33b7
1
[{"id":"auto_disable_native_tools","name":"Auto Disable Native Tools","meta":{"description":"Automatically switches to default tool calling for models that don't support native tools","manifest":{"title":"Auto Disable Native Tools","author":"Brendan Campbell","author_url":"https://github.com/bcambs09","version":"0.1"},"type":"filter"},"content":"\"\"\"\ntitle: Auto Disable Native Tools\nauthor: Brendan Campbell\nauthor_url: https://github.com/bcambs09\nversion: 0.1\n\"\"\"\n\nfrom pydantic import BaseModel, Field\nfrom typing import Optional\n\n\nclass Filter:\n    class Valves(BaseModel):\n        pass\n\n    class UserValves(BaseModel):\n        pass\n\n    def __init__(self):\n        pass\n\n    def inlet(self, body: dict, __user__: Optional[dict] = None) -> dict:\n        metadata = body.get(\"metadata\")\n        if not metadata:\n            return body\n        function_calling = metadata.get(\"function_calling\")\n        if function_calling != \"native\":\n            return body\n        model = metadata.get(\"model\")\n        if not model:\n            return body\n        supported_parameters = model.get(\"supported_parameters\") if model else None\n        if supported_parameters and \"tools\" not in supported_parameters:\n            print(f\"Auto disabling native tool calling for {model.get('id')}\")\n            body[\"metadata\"][\"function_calling\"] = \"default\"\n        return body\n\n    def outlet(self, body: dict, __user__: Optional[dict] = None) -> dict:\n        return body\n"}]