Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for disabling remote enum fetching #603

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions python/composio/client/enums/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Enum helper base.
"""

import os
import typing as t
import warnings
from pathlib import Path
Expand All @@ -25,6 +26,10 @@
ACTIONS_CACHE = LOCAL_CACHE_DIRECTORY / "actions"
TRIGGERS_CACHE = LOCAL_CACHE_DIRECTORY / "triggers"

NO_REMOTE_ENUM_FETCHING = (
os.environ.get("COMPOSIO_NO_REMOTE_ENUM_FETCHING", "false") == "true"
)


class EnumStringNotFound(ComposioSDKError):
"""Raise when user provides invalid enum string."""
Expand Down Expand Up @@ -197,6 +202,16 @@ def _cache_from_local(self) -> t.Optional[EntityType]:
return None

def _cache_from_remote(self) -> EntityType:
if NO_REMOTE_ENUM_FETCHING:
raise ComposioSDKError(
message=(
f"No metadata found for enum `{self.slug}`, "
"You might be trying to use an app or action "
"that is deprecated, run `composio apps update` "
"and try again"
)
)

from composio.client import Composio # pylint: disable=import-outside-toplevel
from composio.client.endpoints import ( # pylint: disable=import-outside-toplevel
v2,
Expand Down
27 changes: 26 additions & 1 deletion python/tests/test_client/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
Test the auto-generate Enum
"""

from pathlib import Path
from typing import Dict, List
from unittest import mock

import pytest
from pydantic import BaseModel

from composio import action
from composio.client.enums import Action, App, Tag, Trigger
from composio.client.enums import Action, App, Tag, Trigger, base
from composio.exceptions import ComposioSDKError
from composio.tools.base.local import LocalAction, LocalTool


Expand Down Expand Up @@ -83,6 +86,28 @@ def test_load_remote_trigger(self, _patch) -> None:
assert enum.slug == Trigger.GITHUB_COMMIT_EVENT.slug


class TestDisableRemoteCaching:
def setup_method(self) -> None:
base.NO_REMOTE_ENUM_FETCHING = True

def teardown_method(self) -> None:
base.NO_REMOTE_ENUM_FETCHING = False

def test_error(self) -> None:
"""Test `NO_REMOTE_ENUM_FETCHING` set to True."""
enum = Action.GITHUB_META_ROOT
enum._path = Path("temp") # pylint: disable=protected-access
with pytest.raises(
ComposioSDKError,
match=(
"No metadata found for enum `GITHUB_META_ROOT`, You might be "
"trying to use an app or action that is deprecated, run "
"`composio apps update` and try again"
),
):
enum.load()


def test_tag_enum() -> None:
"""Test `Tag` enum."""
tag = Tag("ASANA_ALLOCATIONS")
Expand Down
5 changes: 4 additions & 1 deletion python/tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@
"values": ["composio_output/CODEINTERPRETER_GET_FILE_CMD_default_", ""],
},
"env": {"OPENAI_API_KEY": OPENAI_API_KEY, "COMPOSIO_API_KEY": COMPOSIO_API_KEY},
"cwd": EXAMPLES_PATH / "quickstarters" / "sql_agent" / "sql_agent_plotter_crewai",
"cwd": EXAMPLES_PATH
/ "quickstarters"
/ "sql_agent"
/ "sql_agent_plotter_crewai",
},
"multi_entity_api_key": {
"plugin": "langchain",
Expand Down
Loading