@@ -87,11 +87,28 @@ def set_generative_ai_keys(self, genai_api_key):
8787
8888 Args:
8989 genai_api_key: GenAI API key
90+
91+ Returns:
92+ None
9093 """
9194 assert isinstance (genai_api_key , str ), f'Argument "api_key" should be a string'
9295 self .api .set_genai_api_key (genai_api_key )
9396
9497 def get_genai_response_pooling (self , no_of_tries , user_prompt = None , chat_gpt_model = None ):
98+ """
99+ Method to get GenAI response
100+
101+ During first execution get_genai_response API is fired and for next consecutive calls handle_genai_response_timeout API is fired
102+ till we get a response other than AlgoBullsAPIGatewayTimeoutErrorException or GENAI_RESPONSE_POOLING_LIMIT is reached.
103+
104+ Args:
105+ no_of_tries: No of times this function is called recursively
106+ user_prompt: User question
107+ chat_gpt_model: OpenAI chat model name
108+
109+ Returns:
110+ GenAI response
111+ """
95112 if no_of_tries < GENAI_RESPONSE_POOLING_LIMIT :
96113 try :
97114 if no_of_tries > 1 :
@@ -107,7 +124,7 @@ def get_genai_response_pooling(self, no_of_tries, user_prompt=None, chat_gpt_mod
107124
108125 def display_genai_sessions (self ):
109126 """
110- display previous sessions
127+ Display previous sessions
111128 Returns:
112129 available sessions
113130 """
@@ -122,6 +139,12 @@ def display_genai_sessions(self):
122139 return customer_genai_sessions
123140
124141 def continue_from_previous_sessions (self ):
142+ """
143+ Let user select from displayed sessions
144+
145+ Returns:
146+ None
147+ """
125148 customer_genai_sessions = self .display_genai_sessions ()
126149 while True :
127150 user_input = int (input ("Enter session number" ))
@@ -136,6 +159,15 @@ def continue_from_previous_sessions(self):
136159 print ("Please select a valid session number." )
137160
138161 def display_session_chat_history (self , session_id ):
162+ """
163+ Display Chat history for given session
164+
165+ Args:
166+ session_id: session id
167+
168+ Returns:
169+ None
170+ """
139171 if not self .api .genai_sessions_map :
140172 self .api .get_genai_sessions ()
141173
@@ -148,6 +180,26 @@ def display_session_chat_history(self, session_id):
148180 print (f"No available chat history for session id: { session_id } " )
149181
150182 def start_chat (self , start_fresh = None , session_id = None , chat_gpt_model = None ):
183+ """
184+ Start chat with GenAI
185+
186+ If start_fresh is True -
187+ New session is started
188+ If start_fresh is False -
189+ If session_id is None
190+ All available sessions are displayed and user is can select from available sessions.
191+ If session_id is given
192+ Session linked with given session id is used
193+
194+ Args:
195+ start_fresh: strategy name
196+ session_id: strategy python code
197+ chat_gpt_model: OpenAI chat model name
198+
199+ Returns:
200+ None
201+ """
202+
151203 response = self .api .get_genai_api_key_status ()
152204 assert response ['key_available' ], f"Please set your GenAI key using set_generative_ai_keys()"
153205
@@ -187,6 +239,23 @@ def start_chat(self, start_fresh=None, session_id=None, chat_gpt_model=None):
187239 print (f"\n GenAI: { response ['message' ]} " , end = f"\n \n { '-' * 50 } \n \n " )
188240
189241 def save_last_generated_strategy (self , strategy_name = None , strategy_code = None ):
242+ """
243+ Method to save last generated genai response as strategy
244+
245+ User can either pass strategy code as a parameter our use last saved genai response to save strategy.
246+
247+ All strategies are unique by name, per customer.
248+ If customer tries to upload strategy with the same name as an already existing strategy
249+ - AlgoBullsAPIBadRequest Exception will be thrown. No change would be done in the backend database.
250+
251+ Args:
252+ strategy_name: strategy name
253+ strategy_code: strategy python code
254+
255+ Returns:
256+ Dictionary containing strategy name, strategy_id and cstc_id
257+ """
258+
190259 if self .recent_genai_response or strategy_code :
191260 strategy_name = strategy_name or f'GenAI Strategy-{ time .time ():.0f} '
192261 strategy_details = strategy_code or self .recent_genai_response
0 commit comments