Skip to content

Commit

Permalink
add error logs for openaiapi
Browse files Browse the repository at this point in the history
  • Loading branch information
lakhoune committed Nov 18, 2023
1 parent 57bc418 commit 1efcf50
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions bot_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,16 @@ def get_improvements_for_dfg(botName):
prompt = llm.recommendations_from_event_log(event_log)
# log the prompt
current_app.logger.info(prompt)
content = llm.send_prompt(prompt, api_key, openai_model)
current_app.logger.info(content)
return content
try:
content = llm.send_prompt(prompt, api_key, openai_model)
current_app.logger.info(content)
return content
except Exception as e:
current_app.logger.error(e)
return {
"error": "Could not send prompt to OpenAI",
"message": e
}, e.status_code if hasattr(e, 'status_code') else 500


@bot_resource.route('/<botName>/llm/intent-improvements', methods=['POST'])
Expand All @@ -301,9 +308,16 @@ def get_improvements_for_intents(botName):
botName, current_app.db_connection)
prompt = llm.recommendations_for_intents(average_intent_confidence_df)
current_app.logger.info(prompt)
content = llm.send_prompt(prompt, api_key, openai_model)
current_app.logger.info(content)
return content
try:
content = llm.send_prompt(prompt, api_key, openai_model)
current_app.logger.info(content)
return content
except Exception as e:
current_app.logger.error(e)
return {
"error": "Could not send prompt to OpenAI",
"message": e
}, e.status_code if hasattr(e, 'status_code') else 500


@bot_resource.route('/<botName>/llm/custom-prompt', methods=['POST'])
Expand Down Expand Up @@ -355,9 +369,16 @@ def get_custom_improvements(botName):
prompt = llm.custom_prompt(inputPrompt, average_intent_confidence_df,
event_log, net, initial_marking, final_marking)
current_app.logger.info(prompt)
content = llm.send_prompt(prompt, api_key, openai_model)
current_app.logger.info(content)
return content
try:
content = llm.send_prompt(prompt, api_key, openai_model)
current_app.logger.info(content)
return content
except Exception as e:
current_app.logger.error(e)
return {
"error": "Could not send prompt to OpenAI",
"message": e
}, e.status_code if hasattr(e, 'status_code') else 500


@bot_resource.route('/<botName>/llm/describe', methods=['POST'])
Expand Down

0 comments on commit 1efcf50

Please sign in to comment.