Skip to content

Commit

Permalink
Merge branch 'master' into chore/restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade committed Apr 25, 2024
2 parents 7284323 + a41438f commit 14ff9b1
Show file tree
Hide file tree
Showing 28 changed files with 1,058 additions and 602 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/release_workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Build and Release

on:
push:
tags:
- 'v*'

jobs:
setup:
runs-on: ubuntu-latest
outputs:
package_version: ${{ steps.extract_version.outputs.package_version }}
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine build
pip install -r core/requirements.txt
pip install -r langchain/requirements.txt
pip install -r crew_ai/requirements.txt
pip install -r lyzr/requirements.txt
- name: Extract version from tag
id: extract_version
run: echo "::set-output name=package_version::${GITHUB_REF#refs/tags/v}"


build-and-publish:
needs: setup
runs-on: ubuntu-latest
strategy:
max-parallel: 1
# fail-fast: true
matrix:
package: [core, langchain, autogen, crew_ai, lyzr]

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Install dependencies
run: pip install -r ${{ matrix.package }}/requirements.txt

- name: Update version and dependencies
if: startsWith(github.ref, 'refs/tags/v')
run: |
cd ${{ matrix.package }}
sed -i "s/composio_core===.*/composio_core===${{ needs.setup.outputs.package_version }}\",/" pyproject.toml
sed -i "s/composio_core===.*/composio_core===${{ needs.setup.outputs.package_version }}\"/" requirements.txt
sed -i "s/composio_langchain===.*/composio_langchain===${{ needs.setup.outputs.package_version }}\",/" pyproject.toml
sed -i "s/composio_langchain===.*/composio_langchain===${{ needs.setup.outputs.package_version }}\"/" requirements.txt
echo "Updated version in setup.py, pyproject.toml, and requirements.txt"
echo "<----- Pyproject.toml ----->"
cat pyproject.toml
echo "<----- Requirements.txt ----->"
cat requirements.txt
cd ..
- name: Build and install package locally
run: |
cd ${{ matrix.package }}
pip install build
python -m build
pip install -e .
cd ..
env:
RELEASE_VERSION: ${{ needs.setup.outputs.package_version }}

