@@ -87,11 +87,28 @@ def set_generative_ai_keys(self, genai_api_key):
87
87
88
88
Args:
89
89
genai_api_key: GenAI API key
90
+
91
+ Returns:
92
+ None
90
93
"""
91
94
assert isinstance (genai_api_key , str ), f'Argument "api_key" should be a string'
92
95
self .api .set_genai_api_key (genai_api_key )
93
96
94
97
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
+ """
95
112
if no_of_tries < GENAI_RESPONSE_POOLING_LIMIT :
96
113
try :
97
114
if no_of_tries > 1 :
@@ -107,7 +124,7 @@ def get_genai_response_pooling(self, no_of_tries, user_prompt=None, chat_gpt_mod
107
124
108
125
def display_genai_sessions (self ):
109
126
"""
110
- display previous sessions
127
+ Display previous sessions
111
128
Returns:
112
129
available sessions
113
130
"""
@@ -122,6 +139,12 @@ def display_genai_sessions(self):
122
139
return customer_genai_sessions
123
140
124
141
def continue_from_previous_sessions (self ):
142
+ """
143
+ Let user select from displayed sessions
144
+
145
+ Returns:
146
+ None
147
+ """
125
148
customer_genai_sessions = self .display_genai_sessions ()
126
149
while True :
127
150
user_input = int (input ("Enter session number" ))
@@ -136,6 +159,15 @@ def continue_from_previous_sessions(self):
136
159
print ("Please select a valid session number." )
137
160
138
161
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
+ """
139
171
if not self .api .genai_sessions_map :
140
172
self .api .get_genai_sessions ()
141
173
@@ -148,6 +180,26 @@ def display_session_chat_history(self, session_id):
148
180
print (f"No available chat history for session id: { session_id } " )
149
181
150
182
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
+
151
203
response = self .api .get_genai_api_key_status ()
152
204
assert response ['key_available' ], f"Please set your GenAI key using set_generative_ai_keys()"
153
205
@@ -187,6 +239,23 @@ def start_chat(self, start_fresh=None, session_id=None, chat_gpt_model=None):
187
239
print (f"\n GenAI: { response ['message' ]} " , end = f"\n \n { '-' * 50 } \n \n " )
188
240
189
241
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
+
190
259
if self .recent_genai_response or strategy_code :
191
260
strategy_name = strategy_name or f'GenAI Strategy-{ time .time ():.0f} '
192
261
strategy_details = strategy_code or self .recent_genai_response
0 commit comments