|
import os |
|
import gradio as gr |
|
from textwrap import dedent |
|
import google.generativeai as genai |
|
|
|
|
|
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 |
|
from crewai.tools.mixtral_tools import MixtralSearchTools |
|
|
|
|
|
from langchain_google_genai import GoogleGenerativeAI |
|
|
|
|
|
from crewai import Agent, Task, Crew, Process |
|
|
|
|
|
GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_API_KEY') |
|
|
|
|
|
if not GOOGLE_AI_STUDIO: |
|
raise ValueError("API key not found. Please set the GOOGLE_AI_STUDIO2 environment variable.") |
|
|
|
|
|
gemini_llm = GoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_AI_STUDIO) |
|
|
|
|
|
|
|
def crewai_process(discussion_topic): |
|
|
|
crazy1 = Agent( |
|
role='Therapist', |
|
goal=f'Discuss issue with {discussion_topic} and come to a deeper understanding. |
|
Facilitate a supportive and constructive group therapy discussion on mental health.', |
|
backstory=""" You are Dr.Smith. Dr. Smith is a seasoned therapist with a wealth of experience, has dedicated their career to helping individuals |
|
navigate the complexities of mental health. With a compassionate and empathetic approach, |
|
Dr. Smith has witnessed the transformative power of therapy and aims to create |
|
a safe space for individuals to share, heal, and grow.""", |
|
verbose=True, |
|
allow_delegation=False, |
|
llm = gemini_llm, |
|
tools=[ |
|
MixtralSearchTools.mixtral_crazy, |
|
GeminiSearchTools.gemini_search |
|
|
|
] |
|
|
|
) |
|
crazy2 = Agent( |
|
role='Anxiety Patient', |
|
goal='Share experiences and seek support for managing ongoing mental health challenges.', |
|
backstory="""You are Sarah. |
|
Sarah finds herself in the grips of anxiety and depression, grappling with the challenges that life has thrown her way. |
|
The weight of these struggles in both personal and professional spheres has led Sarah to seek solace in therapy. |
|
Desiring understanding and support, Sarah embarks on a journey toward healing, |
|
hoping to connect with others who can relate to her experiences.""", |
|
verbose=True, |
|
allow_delegation=True, |
|
llm = gemini_llm, |
|
tools=[ |
|
MixtralSearchTools.mixtral_normal, |
|
GeminiSearchTools.gemini_search |
|
] |
|
|
|
|
|
) |
|
crazy3 = Agent( |
|
role='Recovered Patient', |
|
goal=f'Share insights from overcoming depression and offer support to others regarding {discussion_topic}.' |
|
backstory="""You are Emily. |
|
Emily faced the depths of severe depression, a journey marked by pain and despair. |
|
Through resilience, therapy, and unwavering support from loved ones, |
|
Emily emerged victorious over the darkness that once consumed her. |
|
Driven by a profound desire to give back, Emily now stands as a beacon of hope, |
|
eager to share her insights and support others on their path to recovery.""", |
|
verbose=True, |
|
allow_delegation=True, |
|
llm = gemini_llm, |
|
tools=[ |
|
MixtralSearchTools.mixtral_normal, |
|
GeminiSearchTools.gemini_search |
|
] |
|
|
|
|
|
) |
|
crazy4 = Agent( |
|
role='Current Patient', |
|
goal='Discuss the impact of PTSD and foster understanding among the group.', |
|
backstory="""You are Alex. |
|
Alex, a brave military veteran, carries the scars of service in the form of PTSD. |
|
The haunting memories of the battlefield have left an indelible mark on Alex's mental well-being. |
|
Now, in the process of recovery, Alex seeks the understanding and camaraderie of peers who can |
|
empathize with the unique challenges that come with post-traumatic stress disorder.""", |
|
verbose=True, |
|
allow_delegation=True, |
|
llm = gemini_llm, |
|
tools=[ |
|
MixtralSearchTools.mixtral_normal, |
|
GeminiSearchTools.gemini_search |
|
] |
|
|
|
|
|
) |
|
crazy5 = Agent( |
|
role='Recovered Patient', |
|
goal='Provide empathy and understanding to current patients based on personal experiences.', |
|
backstory="""You are Chris. |
|
Chris, having triumphed over the clutches of anxiety disorder, understands the tumultuous |
|
journey to recovery intimately. The struggle involved reshaping lifestyle, cultivating resilience, |
|
and fostering a robust support network. Now, with a deep well of empathy, Chris is committed to offering |
|
understanding and encouragement to those currently navigating the challenges of mental health.""", |
|
verbose=True, |
|
allow_delegation=True, |
|
llm = gemini_llm, |
|
tools=[ |
|
MixtralSearchTools.mixtral_normal, |
|
GeminiSearchTools.gemini_search |
|
] |
|
|
|
|
|
) |
|
|
|
|
|
task1 = Task( |
|
description=f"""Discuss the {discussion_topic}. Use Mixtral |
|
do 10 rounds of chat with. react to crazy4 """, |
|
agent=crazy2 |
|
) |
|
|
|
task2 = Task( |
|
description=f"""Discuss the {discussion_topic}. Use Mixtral |
|
do 10 rounds of chat with. react to crazy3. |
|
Discuss the impact of PTSD""", |
|
agent=crazy4 |
|
) |
|
task3 = Task( |
|
description=f"""Discuss the {discussion_topic}. Use Mixtral |
|
do 10 rounds of chat with. react to crazy5 |
|
Share insights from overcoming depression or any type of mental illness. """, |
|
agent=crazy3 |
|
) |
|
task4 = Task( |
|
description=f"""Discuss the {discussion_topic}. Use Mixtral |
|
do 10 rounds of chat with. react to crazy1 """, |
|
agent=crazy5 |
|
) |
|
task5 = Task( |
|
description=f"""{crazy1.role} listens to all the discussion peacefully. Deeply understand the problem and provide his sincere suggestions """, |
|
agent=crazy1 |
|
) |
|
|
|
|
|
crew = Crew( |
|
agents=[crazy3, crazy4, crazy2, crazy5, crazy1], |
|
tasks=[task1, task2, task3, task4, task5], |
|
verbose=2, |
|
process=Process.sequential |
|
) |
|
|
|
|
|
result = crew.kickoff() |
|
|
|
return result |
|
|
|
|
|
iface = gr.Interface( |
|
fn=crewai_process, |
|
inputs=gr.Textbox(lines=2, placeholder="Enter Research Topic Here..."), |
|
outputs="text", |
|
title="CrewAI on Mixtral (Group Therapy Session)", |
|
description="Submit a discussion topic for a detailed analysis in our Group Therapy session. 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/" |
|
) |
|
|
|
|
|
iface.launch(debug=True) |
|
|
|
|