skjaini commited on
Commit
c8b5c08
·
verified ·
1 Parent(s): 1c7f0f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -19
app.py CHANGED
@@ -4,19 +4,17 @@ from langchain_community.tools import DuckDuckGoSearchRun
4
  from langchain_google_genai import ChatGoogleGenerativeAI
5
  import os
6
  import google.generativeai as genai
7
- from langchain.tools import BaseTool # Import BaseTool
8
 
9
 
10
- # Configure Gemini API Key (replace with your actual key)
11
- # Use Streamlit secrets for secure storage.
12
  GOOGLE_API_KEY = st.secrets["GOOGLE_API_KEY"]
13
  genai.configure(api_key=GOOGLE_API_KEY)
14
 
15
 
16
- # Define Tools - Corrected: Wrap the tool in a list if it's a single tool
17
  search_tool = DuckDuckGoSearchRun()
18
 
19
-
20
  class ToolWrapper(BaseTool):
21
  """Wrapper for tools to make them compatible with CrewAI."""
22
 
@@ -31,7 +29,7 @@ class ToolWrapper(BaseTool):
31
  return await self.func(*args, **kwargs)
32
 
33
 
34
- # Define Agents - Corrected: Use ToolWrapper
35
  inventory_specialist = Agent(
36
  role="Inventory Specialist",
37
  goal="Identify the best matching homes from current inventory based on customer criteria.",
@@ -48,10 +46,10 @@ inventory_specialist = Agent(
48
  func=search_tool.run,
49
  description=search_tool.description,
50
  )
51
- ], # Corrected Tool Usage
52
  llm=ChatGoogleGenerativeAI(
53
- model="gemini-pro", temperature=0.7, convert_system_message_to_human=True
54
- ), # Use Gemini model
55
  )
56
 
57
  communication_specialist = Agent(
@@ -63,14 +61,14 @@ communication_specialist = Agent(
63
  You use persuasive language and a friendly tone to create a positive customer experience. You are a world-class copywriter.
64
  """,
65
  verbose=True,
66
- allow_delegation=True, # Allow delegation for potential follow-up tasks
67
  llm=ChatGoogleGenerativeAI(
68
- model="gemini-pro", temperature=0.7, convert_system_message_to_human=True
69
- ), # Use Gemini model
70
  )
71
 
72
 
73
- # Define Tasks - ADDED expected_output
74
  def create_inventory_task(customer_request):
75
  return Task(
76
  description=f"""Analyze the customer's request: '{customer_request}'.
@@ -80,7 +78,7 @@ def create_inventory_task(customer_request):
80
  Do NOT make up any information. If you don't find enough information, say so, but still provide the best possible matches based on what you *can* find.
81
  """,
82
  agent=inventory_specialist,
83
- expected_output="A list of 3-5 homes with their features and prices, or a message indicating no matches found.", # Added expected_output
84
  )
85
 
86
 
@@ -99,7 +97,7 @@ def create_communication_task(inventory_results):
99
  - Include a signature with contact information (e.g., name, title, phone number, email address). Use placeholder information for the signature (like "John Doe, Real Estate Agent, (555) 123-4567, [email protected]").
100
  """,
101
  agent=communication_specialist,
102
- expected_output="A complete, formatted email ready to be sent to the customer.", # Added expected_output
103
  )
104
 
105
 
@@ -128,14 +126,14 @@ if st.button("Submit Inquiry"):
128
  inventory_task = create_inventory_task(customer_request)
129
  communication_task = create_communication_task(
130
  inventory_task.output
131
- ) # Pass output for sequential execution
132
 
133
  # Create Crew
134
  real_estate_crew = Crew(
135
  agents=[inventory_specialist, communication_specialist],
136
  tasks=[inventory_task, communication_task],
137
- process=Process.sequential, # Important: Run tasks in sequence
138
- verbose=True, # Increase verbosity for debugging
139
  )
140
 
141
  # Run the Crew
@@ -143,7 +141,7 @@ if st.button("Submit Inquiry"):
143
  results = real_estate_crew.kickoff()
144
  st.success("Response generated!")
145
  st.write("**Draft Email Response:**")
146
- st.write(results) # Display the final output (email)
147
  st.balloons()
148
  except Exception as e:
149
  st.error(f"An error occurred: {e}")
 
4
  from langchain_google_genai import ChatGoogleGenerativeAI
5
  import os
6
  import google.generativeai as genai
7
+ from langchain.tools import BaseTool
8
 
9
 
10
+ # Configure Gemini API Key
 
11
  GOOGLE_API_KEY = st.secrets["GOOGLE_API_KEY"]
12
  genai.configure(api_key=GOOGLE_API_KEY)
13
 
14
 
15
+ # Define Tools
16
  search_tool = DuckDuckGoSearchRun()
17
 
 
18
  class ToolWrapper(BaseTool):
19
  """Wrapper for tools to make them compatible with CrewAI."""
20
 
 
29
  return await self.func(*args, **kwargs)
30
 
31
 
32
+ # Define Agents - Specify the 'provider' in ChatGoogleGenerativeAI
33
  inventory_specialist = Agent(
34
  role="Inventory Specialist",
35
  goal="Identify the best matching homes from current inventory based on customer criteria.",
 
46
  func=search_tool.run,
47
  description=search_tool.description,
48
  )
49
+ ],
50
  llm=ChatGoogleGenerativeAI(
51
+ model="gemini-pro", temperature=0.7, convert_system_message_to_human=True, client=genai
52
+ ), # Corrected: Pass genai client
53
  )
54
 
55
  communication_specialist = Agent(
 
61
  You use persuasive language and a friendly tone to create a positive customer experience. You are a world-class copywriter.
62
  """,
63
  verbose=True,
64
+ allow_delegation=True,
65
  llm=ChatGoogleGenerativeAI(
66
+ model="gemini-pro", temperature=0.7, convert_system_message_to_human=True, client=genai
67
+ ), # Corrected: Pass genai client
68
  )
69
 
70
 
71
+ # Define Tasks
72
  def create_inventory_task(customer_request):
73
  return Task(
74
  description=f"""Analyze the customer's request: '{customer_request}'.
 
78
  Do NOT make up any information. If you don't find enough information, say so, but still provide the best possible matches based on what you *can* find.
79
  """,
80
  agent=inventory_specialist,
81
+ expected_output="A list of 3-5 homes with their features and prices, or a message indicating no matches found.",
82
  )
83
 
84
 
 
97
  - Include a signature with contact information (e.g., name, title, phone number, email address). Use placeholder information for the signature (like "John Doe, Real Estate Agent, (555) 123-4567, [email protected]").
98
  """,
99
  agent=communication_specialist,
100
+ expected_output="A complete, formatted email ready to be sent to the customer.",
101
  )
102
 
103
 
 
126
  inventory_task = create_inventory_task(customer_request)
127
  communication_task = create_communication_task(
128
  inventory_task.output
129
+ )
130
 
131
  # Create Crew
132
  real_estate_crew = Crew(
133
  agents=[inventory_specialist, communication_specialist],
134
  tasks=[inventory_task, communication_task],
135
+ process=Process.sequential,
136
+ verbose=2,
137
  )
138
 
139
  # Run the Crew
 
141
  results = real_estate_crew.kickoff()
142
  st.success("Response generated!")
143
  st.write("**Draft Email Response:**")
144
+ st.write(results)
145
  st.balloons()
146
  except Exception as e:
147
  st.error(f"An error occurred: {e}")