rchrdgwr commited on
Commit
13c9bc6
1 Parent(s): 0460aec

change meddic call to return json response

Browse files
__pycache__/utils_opportunity_review.cpython-311.pyc CHANGED
Binary files a/__pycache__/utils_opportunity_review.cpython-311.pyc and b/__pycache__/utils_opportunity_review.cpython-311.pyc differ
 
__pycache__/utils_prep.cpython-311.pyc CHANGED
Binary files a/__pycache__/utils_prep.cpython-311.pyc and b/__pycache__/utils_prep.cpython-311.pyc differ
 
reports/HSBC Opportunity Review Report.md CHANGED
@@ -1,26 +1,25 @@
1
  **Analysis Results**
2
 
3
- **Summary:** The opportunity with HSBC involves offering a new analytics engine for their loan origination system, which is currently slow and inflexible. The urgency for decision-making stems from their upcoming renewal with the existing vendor. Multiple meetings have taken place, including an initial discovery call, a technical deep dive, and a proposal review, with HSBC expressing interest in moving forward. The next step involves further discussions with John Smith, the VP of Information Technology, to potentially proceed to a pilot program or final negotiations.
4
 
5
- **Score:** 75
6
 
7
  **MEDDIC Evaluation:**
8
 
9
- **Metrics:** 80
10
- **Evaluation:** John Smith appears to be a potential champion, given his active involvement. However, it is uncertain how strongly he advocates for the solution internally or if there are other champions within HSBC. Further development of internal champions may be needed.
11
- **Economic Buyer:** 70
12
- **Decision Criteria:** 75
13
- **Decision Process:** 70
14
- **Identify Pain:** 85
15
- **Champion:** 65
16
 
17
 
18
  **Next Steps**
19
 
20
- Schedule a meeting with John Smith to deepen the understanding of HSBC's decision-making process and to identify additional internal champions. Aim to set the groundwork for a pilot program or final negotiations.
21
 
22
  **Talking Points:**
23
 
24
- 1. **Reinforce the Value Proposition**: Highlight how the new analytics engine will enhance HSBC's loan origination system by improving speed and flexibility, directly addressing the current pain points
25
- 2. **Discuss the Timeline and Urgency**: Emphasize the importance of aligning with HSBC's renewal timeline to ensure a smooth transition from their existing vendor, and address any potential roadblocks in the decision-making process
26
- 3. **Identify and Develop Additional Champions**: Explore who else within HSBC might benefit from or support the new solution, and strategize on how to engage these stakeholders to strengthen internal advocacy
 
1
  **Analysis Results**
2
 
3
+ **Summary:** The opportunity involves replacing HSBC's current analytics system for their loan origination process with our more flexible and faster solution. The decision is time-sensitive due to an impending renewal with their existing vendor, and there has been strong engagement from key stakeholders, including the VP of IT and the CFO.
4
 
5
+ **Score:** 80
6
 
7
  **MEDDIC Evaluation:**
8
 
9
+ **Metrics:** 7 - The potential ROI and performance improvements were discussed, but specific quantified metrics on cost savings or efficiency gains were not detailed.
10
+ **Economic Buyer:** 8 - The involvement of the CFO in the proposal review suggests access to the economic buyer, but further direct engagement may be needed to solidify alignment.
11
+ **Decision Criteria:** 7 - HSBC is evaluating the proposal based on implementation scenarios and pricing structure, indicating some understanding of their decision criteria, but more clarity is needed.
12
+ **Decision Process:** 8 - HSBC has shown a structured decision-making process with multiple meetings and a review phase, but exact timelines and steps need more definition.
13
+ **Identify Pain:** 9 - The pain point of a slow and inflexible current system is well understood and articulated, with urgency due to contract renewal.
14
+ **Champion:** 8 - John Smith, the VP of IT, has been consistently involved and appears to be a strong advocate, but further validation of his influence in the final decision is necessary.
 
15
 
16
 
17
  **Next Steps**
18
 