- name: Publish package
if: startsWith(github.ref, 'refs/tags/v')
run: |
pip install twine
cd ${{ matrix.package }} && twine upload dist/* && cd ../
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
38 changes: 30 additions & 8 deletions composio/composio_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
import termcolor
from .sdk.storage import get_base_url, save_api_key
from .sdk.core import ComposioCore, UnauthorizedAccessException
from .sdk.utils import generate_enums, generate_enums_beta
from .sdk.utils import generate_enums, generate_enums_beta, get_enum_key
from rich.table import Table
from .sdk.enums import App

import webbrowser

Expand Down Expand Up @@ -107,6 +108,12 @@ def parse_arguments():
generate_enums_beta_parser = subparsers.add_parser('update-beta', help='Update enums including beta for apps and actions')
generate_enums_beta_parser.set_defaults(func=handle_update_beta)

# Get actions for use case command
get_actions_parser = subparsers.add_parser('get-actions', help='Get actions for a given use case')
get_actions_parser.add_argument('app_name', type=str, help='Name of the app to get actions for')
get_actions_parser.add_argument('use_case', type=str, help='Name of the use case to get actions for')
get_actions_parser.set_defaults(func=get_actions)

return parser.parse_args()

def login(args):
Expand Down Expand Up @@ -276,11 +283,6 @@ def enable_trigger(args):
user_input = input(f"{field_title} ({field_description}): ")
user_inputs[field] = user_input

app_enum = client.get_action_enum(app_key)
if not app_enum:
console.print(f"[red]No such app found for {app_key}.\nUse the following command to get list of available apps: [green]composio-cli add show-apps[/green][/red]")
sys.exit(1)

connected_account = client.get_connection(app_key)
if not connected_account:
console.print(f"[red]No connection found for {app_key}.\nUse the following command to add a connection: [green]composio-cli add {app_key}[/green][/red]")
Expand Down Expand Up @@ -317,6 +319,26 @@ def handle_update_beta(args):
generate_enums_beta()
console.print(f"\n[green]✔ Enums(including Beta) updated successfully![/green]\n")

def get_actions(args):
client = ComposioCore()
app_name = args.app_name
use_case = args.use_case
try:
for app_enum in App:
if app_enum.value == app_name:
app = app_enum
break
if not app:
console.print(f"[red]No such app found for {app_name}.\nUse the following command to get list of available apps: [green]composio-cli add show-apps[/green][/red]")
sys.exit(1)
actions = client.sdk.get_list_of_actions(apps=[app], use_case=use_case)
action_enums = [f"Action.{get_enum_key(action['name'])}" for action in actions]
console.print(f"\n[green]> Actions for {app_name} and use case {use_case}:[/green]\n")
console.print(", ".join(action_enums))
except Exception as e:
console.print(f"[red] Error occurred during getting actions: {e}[/red]")
sys.exit(1)

def add_integration(args):
global should_disable_webbrowser_open

Expand All @@ -338,7 +360,7 @@ def add_integration(args):
auth_schemes = app.get('auth_schemes')
auth_modes_arr = [auth_scheme.get('auth_mode') for auth_scheme in auth_schemes]
if len(auth_modes_arr) > 0 and auth_modes_arr[0] in ['API_KEY', 'BASIC', 'SNOWFLAKE']:
connection = entity.initiate_connection_not_oauth(integration_name.lower(), auth_mode=auth_modes_arr[0])
connection = entity.initiate_connection_not_oauth(app_name=integration_name.lower(), auth_mode=auth_modes_arr[0])
fields = auth_schemes[0].get('fields')
fields_input = {}
for field in fields:
Expand All @@ -356,7 +378,7 @@ def add_integration(args):
connection.save_user_access_data(fields_input, entity_id=entity.entity_id)
else:
# @TODO: add logic to wait and ask for API_KEY
connection = entity.initiate_connection(integration_name.lower())
connection = entity.initiate_connection(app_name=integration_name.lower())
if not should_disable_webbrowser_open:
webbrowser.open(connection.redirectUrl)
print(f"Please authenticate {integration_name} in the browser and come back here. URL: {connection.redirectUrl}")
Expand Down
6 changes: 3 additions & 3 deletions composio/sdk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def generate_cli_auth_session(self):
if resp.get('key'):
return resp['key']

raise Exception("Bad request to cli/generate-cli-session")
raise Exception(f"Bad request to cli/generate-cli-session. Status code: {resp.status_code}, response: {resp.text}")

def verify_cli_auth_session(self, key: str, code: str):
resp = self.http_client.get(f"{self.base_url}/v1/cli/verify-cli-code?key={key}&code={code}");
Expand All @@ -97,7 +97,7 @@ def verify_cli_auth_session(self, key: str, code: str):
elif resp.status_code == 401:
raise UnauthorizedAccessException("UnauthorizedError: Unauthorized access to cli/verify-cli-session")

raise Exception("Bad request to cli/verify-cli-session")
raise Exception(f"Bad request to cli/verify-cli-session. Status code: {resp.status_code}, response: {resp.text}")

def initiate_connection(self, appName: Union[str, App], integrationId: str = None) -> ConnectionRequest:
if integrationId is None:
Expand All @@ -112,7 +112,7 @@ def initiate_connection(self, appName: Union[str, App], integrationId: str = Non
if resp.status_code == 200:
return ConnectionRequest(self.sdk, **resp.json())

raise Exception("Failed to create connection")
raise Exception(f"Failed to create connection. Status code: {resp.status_code}, response: {resp.text}")

def set_global_trigger(self, callback_url: str):
try:
Expand Down
Loading

0 comments on commit 14ff9b1

Please sign in to comment.