File size: 7,564 Bytes
7200ed6
147252c
ca6df07
fd234e5
57f10fe
 
efe7912
6168534
 
57f10fe
9dceda0
bfb2154
1c477d1
a293459
1c477d1
997b388
bb41c4b
07cda62
fd234e5
71b294c
 
fd234e5
 
 
 
997b388
50c03f6
 
f995681
1c9438b
020335a
3a698b7
506056f
020335a
66e6274
020335a
 
 
 
3a698b7
06e2e1e
a562d9c
06e2e1e
e7b63ad
90d96a6
e7b63ad
06e2e1e
a600c86
3a698b7
506056f
020335a
 
 
 
 
 
 
 
 
 
 
 
90d96a6
020335a
 
 
 
 
 
3347cec
020335a
 
 
 
 
 
 
 
 
 
 
90d96a6
020335a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90d96a6
020335a
 
 
 
 
 
 
 
 
 
 
 
3a698b7
a562d9c
506056f
 
1151d64
90d96a6
506056f
bfb2154
3a698b7
 
 
 
 
020335a
9aa946f
020335a
3a698b7
 
 
020335a
9aa946f
020335a
9aa946f
020335a
 
 
 
 
9aa946f
020335a
 
 
4e4205d
020335a
 
 
 
 
3a698b7
 
 
d167f12
9aa946f
020335a
3a698b7
 
 
 
 
 
a8ed030
3a698b7
a8ed030
3a698b7
 
 
 
 
e1d67d3
 
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
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
from crewai.tools.mixtral_tools import MixtralSearchTools

# 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(discussion_topic):
    # Define your agents with roles and goals
    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
      ]
     
        # Add tools and other optional parameters as needed
    )
    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
      ]
     
        # Add tools and other optional parameters as needed
    )
    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
      ]
     
        # Add tools and other optional parameters as needed
    )
    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
      ]
     
        # Add tools and other optional parameters as needed
    )

    # Create tasks for your agents
    task1 = Task(
        description=f"""Discuss the  {discussion_topic}. Use Mixtral
        do 10 rounds of chat with. react to crazy3 """,
        agent=crazy2
    )

    task2 = Task(
        description=f"""Discuss the  {discussion_topic}. Use Mixtral
        do 10 rounds of chat with. react to crazy4.
        Discuss the impact of PTSD""",
        agent=crazy3
    )
    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=crazy4
    )
    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
    )

    # Instantiate your crew with a sequential process
    crew = Crew(
        agents=[crazy2, crazy3, crazy4, crazy5, crazy1],
        tasks=[task1, task2, task3, task4, task5],
        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 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/"
)

# Launch the interface
iface.launch(debug=True)