From fa4b5c842ef6772bdef07586d2961a2b0f317878 Mon Sep 17 00:00:00 2001 From: Senko Rasic Date: Sun, 10 Mar 2024 23:09:08 +0100 Subject: [PATCH 1/2] show more information on key expired error --- pilot/utils/llm_connection.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pilot/utils/llm_connection.py b/pilot/utils/llm_connection.py index c358958847..157e038159 100644 --- a/pilot/utils/llm_connection.py +++ b/pilot/utils/llm_connection.py @@ -442,7 +442,12 @@ def stream_gpt_completion(data, req_type, project): if response.status_code == 401 and 'BricksLLM' in response.text: print("", type='keyExpired') - raise ApiError("Trial Expired", response=response) + msg = "Trial Expired" + key = os.getenv("OPENAI_API_KEY") + if key: + msg += f" (using key ending in ...{key[-4:]}):" + msg += f"Error details: {response.text}" + raise ApiError(msg, response=response) if response.status_code != 200: project.dot_pilot_gpt.log_chat_completion(endpoint, model, req_type, data['messages'], response.text) From 3a8e7321a8f37f71d21a1b4ec7eb0aa2a11e68e7 Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Sun, 10 Mar 2024 18:16:20 -0700 Subject: [PATCH 2/2] add logging endpoint when getting 401 from bricks --- pilot/utils/llm_connection.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pilot/utils/llm_connection.py b/pilot/utils/llm_connection.py index 157e038159..e0cfe21afb 100644 --- a/pilot/utils/llm_connection.py +++ b/pilot/utils/llm_connection.py @@ -444,9 +444,12 @@ def stream_gpt_completion(data, req_type, project): print("", type='keyExpired') msg = "Trial Expired" key = os.getenv("OPENAI_API_KEY") + endpoint = os.getenv("OPENAI_ENDPOINT") if key: - msg += f" (using key ending in ...{key[-4:]}):" - msg += f"Error details: {response.text}" + msg += f"\n\n(using key ending in ...{key[-4:]}):" + if endpoint: + msg += f"\n(using endpoint: {endpoint}):" + msg += f"\n\nError details: {response.text}" raise ApiError(msg, response=response) if response.status_code != 200: