Skip to content

Commit

Permalink
Merge pull request #113 from ComposioHQ/kaavee/download
Browse files Browse the repository at this point in the history
Handle download response in file [ENG-800]
  • Loading branch information
kaavee315 committed Jun 8, 2024
2 parents 59e9b1b + facbf5a commit 0e5b8cc
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 4 deletions.
5 changes: 5 additions & 0 deletions composio/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
Local cache directory name for composio CLI
"""

LOCAL_OUTPUT_FILE_DIRECTORY_NAME = "output"
"""
Local output file directory name for composio tools
"""

USER_DATA_FILE_NAME = "user_data.json"
"""
Filename for storing user data.
Expand Down
15 changes: 14 additions & 1 deletion composio/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import os
import time
import typing as t
from pathlib import Path

Expand All @@ -13,6 +14,7 @@
ENV_COMPOSIO_API_KEY,
LOCAL_CACHE_DIRECTORY_NAME,
USER_DATA_FILE_NAME,
LOCAL_OUTPUT_FILE_DIRECTORY_NAME,
)
from composio.exceptions import raise_api_key_missing
from composio.storage.user import UserData
Expand All @@ -28,6 +30,7 @@ def __init__(
api_key: t.Optional[str] = None,
base_url: t.Optional[str] = None,
runtime: t.Optional[str] = None,
output_in_file: bool = False,
entity_id: str = DEFAULT_ENTITY_ID,
) -> None:
"""
Expand All @@ -53,6 +56,7 @@ def __init__(
)
self.runtime = runtime
self.entity_id = entity_id
self.output_in_file = output_in_file

def execute_action(
self,
Expand All @@ -71,4 +75,13 @@ def execute_action(
"""
if isinstance(action, str):
action = Action(action)
return self.client.get_entity(entity_id).execute(action=action, params=params)

output = self.client.get_entity(entity_id).execute(action=action, params=params)
if self.output_in_file:
if not os.path.exists(Path.home() / LOCAL_CACHE_DIRECTORY_NAME / LOCAL_OUTPUT_FILE_DIRECTORY_NAME):
os.makedirs(Path.home() / LOCAL_CACHE_DIRECTORY_NAME / LOCAL_OUTPUT_FILE_DIRECTORY_NAME)
output_file_path = Path.home() / LOCAL_CACHE_DIRECTORY_NAME / LOCAL_OUTPUT_FILE_DIRECTORY_NAME / f"{action.name}_{entity_id}_{time.time()}"
with open(output_file_path, 'w') as file:
file.write(str(output))
return {"output_file": f"{output_file_path}"}
return output
3 changes: 2 additions & 1 deletion examples/local_tools/langchain_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
prompt = hub.pull("hwchase17/openai-functions-agent")

# Get All the tools
tools = ComposioToolSet().get_tools([App.MATHEMATICAL])
tools = ComposioToolSet(output_in_file=True).get_tools([App.MATHEMATICAL])
print(tools)


task = "Calculate the forumula as mentioned in the file /Users/karanvaidya/codes/composio_sdk/eq.txt"
Expand Down
3 changes: 3 additions & 0 deletions plugins/autogen/composio_autogen/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(
api_key: t.Optional[str] = None,
base_url: t.Optional[str] = None,
entity_id: str = DEFAULT_ENTITY_ID,
output_in_file: bool = False,
) -> None:
"""
Initialize composio toolset.
Expand All @@ -33,12 +34,14 @@ def __init__(
:param api_key: Composio API key
:param base_url: Base URL for the Composio API server
:param entity_id: Entity ID for making function calls
:param output_in_file: Whether to write output to a file
"""
super().__init__(
api_key=api_key,
base_url=base_url,
runtime="autogen",
entity_id=entity_id,
output_in_file=output_in_file,
)
self.caller = caller
self.executor = executor
Expand Down
7 changes: 5 additions & 2 deletions plugins/claude/composio_claude/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

from composio.client.enums import Action, App, Tag
from composio.constants import DEFAULT_ENTITY_ID
from composio.tools import ComposioToolSet
from composio.tools import ComposioToolSet as BaseComposioToolSet
from composio.tools.schema import ClaudeSchema, SchemaType