19
+ Schedule a meeting with the CFO to directly address economic concerns and solidify alignment with the economic buyer, ensuring full understanding of the ROI and financial benefits of the proposed solution.
20
 
21
  **Talking Points:**
22
 
23
+ 1. Highlight the specific ROI and cost savings that HSBC can expect by switching to our analytics system, providing detailed metrics and case studies to illustrate the potential financial impact
24
+ 2. Discuss the clear advantages of our system in terms of flexibility and speed, emphasizing how these improvements directly address HSBC's current pain points and align with their decision criteria
25
+ 3. Outline a clear implementation plan with defined timelines and steps to reassure HSBC of a smooth transition process, addressing any concerns about the decision-making process and renewal urgency
utils_opportunity_review.py CHANGED
@@ -1,5 +1,6 @@
1
  import json
2
  import os
 
3
  from langchain.document_loaders import CSVLoader, PyPDFLoader, Docx2txtLoader
4
  from langgraph.graph import StateGraph, END
5
  from langchain.prompts import PromptTemplate
@@ -134,7 +135,8 @@ def agent_2() -> Dict[str, Any]:
134
 
135
  Assign an overall opportunity score (1-100) with 100 means that the opportunity is a sure win.
136
 
137
- Provide a Summary of the opportunity.
 
138
 
139
  Evaluate the opportunity based on each MEDDIC criterion and assign a score for each criterion:
140
  1. Metrics
@@ -168,10 +170,13 @@ def agent_2() -> Dict[str, Any]:
168
  else:
169
  raise ValueError(f"Unexpected response type: {type(response)}")
170
 
 
171
  # Parse the response content
172
  lines = response_content.split('\n')
173
  summary = next((line.split('Summary:')[1].strip() for line in lines if line.startswith('Summary:')), 'N/A')
 
174
  score = next((int(line.split('Score:')[1].strip()) for line in lines if line.startswith('Score:')), 0)
 
175
  meddic_eval = {}
176
  current_criterion = None
177
  for line in lines:
@@ -197,6 +202,108 @@ def agent_2() -> Dict[str, Any]:
197
  'meddic_evaluation': str(e)
198
  }
199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  def agent_3(meddic_evaluation: Dict[str, Any]) -> Dict[str, Any]:
201
  """Agent 3: Suggest next best action and talking points."""
202
  try:
@@ -250,7 +357,7 @@ def process_document(state: State) -> State:
250
 
251
  def evaluate_opportunity(state: State) -> State:
252
  print("Agent 2: Evaluating opportunity...")
253
- result = agent_2()
254
  return State(file_path=state.file_path, document_processed=state.document_processed, opportunity_evaluation=result)
255
 
256
  def suggest_next_action(state: State) -> State:
 
1
  import json
2
  import os
3
+ import re
4
  from langchain.document_loaders import CSVLoader, PyPDFLoader, Docx2txtLoader
5
  from langgraph.graph import StateGraph, END
6
  from langchain.prompts import PromptTemplate
 
135
 
136
  Assign an overall opportunity score (1-100) with 100 means that the opportunity is a sure win.
137
 
138
+ Provide a Summary of the opportunity. There must always be a summary. Ensure the summary is on the
139
+ same line as the Summary: title
140
 
141
  Evaluate the opportunity based on each MEDDIC criterion and assign a score for each criterion:
142
  1. Metrics
 
170
  else:
171
  raise ValueError(f"Unexpected response type: {type(response)}")
172
 
173
+ print(response_content)
174
  # Parse the response content
175
  lines = response_content.split('\n')
176
  summary = next((line.split('Summary:')[1].strip() for line in lines if line.startswith('Summary:')), 'N/A')
177
+ print(summary)
178
  score = next((int(line.split('Score:')[1].strip()) for line in lines if line.startswith('Score:')), 0)
179
+ print(score)
180
  meddic_eval = {}
181
  current_criterion = None
182
  for line in lines:
 
202
  'meddic_evaluation': str(e)
203
  }
204
 
