Skip to content

Commit

Permalink
Merge branch 'ft-change-to-https-module' of github.com:ComposioHQ/com…
Browse files Browse the repository at this point in the history
…posio into ft-change-to-https-module
  • Loading branch information
himanshu-dixit committed Dec 11, 2024
2 parents 77dc90f + f0c8022 commit 2bae53f
Show file tree
Hide file tree
Showing 35 changed files with 1,454 additions and 2,157 deletions.
1 change: 0 additions & 1 deletion .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ jobs:
python -m pip install 'numpy<2' python-dotenv
python -m pip install unstructured
COMPOSIO_BASE_URL=${{ env.COMPOSIO_BASE_URL }} COMPOSIO_API_KEY=${{ env.COMPOSIO_API_KEY }} COMPOSIO_LOGGING_LEVEL='debug' composio apps update
COMPOSIO_BASE_URL=${{ env.COMPOSIO_BASE_URL }} COMPOSIO_API_KEY=${{ env.COMPOSIO_API_KEY }} COMPOSIO_LOGGING_LEVEL='debug' PLUGIN_TO_TEST=${{matrix.package}} CI=false pytest -vv tests/test_example.py
COMPOSIO_BASE_URL=${{ env.COMPOSIO_BASE_URL }} COMPOSIO_API_KEY=${{ env.COMPOSIO_API_KEY }} COMPOSIO_LOGGING_LEVEL='debug' PLUGIN_TO_TEST=${{matrix.package}} CI=false pytest -vv tests/test_load_tools.py
- name: Slack Notification on Failure
Expand Down
35 changes: 33 additions & 2 deletions docs/patterns/tools/build-tools/custom-action-with-auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,29 @@ Custom Actions are powerful building blocks that enable you to create custom fun

## Creating a Custom Action with Authentication

<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/tVfm90v5_sM?si=4nk5sOBwhUdx_HtT"
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>


<Steps>
<Step title="Install Dependencies">
<CodeGroup>
```bash Python
pip install composio_openai openai
```

```bash JavaScript
npm install composio-core openai
```
</CodeGroup>
</Step>
<Step title="Import necessary modules & initialize them">

<CodeGroup>
Expand All @@ -35,7 +57,16 @@ const openAIToolset = new OpenAIToolSet();
</Step>

<Step title="Creating a custom action">
Below are examples of creating a custom action called `list_repositories` (Python) & `star_repo` (JavaScript) that integrates with the `github` tool. This action demonstrates how to list all the repositories for a given user or organization.
Below are examples of creating a custom action called `list_repositories` (Python) & `star_repo` (JavaScript) that integrates with the `github` tool.

You need to add the action, input parameters & return content description, this is what the LLM will use to understand the action.

The `execute_request/executeRequest` method is used to make API calls, it accepts the following arguments:
- `endpoint`: Endpoint URL. The base URL of the API will be prepended to this. You can find it in your connection's **Connection Info** section
- `method`: HTTP method to use
- `body`: Request body to pass to the API
- `parameters`: Custom Authentication Parameters
- `connection_id`: ID of the connected account

<Note>
Since `github` is a registered tool in Composio, the authentication credentials are automatically injected into your custom action!
Expand Down Expand Up @@ -90,7 +121,7 @@ const action = await openAIToolset.createAction({

</Step>
<Step title="Executing the Custom Action">
Executing the custom action using LLM
Executing the custom action using LLM. Learn how to execute the custom action without LLM [here](/patterns/tools/use-tools/action-guide-without-agents#how-to-execute-custom-actions-directly).
<CodeGroup>
```python Python
tools = toolset.get_tools(actions=[list_repositories])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const toolset = new OpenAIToolSet();
</CodeGroup>
</Step>
<Step title="Creating a custom action">
Below are examples of creating a custom action called `my_custom_action` (Python) & `myCustomAction` (JavaScript) to make cowsay say whatever you want it to say.

You need to add the action, input parameters & return content description, this is what the LLM will use to understand the action.
<CodeGroup>
```python Python
@action(toolname="cow", requires=["cowsay"])
Expand Down Expand Up @@ -64,7 +67,7 @@ await toolset.createAction({
</CodeGroup>
</Step>
<Step title="Executing the Custom Action">
Executing the custom action using LLM
Executing the custom action using LLM. Learn how to execute the custom action without LLM [here](/patterns/tools/use-tools/action-guide-without-agents#how-to-execute-custom-actions-directly).
<CodeGroup>
```python Python
tools = toolset.get_tools(actions=[my_custom_action])
Expand Down
97 changes: 40 additions & 57 deletions docs/patterns/tools/use-tools/action-guide-without-agents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,101 +10,84 @@ description: "Guide to use Tools directly as function calls"
Composio allows you to execute tools directly as function calls. When calling a tool directly, you'll need to provide the input parameters. Checkout [Get Action Schema](/patterns/tools/use-tools/get-action-inputs) to learn how to get the input parameters for an action.

<CodeGroup>
```python Python Star a repo
```python Python
from composio import ComposioToolSet, Action

tool_set = ComposioToolSet(entity_id="Jessica")
#If you did not run 'composio login' in the CLI, you can use API Key like this:
#tool_set = ComposioToolSet(api_key, entity_id="Jessica")

#You can change the repo you want to star by modifying the parameters
tool_set.execute_action(
action=Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER,
params={"owner": "composiohq", "repo": "composio"},
entity_id="Jessica",
)
```

```javascript JavaScript Get Hypermedia links in GitHub
```javascript JavaScript
import { OpenAIToolSet } from "composio-core";

const toolset = new OpenAIToolSet();
const entity = toolset.client.getEntity("Jessica");

const customAuthAction = await toolset.client.actions.execute({
actionName: "GITHUB_GITHUB_API_ROOT",
requestBody: {
appName: "github",
authConfig: {
parameters: [{
name: "Authorization",
in: "header",
value: `Bearer YOUR_API_KEY`
}]
},
input: {}
const result = await entity.execute(
"GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER",
{
"owner": "composiohq",
"repo": "composio"
}
});

console.log("Custom auth action response", customAuthAction)
);
console.log(result);
```
</CodeGroup>

### Execute Tools or Actions with Natural Language
You can also execute Tools or Actions by passing in natural language prompts without specific parameters
<CodeGroup>
```python Python
tool_set.execute_action(
action=Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER,
params={},
# Natural language prompt
text="Star the repo composiohq/composio",
entity_id="Jessica",
)
tool_set.execute_action(
action=Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER,
params={},
# Natural language prompt
text="Star the repo composiohq/composio",
entity_id="Jessica",
)
```

```javascript JavaScript
await toolset.getEntity("Jessica").execute(
const result = await toolset.client.getEntity("Jessica").execute(
'github_star_a_repository_for_the_authenticated_user',
{},
// Natural language prompt
"Star the repo composiohq/composio"
);
)
console.log(result);
```
</CodeGroup>

### How can I use Tools for a specific user?
You can use the entity object of a specific user and execute action on behalf of that user. Learn more about Entities [here](/patterns/Auth/connected_account#entities).

### How to execute custom actions directly?
You can execute custom actions directly by specifying the action name as shown below. Here `create_draft` is the custom action name. Learn more about custom actions [here](/patterns/tools/build-tools/custom-action-with-auth).
<CodeGroup>

```python Python {4}
from composio import ComposioToolSet

toolset = ComposioToolSet()
entity = toolset.get_entity(id='Jessica')

res = entity.execute(
action=Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER,
```python Python {2}
toolset.execute_action(
action=create_draft,
params={
"owner": "composiohq",
"repo": "composio"
"thread_id": "",
"message_body": "",
},
entity_id="Jessica",
)
print(res)
```

```javascript JavaScript {4}
import { OpenAIToolSet } from "composio-core";

const toolset = new OpenAIToolSet();
const entity = toolset.client.getEntity(id='Jessica');
const result = entity.execute(
action="GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER",
params={
"owner": "composiohq",
"repo": "composio"
```javascript JavaScript {2}
const result = await langchainToolset.executeAction({
action: "create_draft",
params:{
thread_id: "",
message_body: ""
},
)
entityId: "Jessica",
})

console.log(result);
```
</CodeGroup>
</CodeGroup>


2 changes: 1 addition & 1 deletion python/.pylintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[MASTER]
ignore-patterns=
ignore-patterns=.*\.pyi
ignore=

[MESSAGES CONTROL]
Expand Down
Loading

0 comments on commit 2bae53f

Please sign in to comment.