Skip to content

Commit 3fc5c1a

Browse files
committed
fix: pass environment id when calling assistant message_stateless endpoint
1 parent 3172999 commit 3fc5c1a

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

assistant_skill_analysis/highlighting/highlighter.py

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def get_highlights_in_batch_multi_thread(
2626
skill_id=None,
2727
assistant_id=None,
2828
intent_to_action_mapping=None,
29+
environment_id=None,
2930
):
3031
"""
3132
Given the prediction result, rank prediction results from worst to best
@@ -39,6 +40,7 @@ def get_highlights_in_batch_multi_thread(
3940
:param show_worst_k: the top worst k results based on heuristics
4041
:param assistant_id:
4142
:param intent_to_action_mapping:
43+
:param environment_id: the environment id
4244
:return:
4345
"""
4446
if isinstance(conversation, ibm_watson.AssistantV1):
@@ -68,6 +70,7 @@ def get_highlights_in_batch_multi_thread(
6870
skill_id=skill_id,
6971
assistant_id=assistant_id,
7072
intent_to_action_mapping=intent_to_action_mapping,
73+
environment_id=environment_id,
7174
)
7275

7376
if not adversarial_results.empty:
@@ -253,6 +256,7 @@ def _adversarial_examples_multi_thread_inference(
253256
skill_id=None,
254257
assistant_id=None,
255258
intent_to_action_mapping=None,
259+
environment_id=None,
256260
):
257261
"""
258262
Perform multi threaded inference on all the adversarial examples
@@ -261,6 +265,7 @@ def _adversarial_examples_multi_thread_inference(
261265
:param skill_id:
262266
:param assistant_id:
263267
:param intent_to_action_mapping:
268+
:param environment_id:
264269
"""
265270
if isinstance(conversation, ibm_watson.AssistantV1):
266271
assert skill_id is not None
@@ -299,6 +304,7 @@ def _adversarial_examples_multi_thread_inference(
299304
skill_id=skill_id,
300305
assistant_id=assistant_id,
301306
intent_to_action_mapping=intent_to_action_mapping,
307+
environment_id=environment_id,
302308
)
303309
display(Markdown(" "))
304310
return adversarial_results, adversarial_span_dict

assistant_skill_analysis/inferencing/inferencer.py

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def inference(
1818
skill_id=None,
1919
intent_to_action_mapping=None,
2020
timeout=1,
21+
environment_id=None,
2122
):
2223
"""
2324
query the message api to generate results on the test data
@@ -29,6 +30,7 @@ def inference(
2930
:parameter: assistant_id:
3031
:parameter: intent_to_action_mapping:
3132
:parameter: timeout: integer or float that specifies number of seconds each thread should wait for inference result
33+
:parameter: environment_id: environment id
3234
:return result_df: results dataframe
3335
"""
3436
skd_version = "V1"
@@ -54,6 +56,7 @@ def inference(
5456
user_id=user_id,
5557
assistant_id=assistant_id,
5658
skill_id=skill_id,
59+
environment_id=environment_id,
5760
)
5861
time.sleep(0.3)
5962

@@ -118,6 +121,7 @@ def inference(
118121
assistant_id=assistant_id,
119122
intent_to_action_mapping=intent_to_action_mapping,
120123
timeout=timeout,
124+
environment_id=environment_id,
121125
)
122126
return result_df
123127

