return failure reason to front-end

This commit is contained in:
Abi Raja 2023-12-06 10:50:22 -05:00
parent 0698af8434
commit f0101036a0
2 changed files with 4 additions and 9 deletions

View File

@ -18,10 +18,4 @@ async def validate_access_token(access_code: str):
response = await client.post(url, content=data, headers=headers)
response_data = response.json()
if response_data["success"]:
print("Access token is valid.")
return True
else:
print(f"Access token validation failed: {response_data['failure_reason']}")
return False
return response_data

View File

@ -97,13 +97,14 @@ async def stream_code(websocket: WebSocket):
openai_api_key = None
if "accessCode" in params and params["accessCode"]:
print("Access code - using platform API key")
if await validate_access_token(params["accessCode"]):
res = await validate_access_token(params["accessCode"])
if res["success"]:
openai_api_key = os.environ.get("PLATFORM_OPENAI_API_KEY")
else:
await websocket.send_json(
{
"type": "error",
"value": "Invalid access code or you're out of credits. Please try again.",
"value": res["failure_reason"],
}
)
return