mirror of
https://github.com/TheR1D/shell_gpt.git
synced 2026-07-03 14:10:18 +02:00
Handle API authenticating response (#395)
This commit is contained in:
+8
-1
@@ -3,9 +3,10 @@ from pathlib import Path
|
||||
from typing import Dict, Generator, List
|
||||
|
||||
import requests
|
||||
import typer
|
||||
|
||||
from .cache import Cache
|
||||
from .config import cfg
|
||||
from .config import SHELL_GPT_CONFIG_PATH, cfg
|
||||
|
||||
CACHE_LENGTH = int(cfg.get("CACHE_LENGTH"))
|
||||
CACHE_PATH = Path(cfg.get("CACHE_PATH"))
|
||||
@@ -58,6 +59,12 @@ class OpenAIClient:
|
||||
timeout=REQUEST_TIMEOUT,
|
||||
stream=stream,
|
||||
)
|
||||
# Check if OPENAI_API_KEY is valid
|
||||
if response.status_code == 401 or response.status_code == 403:
|
||||
typer.secho(
|
||||
f"Invalid OpenAI API key, update your config file: {SHELL_GPT_CONFIG_PATH}",
|
||||
fg="red",
|
||||
)
|
||||
response.raise_for_status()
|
||||
# TODO: Optimise.
|
||||
# https://github.com/openai/openai-python/blob/237448dc072a2c062698da3f9f512fae38300c1c/openai/api_requestor.py#L98
|
||||
|
||||
Reference in New Issue
Block a user