@@ -131,6 +135,7 @@ def thread_inference(
131135
skill_id=None,
132136
intent_to_action_mapping=None,
133137
timeout=1,
138+
environment_id=None,
134139
):
135140
"""
136141
Perform multi thread inference for faster inference time
@@ -143,6 +148,7 @@ def thread_inference(
143148
:param assistant_id:
144149
:parameter: intent_to_action_mapping:
145150
:parameter: timeout: integer or float that specifies number of seconds each thread should wait for inference result
151+
:parameter: environment_id: environment id
146152
:return result_df: results dataframe
147153
"""
148154
if isinstance(conversation, ibm_watson.AssistantV1):
@@ -162,6 +168,7 @@ def thread_inference(
162168
user_id=user_id,
163169
assistant_id=assistant_id,
164170
skill_id=skill_id,
171+
environment_id=environment_id,
165172
)
166173
except Exception:
167174
count += 1
@@ -179,6 +186,7 @@ def thread_inference(
179186
user_id=user_id,
180187
assistant_id=assistant_id,
181188
skill_id=skill_id,
189+
environment_id=environment_id,
182190
retry=0,
183191
)
184192
futures[future] = (test_example, ground_truth)
@@ -248,6 +256,7 @@ def get_intent_confidence_retry(
248256
user_id,
249257
assistant_id,
250258
skill_id,
259+
environment_id,
251260
retry=0,
252261
):
253262
try:
@@ -258,6 +267,7 @@ def get_intent_confidence_retry(
258267
user_id=user_id,
259268
assistant_id=assistant_id,
260269
skill_id=skill_id,
270+
environment_id=environment_id,
261271
)
262272
except Exception as e:
263273
if retry < MAX_RETRY:
@@ -268,6 +278,7 @@ def get_intent_confidence_retry(
268278
user_id,
269279
assistant_id,
270280
skill_id,
281+
environment_id=environment_id,
271282
retry=retry + 1,
272283
)
273284
else:

assistant_skill_analysis/utils/skills_util.py

+3
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ def retrieve_classifier_response(
453453
user_id="256",
454454
assistant_id=None,
455455
skill_id=None,
456+
environment_id=None,
456457
):
457458
"""
458459
retrieve classifier response
@@ -462,6 +463,7 @@ def retrieve_classifier_response(
462463
:param alternate_intents:
463464
:param user_id:
464465
:param assistant_id:
466+
:param environment_id: environment id
465467
:return response:
466468
"""
467469
if isinstance(conversation, ibm_watson.AssistantV1):
@@ -482,5 +484,6 @@ def retrieve_classifier_response(
482484
},
483485
context={"metadata": {"user_id": user_id}},
484486
assistant_id=assistant_id,
487+
environment_id=environment_id,
485488
).get_result()
486489
return response

new_experience_skill_analysis.ipynb

+8-2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@
114114
"\n",
115115
"iam_apikey, _, ASSISTANT_ID = skills_util.input_credentials(input_apikey=True,input_skill_id=False,input_assistant_id=True)\n",
116116
"\n",
117+
"ENVIRONMENT_ID = ASSISTANT_ID\n",
118+
"\n",
117119
"# If you do not have IAM based API Keys\n",
118120
"# but have access to a Username, Password\n",
119121
"# You can use username and password for authentication purpose and comment out iam_apikey\n",
@@ -614,7 +616,8 @@
614616
" max_thread=THREAD_NUM, \n",
615617
" assistant_id=ASSISTANT_ID,\n",
616618
" intent_to_action_mapping=intent_to_action_mapping,\n",
617-
" timeout=TIMEOUT\n",
619+
" timeout=TIMEOUT,\n",
620+
" environment_id=ENVIRONMENT_ID,\n",
618621
" )"
619622
]
620623
},
@@ -794,7 +797,8 @@
794797
" max_thread = 1, \n",
795798
" assistant_id=ASSISTANT_ID,\n",
796799
" intent_to_action_mapping=intent_to_action_mapping,\n",
797-
" timeout=TIMEOUT\n",
800+
" timeout=TIMEOUT,\n",
801+
" environment_id=ENVIRONMENT_ID,\n",
798802
" )\n",
799803
"\n",
800804
"highlighter.get_highlights_in_batch_multi_thread(conversation=conversation, \n",
@@ -805,6 +809,7 @@
805809
" lang_util=lang_util,\n",
806810
" assistant_id=ASSISTANT_ID,\n",
807811
" intent_to_action_mapping=intent_to_action_mapping,\n",
812+
" environment_id=ENVIRONMENT_ID,\n",
808813
" )"
809814
]
810815
},
@@ -847,6 +852,7 @@
847852
" lang_util=lang_util,\n",
848853
" assistant_id=ASSISTANT_ID,\n",
849854
" intent_to_action_mapping=intent_to_action_mapping,\n",
855+
" environment_id=ENVIRONMENT_ID,\n",
850856
" )"
851857
]
852858
},

0 commit comments

Comments
 (0)