File size: 2,860 Bytes
7200ed6 147252c ca6df07 fd234e5 57f10fe efe7912 6168534 57f10fe bfb2154 1c477d1 a293459 1c477d1 997b388 bb41c4b 07cda62 fd234e5 71b294c fd234e5 997b388 50c03f6 f995681 1c9438b 3a698b7 506056f 3a698b7 06e2e1e a562d9c 06e2e1e 506056f 06e2e1e a600c86 3a698b7 506056f 3a698b7 a562d9c 506056f bfb2154 3a698b7 506056f 3a698b7 506056f 3a698b7 d167f12 506056f 3a698b7 a8ed030 3a698b7 a8ed030 3a698b7 0663b51 bb7cbf1 3a698b7 147252c 3a698b7 777a1db c055605 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
import os
import gradio as gr
from textwrap import dedent
import google.generativeai as genai
# Tool import
from crewai.tools.gemini_tools import GeminiSearchTools
from langchain.tools.yahoo_finance_news import YahooFinanceNewsTool
from crewai.tools.browser_tools import BrowserTools
from crewai.tools.sec_tools import SECTools
# Google Langchain
from langchain_google_genai import GoogleGenerativeAI
#Crew imports
from crewai import Agent, Task, Crew, Process
# Retrieve API Key from Environment Variable
GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_API_KEY')
# Ensure the API key is available
if not GOOGLE_AI_STUDIO:
raise ValueError("API key not found. Please set the GOOGLE_AI_STUDIO2 environment variable.")
# Set gemini_llm
gemini_llm = GoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_AI_STUDIO)
# Base Example with Gemini Search
def crewai_process(research_topic):
# Define your agents with roles and goals
crazy1 = Agent(
role='Homeless Person',
goal=f'Discuss issue with {research_topic} and come to a deeper understanding',
backstory="""Not doing well mentally living on the street""",
verbose=True,
allow_delegation=False,
llm = gemini_llm,
tools=[
MixtralSearchTools.mixtral_crazy
]
)
crazy2 = Agent(
role='Distressed Mom',
goal='Resond to answers',
backstory="""Struggling with depression and loss of a child""",
verbose=True,
allow_delegation=True,
llm = gemini_llm,
tools=[
MixtralSearchTools.mixtral_crazy
]
# Add tools and other optional parameters as needed
)
# Create tasks for your agents
task1 = Task(
description=f"""Discuss the {query}. Use Mixtral
do 10 rounds of chat with """,
agent=crazy1
)
task2 = Task(
description=f"""Discuss the {query}. Use Mixtral
do 10 rounds of chat with """,
agent=crazy2
)
# Instantiate your crew with a sequential process
crew = Crew(
agents=[crazy1, crazy2],
tasks=[task1, task2],
verbose=2,
process=Process.sequential
)
# Get your crew to work!
result = crew.kickoff()
return result
# Create a Gradio interface
iface = gr.Interface(
fn=crewai_process,
inputs=gr.Textbox(lines=2, placeholder="Enter Research Topic Here..."),
outputs="text",
title="CrewAI on Gemini (Blog Post Writer)",
description="Input a research topic to get a comprehensive analysis (in logs) and a blog post draft (in output). To learn more connect with Mike Lively on LinkedIn at https://www.linkedin.com/in/awsmulticloud/ or join his cloud Meetup at https://www.meetup.com/florence-aws-user-group-meetup/"
)
# Launch the interface
iface.launch(debug=True)
|