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 google plugin [ENG-1238] #585

Merged
merged 9 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
praisonai,
langgraph,
phidata,
google,
]
runs-on: ${{ matrix.os }}
steps:
Expand Down
119 changes: 119 additions & 0 deletions docs/framework/google.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
title: "Using Composio With Google AI"
sidebarTitle: "Google AI"
icon: "robot"
description: "Enable Google AI models to seamlessly interact with external apps via Composio for enhanced functionality"
---

**Composio enables** your **Google AI models** to **connect** with many **tools**!

### Install Packages & Connect a Tool

<Tip>
Goal: Enable Google AI models to perform tasks like starring a repository on
GitHub via natural language commands
</Tip>

These steps prepare your environment to enable interactions between Google AI and GitHub through Composio.

<CodeGroup>
```bash Run Command
pip install composio-google

# Connect your GitHub so models can interact with it

composio add github

# Check all supported apps

composio apps
```
</CodeGroup>

<Steps>

<Step title="Import Base Packages & Initialize Google AI Model">
Replace `{google_api_key}` with your actual API key.
<CodeGroup>
```python Default Imports & Configuration
import dotenv
from composio_google import App, ComposioToolset
from vertexai.generative_models import GenerativeModel

# Load environment variables from .env
dotenv.load_dotenv()

# Initialize the Composio Toolset
composio_toolset = ComposioToolset()

# Get GitHub tools that are pre-configured
tool = composio_toolset.get_tool(apps=[App.GITHUB])

# Initialize the Google AI Gemini model
model = GenerativeModel("gemini-1.5-pro", tools=[tool])
```
</CodeGroup>
</Step>

<Step title="Start a Chat Session with the Model">
<CodeGroup>
```python Start Chat Session
# Start a chat session
chat = model.start_chat()
```
</CodeGroup>
</Step>

<Step title="Execute the Task via Google AI Model">
<CodeGroup>
```python Execute Task
# Define task
task = "Star a repo composiohq/composio on GitHub"

# Send a message to the model
response = chat.send_message(task)

print("Model response:")
print(response)
```
</CodeGroup>
</Step>

<Step title="Handle the Tool Calls">
<CodeGroup>
```python Handle Tool Calls
result = composio_toolset.handle_response(response)
print("Function call result:")
print(result)
```
</CodeGroup>
</Step>

</Steps>

### Use Specific Actions

<CodeGroup>
```python Filter Specific Action
# To restrict models from executing any actions, filter specific actions
actions = composio_toolset.get_tool(actions=[Action.GITHUB_CREATE_ISSUE])
```
</CodeGroup>

### Use Specific Apps

<CodeGroup>
```python Filter Specific App
# To restrict models from using all tools, filter specific tools
actions = composio_toolset.get_tool(apps=[App.ASANA, App.GITHUB])
```
</CodeGroup>

### Filter apps actions by tags

<CodeGroup>
```python Filter Actions by Tags
actions = composio_toolset.get_tool(apps=[App.ASANA], tags=[Tag.ASANA_TASKS])
```
</CodeGroup>

2 changes: 1 addition & 1 deletion docs/framework/julep.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Using Composio With Julep"
sidebarTitle: "Julep"
icon: "glass"
icon: "robot"
description: "Integrate Composio with Julep agents to enhance their interaction with external apps"
---

Expand Down
66 changes: 66 additions & 0 deletions python/plugins/google/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## 🚀🔗 Integrating Composio with Google AI Python

Streamline the integration of Composio with Google AI Python to enhance the capabilities of Gemini models, allowing them to interact directly with external applications and expanding their operational scope.

### Objective

- **Automate starring a GitHub repository** using conversational instructions via Google AI Python's Function Calling feature.

### Installation and Setup

Ensure you have the necessary packages installed and connect your GitHub account to allow your agents to utilize GitHub functionalities.

```bash
# Install Composio LangChain package
pip install composio-google

# Connect your GitHub account
composio-cli add github

# View available applications you can connect with
composio-cli show-apps
```

### Usage Steps

#### 1. Import Base Packages

Prepare your environment by initializing necessary imports from Google AI Python and setting up your client.

```python
from vertexai.generative_models import GenerativeModel

# Initialize Google AI Python client
model = GenerativeModel("gemini-pro")
```

### Step 2: Integrating GitHub Tools with Composio

This step involves fetching and integrating GitHub tools provided by Composio, enabling enhanced functionality for Google AI Python operations.
```python
from composio_google import App, ComposioToolset

toolset = ComposioToolset()
actions = toolset.get_tools(apps=[App.GITHUB])
```

### Step 3: Agent Execution

This step involves configuring and executing the agent to carry out actions, such as starring a GitHub repository.

```python
# Define task
task = "Star a repo composiohq/composio on GitHub"

# Send a message to the model
response = chat.send_message(task)
```

### Step 4: Validate Execution Response

Execute the following code to validate the response, ensuring that the intended task has been successfully completed.

```python
result = composio_toolset.handle_response(response)
print("Function call result:", result)
```
13 changes: 13 additions & 0 deletions python/plugins/google/composio_google/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from composio_google.toolset import ComposioToolset

from composio import Action, App, Tag, Trigger, WorkspaceType


__all__ = (
"Action",
"App",
"Tag",
"Trigger",
"WorkspaceType",
"ComposioToolset",
)
Loading
Loading