File size: 4,352 Bytes
7781557
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import asyncio
import chainlit as cl
from datetime import datetime
from .utils_data import  get_company_data, get_opportunities, get_questions, get_customer_background
from .utils_output import display_evaluation_results, display_llm_responses
from .utils_objections import create_objections
# async def callback_show_scenarios():
#     scenarios = get_opportunities()
#     cl.user_session.set("scenarios", scenarios)
#     scenarios = cl.user_session.get("scenarios", None)
#     if scenarios is None:
#         await cl.Message(content="No scenarios found.").send()
#         return
    
#     scenario_actions = []
#     for idx, row in scenarios.iterrows():
#         if row['Opportunity Description'] != "":
#             scenario_action = cl.Action(
#                 name="Scenario",
#                 value=f"{idx}",  # Send the row index as value
#                 description=f"{row['Customer Name']}: {row['Opportunity Name']} ({row['Opportunity Stage']}) "
#                             f"Value: {row['Opportunity Value']}. Meeting with {row['Customer Contact']} "
#                             f"({row['Customer Contact Role']})"
#             )
#             scenario_actions.append(scenario_action)
#     await cl.Message(content="Select a scenario (hover for details):", actions=scenario_actions).send()


async def callback_run_scenario(action):
    await cl.Message(content="*Preparing simulation - please wait ...*").send()
    index = 0
    opportunities = cl.user_session.get("opportunities", None)
    if opportunities is None:
        await cl.Message(content="No scenarios found.").send()
        return
    await cl.Message(content="*Gathering opportunity information ...*").send()
    await asyncio.sleep(1) 

    await cl.Message(content="*Customizing questions for this opportunity ...*").send()  
    await asyncio.sleep(1)

    selected_opportunity = opportunities.iloc[index]
    session_state = cl.user_session.get("session_state", None)
    session_state.add_scenario_info(selected_opportunity) 
    get_customer_background(session_state, selected_opportunity['Customer Name'])
    if session_state.ask_objections:
        print("creating objections")
        session_state.objections = await create_objections(session_state)
        questions = []
        for obj in session_state.objections:
            print(obj)
            q = {"stage": session_state.opportunity.stage, "question": obj[3:], "ground_truth": ""}
            questions.append(q)
        session_state.questions = questions
    else:
        print("questions created")
        session_state.questions = get_questions(session_state.opportunity.stage, session_state.num_questions)
    for q in session_state.questions:
        print(q)
    opening_message = session_state.get_opening()  
    await cl.Message(content=opening_message).send()
    start_actions = [
        cl.Action(name="Start Simulation", value="start_simulation", description="Start Simulation"),
    ]
    await cl.Message(content="Click to start simulation", actions=start_actions).send()

async def callback_start_scenario():
    print("callback_start_scenario()")
    session_state = cl.user_session.get("session_state", None)
    await cl.Message(content="3...").send()
    await asyncio.sleep(1)
    await cl.Message(content="2...").send()
    await asyncio.sleep(1)
    await cl.Message(content="1...").send()
    await asyncio.sleep(1)
    await cl.Message(content="**Simulation Starting**").send()
    await cl.Message(content="\n\n").send()
    start_time = datetime.now()
    print("setting start time")
    session_state.start_time = start_time
    output = f"{session_state.customer.contact_name} joins the zoom call"
    print(output)
    await cl.Message(content=output).send()
    await cl.Message(content="\n\n").send()

async def callback_evaluate_performance():
    session_state = cl.user_session.get("session_state", None)
    if session_state is None:
        await cl.Message(content="No session found.").send()
        return  
    await display_evaluation_results(cl, session_state)

async def callback_display_queries_responses():
    session_state = cl.user_session.get("session_state", None)
    if session_state is None:
        await cl.Message(content="No session found.").send()
        return  
    await display_llm_responses(cl, session_state)