205
+ def clean_and_parse_json(json_string):
206
+ # Remove triple backticks and "json" label if present
207
+ json_string = re.sub(r'^```json\s*', '', json_string)
208
+ json_string = re.sub(r'\s*```$', '', json_string)
209
+
210
+ # Remove any leading/trailing whitespace
211
+ json_string = json_string.strip()
212
+
213
+ # Parse the cleaned JSON string
214
+ try:
215
+ return json.loads(json_string)
216
+ except json.JSONDecodeError as e:
217
+ print(f"Error parsing JSON: {e}")
218
+ return None
219
+
220
+ def agent_2_json() -> Dict[str, Any]:
221
+ """Agent 2: Evaluate opportunity based on MEDDIC criteria."""
222
+ try:
223
+ results = qdrant.scroll(collection_name="opportunities", limit=100)
224
+ if not results or len(results[0]) == 0:
225
+ raise ValueError("No documents found in Qdrant")
226
+
227
+ full_text = " ".join([point.payload.get("text", "") for point in results[0]])
228
+
229
+ meddic_template = """
230
+ Analyze the following opportunity information using the MEDDIC sales methodology:
231
+
232
+ {opportunity_info}
233
+
234
+ Assign an overall opportunity score (1-100) with 100 means that the opportunity is a sure win.
235
+
236
+ Provide a Summary of the opportunity. There must always be a summary. Ensure the summary is on the
237
+ same line as the Summary: title
238
+
239
+ Evaluate the opportunity based on each MEDDIC criterion and assign a score for each criterion:
240
+ 1. Metrics
241
+ 2. Economic Buyer
242
+ 3. Decision Criteria
243
+ 4. Decision Process
244
+ 5. Identify Pain
245
+ 6. Champion
246
+
247
+ Your response must be in JSON format.
248
+ Use the following keys in the JSON:
249
+ Summary: Opportunity Summary
250
+ Score: Overall Opportunity Score between 1 to 100 based on MEDDIC criteria
251
+ Metrics Score: MEDDIC score on Metrics
252
+ Metrics Evaluation: Evaluation on MEDDIC Metrics criterion
253
+ Economic Buyer Score: MEDDIC Score on Economic Buyer
254
+ Economic Buyer Evaluation: Evaluation on MEDDIC Economic Buyer criterion
255
+ Decision Criteria Score: MEDDIC Score on Decision Criteria
256
+ Decision Criteria Evaluation: Evaluation on MEDDIC Decision Criteria criterion
257
+ Decision Process Score: MEDDIC Score on Decision Process
258
+ Decision Process Evaluation: Evaluation on MEDDIC Decision Process criterion
259
+ Identify Pain Score: MEDDIC Score on Identify Pain
260
+ Identify Pain Evaluation: Evaluation on MEDDIC Identify Pain criterion
261
+ Champion Score: MEDDIC Score on Champion
262
+ Champion Evaluation: Evaluation on MEDDIC Champion criterion
263
+ """
264
+
265
+ meddic_prompt = PromptTemplate(template=meddic_template, input_variables=["opportunity_info"])
266
+ meddic_chain = meddic_prompt | llm
267
+
268
+ response = meddic_chain.invoke({"opportunity_info": full_text})
269
+
270
+ if isinstance(response, AIMessage):
271
+ response_content = response.content
272
+ elif isinstance(response, str):
273
+ response_content = response
274
+ else:
275
+ raise ValueError(f"Unexpected response type: {type(response)}")
276
+
277
+ print(response_content)
278
+
279
+ meddic_data = clean_and_parse_json(response_content)
280
+ print("jsonified")
281
+ print(meddic_data)
282
+ # Create the output structure
283
+ output = {
284
+ 'summary': meddic_data.get('Summary', 'N/A'),
285
+ 'score': meddic_data.get('Score', 0),
286
+ 'meddic_evaluation': {
287
+ 'Metrics': f"{meddic_data.get('Metrics Score', 'N/A')} - {meddic_data.get('Metrics Evaluation', 'N/A')}",
288
+ 'Economic Buyer': f"{meddic_data.get('Economic Buyer Score', 'N/A')} - {meddic_data.get('Economic Buyer Evaluation', 'N/A')}",
289
+ 'Decision Criteria': f"{meddic_data.get('Decision Criteria Score', 'N/A')} - {meddic_data.get('Decision Criteria Evaluation', 'N/A')}",
290
+ 'Decision Process': f"{meddic_data.get('Decision Process Score', 'N/A')} - {meddic_data.get('Decision Process Evaluation', 'N/A')}",
291
+ 'Identify Pain': f"{meddic_data.get('Identify Pain Score', 'N/A')} - {meddic_data.get('Identify Pain Evaluation', 'N/A')}",
292
+ 'Champion': f"{meddic_data.get('Champion Score', 'N/A')} - {meddic_data.get('Champion Evaluation', 'N/A')}"
293
+ }
294
+ }
295
+ print("output")
296
+ print(output)
297
+ return output
298
+
299
+ except Exception as e:
300
+ print(f"Error in agent_2_json: {str(e)}")
301
+ return {
302
+ 'summary': "Error occurred during evaluation",
303
+ 'score': 0,
304
+ 'meddic_evaluation': str(e)
305
+ }
306
+
307
  def agent_3(meddic_evaluation: Dict[str, Any]) -> Dict[str, Any]:
308
  """Agent 3: Suggest next best action and talking points."""
309
  try:
 
357
 
358
  def evaluate_opportunity(state: State) -> State:
359
  print("Agent 2: Evaluating opportunity...")
360
+ result = agent_2_json()
361
  return State(file_path=state.file_path, document_processed=state.document_processed, opportunity_evaluation=result)
362
 
363
  def suggest_next_action(state: State) -> State:
utils_prep.py CHANGED
@@ -62,11 +62,11 @@ async def prep_opportunities(session_state):
62
  async def prep_opportunity_analysis():
63
 
64
  session_state = cl.user_session.get("session_state", None)
65
- opportunity_analysis_message = "Retrieving and Reviewing HSBC Opportunitiy - please wait..."
66
  await cl.Message(content=opportunity_analysis_message).send()
67
 
68
  if session_state.do_opportunity_analysis:
69
- agent_1_message = "*Retrieving and reviewing opportunity data from SalesForce CRM ...*"
70
  await cl.Message(content=agent_1_message).send()
71
  await prep_opportunity_review(session_state)
72
  report = session_state.opportunity_review_report
@@ -78,11 +78,11 @@ async def prep_opportunity_analysis():
78
  await asyncio.sleep(2)
79
 
80
  if session_state.add_objections_to_analysis:
81
- agent_3_message = "*Evaluating opportunity and identifying risks ...*"
82
  await cl.Message(content=agent_3_message).send()
83
  session_state.objections = await create_objections(session_state)
84
  else:
85
- agent_2_message = "*Evaluating opportunity ...*"
86
  await cl.Message(content=agent_2_message).send()
87
  await asyncio.sleep(1.5)
88
 
 
62
  async def prep_opportunity_analysis():
63
 
64
  session_state = cl.user_session.get("session_state", None)
65
+ opportunity_analysis_message = "Reviewing HSBC Opportunitiy - please wait..."
66
  await cl.Message(content=opportunity_analysis_message).send()
67
 
68
  if session_state.do_opportunity_analysis:
69
+ agent_1_message = "*Retrieving and evaluating opportunity data from SalesForce CRM ...*"
70
  await cl.Message(content=agent_1_message).send()
71
  await prep_opportunity_review(session_state)
72
  report = session_state.opportunity_review_report
 
78
  await asyncio.sleep(2)
79
 
80
  if session_state.add_objections_to_analysis:
81
+ agent_3_message = "*Evaluating opportunity data and identifying risks ...*"
82
  await cl.Message(content=agent_3_message).send()
83
  session_state.objections = await create_objections(session_state)
84
  else:
85
+ agent_2_message = "*Evaluating opportunity data...*"
86
  await cl.Message(content=agent_2_message).send()
87
  await asyncio.sleep(1.5)
88