From bbeaa929041d46c59694798899a13ace46039cd2 Mon Sep 17 00:00:00 2001 From: Sakkus Date: Mon, 26 Feb 2024 12:25:08 +0000 Subject: [PATCH 1/2] Fix OpenAI integration: from docker on mac get errors since num_ctx not recognized; remove num_ctx from, and max_tokens to, body in API calls. --- backend/apps/openai/main.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/apps/openai/main.py b/backend/apps/openai/main.py index 36326430..5612e7dc 100644 --- a/backend/apps/openai/main.py +++ b/backend/apps/openai/main.py @@ -146,6 +146,15 @@ async def proxy(path: str, request: Request, user=Depends(get_verified_user)): body["max_tokens"] = 4000 print("Modified body_dict:", body) + # Fix for ChatGPT calls failing because the num_ctx key is in body + if 'num_ctx' in body: + # If 'num_ctx' is in the dictionary, delete it + # Leaving it there generates an error with the + # OpenAI API (Feb 2024) + del body['num_ctx'] + # OpenAI API (Feb 2024) accepts max_tokens + body["max_tokens"] = 1600 + # Convert the modified body back to JSON body = json.dumps(body) except json.JSONDecodeError as e: From 781be2779bb6a20d719f8134a6b17a994358c51b Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 27 Feb 2024 20:02:23 -0800 Subject: [PATCH 2/2] refac: unnecessary max_token value removed --- backend/apps/openai/main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/backend/apps/openai/main.py b/backend/apps/openai/main.py index 5612e7dc..172332b9 100644 --- a/backend/apps/openai/main.py +++ b/backend/apps/openai/main.py @@ -147,13 +147,11 @@ async def proxy(path: str, request: Request, user=Depends(get_verified_user)): print("Modified body_dict:", body) # Fix for ChatGPT calls failing because the num_ctx key is in body - if 'num_ctx' in body: + if "num_ctx" in body: # If 'num_ctx' is in the dictionary, delete it # Leaving it there generates an error with the # OpenAI API (Feb 2024) - del body['num_ctx'] - # OpenAI API (Feb 2024) accepts max_tokens - body["max_tokens"] = 1600 + del body["num_ctx"] # Convert the modified body back to JSON body = json.dumps(body)