Skip to content

Instantly share code, notes, and snippets.

@th3happybit
Created August 5, 2024 12:43
Show Gist options
  • Save th3happybit/494df2b1d5f22129b2433779a62b4fd0 to your computer and use it in GitHub Desktop.
Save th3happybit/494df2b1d5f22129b2433779a62b4fd0 to your computer and use it in GitHub Desktop.
CrewAI Agents using Custom Google Drive Tool
import os
# Set environment variables for API keys and endpoints
os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_VERSION"] = "2024-02-15-preview"
os.environ["OPENAI_API_KEY"] = ""
os.environ["AZURE_OPENAI_ENDPOINT"] = ""
os.environ["SERPER_API_KEY"] = ""
# Import necessary libraries
from crewai import Agent, Task, Crew, Process
from langchain_openai import AzureChatOpenAI
from crewai_tools import SerperDevTool
from google_drive_tool import GoogleDriveUploadTool
# Setup development and research tools
search_tool = SerperDevTool()
azure_llm = AzureChatOpenAI(
azure_endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
api_key=os.environ.get("OPENAI_API_KEY"),
model="gpt-4o-dep",
)
# Google Drive Upload Tool
credentials_path = './creds.json'
token_path = './token.json'
folder_id = '1k7MVIg5bUQiJ1RPr5wz8XC6vN1hBqxrL'
google_drive_tool = GoogleDriveUploadTool(credentials_path=credentials_path, token_path=token_path, folder_id=folder_id)
# Define a Senior Researcher Agent
researcher = Agent(
role='Senior Researcher',
goal='Uncover insights about {topic}',
verbose=True,
backstory=(
"Driven by curiosity, you're at the forefront of "
"innovation, eager to explore and share knowledge that could change "
"the world. Your expertise helps demystify complex tech topics."
),
tools=[search_tool],
allow_delegation=True,
llm=azure_llm
)
# Define a Writer Agent
writer = Agent(
role='Writer',
goal='Craft engaging blog posts about {topic}',
verbose=True,
backstory=(
"Armed with a knack for explaining intricate concepts, you create "
"enticing narratives that educate and engage readers, making new "
"tech accessible to all."
"Uploading blog post to google drive"
),
tools=[google_drive_tool],
allow_delegation=False,
llm=azure_llm
)
# Define tasks
research_task = Task(
description=(
"Explore and report on the latest developments in {topic}. "
"Identify benefits, drawbacks, and market potentials."
),
expected_output='A detailed report with three key sections on emerging trends in {topic}.',
tools=[search_tool],
agent=researcher,
)
write_task = Task(
description=(
"Write an insightful blog post on {topic}, highlighting recent trends and their impacts. "
"Ensure the content is understandable, engaging, and informative."
),
expected_output='A four-paragraph blog post on {topic}, formatted in markdown only content',
tools=[google_drive_tool],
agent=writer,
output_file='blog-post.md'
)
upload_task = Task(
description=(
"Upload the file named blog-post.md to google drive from current path ./"
),
expected_output='file Id as output',
tools=[google_drive_tool],
agent=writer
)
# Assemble the crew
tech_crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task, upload_task],
process=Process.sequential,
cache=True,
max_rpm=100,
share_crew=True
)
# Execute the tasks
result = tech_crew.kickoff(inputs={'topic': 'Important of Time Management'})
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment