@@ -90,15 +90,54 @@ def set_generative_ai_keys(self, api_key, secret_key, token_key):
9090 # todo: learn about different generative AIs and how many and what keys are required ?
9191 # also confirm with backend the format of API keys to be received
9292 """
93-
93+ assert isinstance (api_key , str ), f'Argument "api_key" should be a string'
94+ self .api .openai_key = api_key
9495 return 'SUCCESS' or 'FAILURE'
9596
96- def generate_strategy (self ):
97- input_prompt = str (input ())
97+ def start_chat (self , chat_gpt_model ):
98+ while True :
99+ user_prompt = str (input ())
100+ if user_prompt .lower () == 'exit' :
101+ print ("Thanks for the chat" )
102+ return
103+
104+ response = self .api .get_genai (user_prompt , chat_gpt_model )
105+ while response ['status_code' ] == 504 :
106+ response = self .api .get_genai_response ()
107+
108+ print (f"GenAI: { response ['message' ]} " )
109+
110+ def continue_from_previous_session (self , page_no ):
111+ """
112+ display previous sessions
113+ Returns:
98114
99- # call the api
115+ """
116+ customer_genai_sessions = self .api .get_genai_sessions (page_no )
117+ for i , session in enumerate (customer_genai_sessions ):
118+ print (f"Session { i } : ID: { session ['id' ]} , Started: { session ['last_user_prompt' ]} " )
100119
101- return # strategy in strings
120+ if len (customer_genai_sessions ) < 20 :
121+ print ("End" )
122+ else :
123+ print (f"Type 'next' to view the next 20 sessions." )
124+
125+ user_input = input ("Enter session number or 'next': " )
126+ if user_input .lower () == "next" and len (customer_genai_sessions ) > 20 :
127+ self .continue_from_previous_session (page_no = page_no + 1 )
128+ elif user_input .isdigit () and 1 <= int (user_input ) <= len (customer_genai_sessions ):
129+ selected_session_index = page_no + int (user_input ) - 1
130+ selected_session_id = customer_genai_sessions [selected_session_index ]["id" ]
131+ self .api .genai_api_key = selected_session_id
132+
133+ def initiate_chat (self , start_fresh = None , chat_gpt_model = None ):
134+ if start_fresh :
135+ # reset session
136+ self .api .genai_api_key = None
137+ elif start_fresh is not None :
138+ self .continue_from_previous_session (page_no = 1 )
139+
140+ self .start_chat (chat_gpt_model )
102141
103142 def save_latest_generated_strategy (self ):
104143 pass
0 commit comments