arcade-mcp/examples/fastapi/arcade_example_fastapi/main.py
Eric Gustin 43198a3a9b
Add New Gmail Tools To The Google Toolkit (#41)
# PR Description

## Summary

Changes include renaming the `arcade_gmail` toolkit to `arcade_google`,
adding unit tests for Google toolkit, add new tools to the Google
toolkit.
## Changes

### Makefile
- Added a new `make test-toolkits` target to iterate over all toolkits
and run pytest on each one.

### Added new tools for the google toolkit

1. `send_email`
This tool sends an email using the Gmail API.

2. `write_draft_email`
This tool creates a draft email using the Gmail API. 

3. `update_draft_email`
This tool updates an existing draft email using the Gmail API.

4. `send_draft_email`
This tool sends a draft email using the Gmail API.

5. `delete_draft_email`
This tool deletes a draft email using the Gmail API. 

6. `list_draft_emails`
This tool retrieves a list of draft emails using the Gmail API.

7. `list_emails_by_header`
This tool searches for emails by a specific header using the Gmail API.
- `sender`: The sender's email address to search for.
- `limit`: The maximum number of emails to retrieve.

8. `list_emails`
This tool retrieves a list of emails using the Gmail API.

9. `trash_email`
This tool moves an email to the trash using the Gmail API.
2024-09-19 10:18:49 -07:00

62 lines
2 KiB
Python

from arcade_github.tools import repo, user
from arcade_google.tools import gmail
from arcade_slack.tools import chat
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from arcade.actor.fastapi.actor import FastAPIActor
from arcade.client import AsyncArcade
from arcade.core.config import config
if not config.api or not config.api.key:
raise ValueError("Arcade API key not set. Please run `arcade login`.")
client = AsyncArcade(api_key=config.api.key)
app = FastAPI()
actor = FastAPIActor(app)
# actor.register_tool(arithmetic.add)
# actor.register_tool(arithmetic.multiply)
# actor.register_tool(arithmetic.divide)
# actor.register_tool(arithmetic.sqrt)
actor.register_tool(gmail.list_emails)
actor.register_tool(gmail.list_emails_by_header)
actor.register_tool(gmail.write_draft_email)
actor.register_tool(repo.count_stargazers)
actor.register_tool(repo.search_issues)
actor.register_tool(user.set_starred)
actor.register_tool(chat.send_dm_to_user)
actor.register_tool(chat.send_message_to_channel)
class ChatRequest(BaseModel):
message: str
@app.post("/chat")
async def postChat(request: ChatRequest, tool_choice: str = "execute"):
try:
raw_response = await client.chat.completions.create(
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": request.message},
],
model="gpt-4o-mini",
max_tokens=500,
tools=[
"GetEmails",
"SearchEmailsByHeader",
"WriteDraft",
"CountStargazers",
"SetStarred",
"SearchIssues",
"SendDmToUser",
"SendMessageToChannel",
],
tool_choice=tool_choice,
user=config.user.email if config.user else None,
)
return raw_response.choices
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))