Skip to content

Commit

Permalink
feat: make timeout for inferencing calls configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratyush Singh committed Oct 9, 2023
1 parent d10cad8 commit 53f049e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion assistant_skill_analysis/inferencing/inferencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def inference(
assistant_id=None,
skill_id=None,
intent_to_action_mapping=None,
timeout=1
):
"""
query the message api to generate results on the test data
Expand Down Expand Up @@ -115,6 +116,7 @@ def inference(
skill_id=skill_id,
assistant_id=assistant_id,
intent_to_action_mapping=intent_to_action_mapping,
timeout=timeout
)
return result_df

Expand All @@ -127,6 +129,7 @@ def thread_inference(
assistant_id=None,
skill_id=None,
intent_to_action_mapping=None,
timeout=1
):
"""
Perform multi thread inference for faster inference time
Expand Down Expand Up @@ -179,7 +182,7 @@ def thread_inference(
futures[future] = (test_example, ground_truth)

for future in tqdm(futures):
res = future.result(timeout=1)
res = future.result(timeout=timeout)
test_example, ground_truth = futures[future]
result.append(
process_result(
Expand Down
12 changes: 9 additions & 3 deletions new_experience_skill_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -606,12 +606,15 @@
"outputs": [],
"source": [
"THREAD_NUM = min(4, os.cpu_count() if os.cpu_count() else 1)\n",
"\n",
"# increase timeout if you experience `TimeoutError`. \n",
"# Increasing the `TIMEOUT` allows the process more breathing room to compete\n",
"TIMEOUT = 1 \n",
"full_results = inferencer.inference(conversation,\n",
" test_df,\n",
" max_thread=THREAD_NUM, \n",
" assistant_id=ASSISTANT_ID,\n",
" intent_to_action_mapping=intent_to_action_mapping\n",
" intent_to_action_mapping=intent_to_action_mapping,\n",
" timeout=TIMEOUT\n",
" )"
]
},
Expand Down Expand Up @@ -782,13 +785,16 @@
"utterance = \"what can i do to talk to someone\" # input example\n",
"intent = \"Schedule An Appointment\" # input an intent in your workspace which you are interested in.\n",
"\n",
"\n",
"# increase timeout if you experience `TimeoutError`. \n",
"# Increasing the `TIMEOUT` allows the process more breathing room to compete\n",
"TIMEOUT = 1 \n",
"inference_results = inferencer.inference(conversation=conversation, \n",
" test_data=pd.DataFrame({'utterance':[utterance], \n",
" 'intent':[intent]}), \n",
" max_thread = 1, \n",
" assistant_id=ASSISTANT_ID,\n",
" intent_to_action_mapping=intent_to_action_mapping,\n",
" timeout=TIMEOUT\n",
" )\n",
"\n",
"highlighter.get_highlights_in_batch_multi_thread(conversation=conversation, \n",
Expand Down

0 comments on commit 53f049e

Please sign in to comment.