class ComposioToolset(ComposioToolSet):
class ComposioToolset(BaseComposioToolSet):
"""
Composio toolset for Anthropic Claude platform.
Expand Down Expand Up @@ -55,19 +55,22 @@ def __init__(
api_key: t.Optional[str] = None,
base_url: t.Optional[str] = None,
entity_id: str = DEFAULT_ENTITY_ID,
output_in_file: bool = False,
) -> None:
"""
Initialize composio toolset.
:param api_key: Composio API key
:param base_url: Base URL for the Composio API server
:param entity_id: Entity ID for making function calls
:param output_in_file: Whether to write output to a file
"""
super().__init__(
api_key=api_key,
base_url=base_url,
runtime="claude",
entity_id=entity_id,
output_in_file=output_in_file,
)
self.schema = SchemaType.CLAUDE

Expand Down
3 changes: 3 additions & 0 deletions plugins/griptape/composio_griptape/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,22 @@ def __init__(
api_key: t.Optional[str] = None,
base_url: t.Optional[str] = None,
entity_id: str = DEFAULT_ENTITY_ID,
output_in_file: bool = False,
) -> None:
"""
Initialize composio toolset.
:param api_key: Composio API key
:param base_url: Base URL for the Composio API server
:param entity_id: Entity ID for making function calls
:param output_in_file: Whether to write output to a file
"""
super().__init__(
api_key=api_key,
base_url=base_url,
runtime="griptape",
entity_id=entity_id,
output_in_file=output_in_file,
)

def _wrap_tool(
Expand Down
3 changes: 3 additions & 0 deletions plugins/julep/composio_julep/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ def __init__(
api_key: t.Optional[str] = None,
base_url: t.Optional[str] = None,
entity_id: str = DEFAULT_ENTITY_ID,
output_in_file: bool = False,
) -> None:
"""
Initialize composio toolset.
:param api_key: Composio API key
:param base_url: Base URL for the Composio API server
:param entity_id: Entity ID for making function calls
:param output_in_file: Whether to write output to a file
"""
super().__init__(
api_key,
base_url,
entity_id=entity_id,
output_in_file=output_in_file,
)
self.runtime = "julep"

Expand Down
3 changes: 3 additions & 0 deletions plugins/langchain/composio_langchain/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,22 @@ def __init__(
api_key: t.Optional[str] = None,
base_url: t.Optional[str] = None,
entity_id: str = DEFAULT_ENTITY_ID,
output_in_file: bool = False,
) -> None:
"""
Initialize composio toolset.
:param api_key: Composio API key
:param base_url: Base URL for the Composio API server
:param entity_id: Entity ID for making function calls
:param output_in_file: Whether to write output to a file
"""
super().__init__(
api_key=api_key,
base_url=base_url,
runtime="langchain",
entity_id=entity_id,
output_in_file=output_in_file,
)

def _wrap_tool(
Expand Down
3 changes: 3 additions & 0 deletions plugins/lyzr/composio_lyzr/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,22 @@ def __init__(
api_key: t.Optional[str] = None,
base_url: t.Optional[str] = None,
entity_id: str = DEFAULT_ENTITY_ID,
output_in_file: bool = False,
) -> None:
"""
Initialize composio toolset.
:param api_key: Composio API key
:param base_url: Base URL for the Composio API server
:param entity_id: Entity ID for making function calls
:param output_in_file: Whether to write output to a file
"""
super().__init__(
api_key=api_key,
base_url=base_url,
runtime="lyzr",
entity_id=entity_id,
output_in_file=output_in_file,
)

def _wrap_tool(
Expand Down
3 changes: 3 additions & 0 deletions plugins/openai/composio_openai/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,22 @@ def __init__(
api_key: t.Optional[str] = None,
base_url: t.Optional[str] = None,
entity_id: str = DEFAULT_ENTITY_ID,
output_in_file: bool = False,
) -> None:
"""
Initialize composio toolset.
:param api_key: Composio API key
:param base_url: Base URL for the Composio API server
:param entity_id: Entity ID for making function calls
:param output_in_file: Whether to write output to a file
"""
super().__init__(
api_key,
base_url,
runtime="openai",
entity_id=entity_id,
output_in_file=output_in_file,
)
self.schema = SchemaType.OPENAI

Expand Down

0 comments on commit 0e5b8cc

Please sign in to comment.