cortex.cpp icon indicating copy to clipboard operation
cortex.cpp copied to clipboard

feat: [Add Response Code to Nitro REST API for Localization Support]

Open hahuyhoang411 opened this issue 1 year ago • 2 comments

Current Behavior

{"message":"Model unloaded successfully"}
{"message":"No model loaded"}

Expected Behavior

{"message":"Model unloaded successfully", "code": "ModelUnloadedSuccessfully"}
{"message":"No model loaded", "code": "NoModelLoaded"}

hahuyhoang411 avatar Nov 14 '23 07:11 hahuyhoang411

For reference:

import openai
from openai import OpenAI
client = OpenAI()

try:
  #Make your OpenAI API request here
  response = client.completions.create(
    prompt="Hello world",
    model="gpt-3.5-turbo-instruct"
  )
except openai.APIError as e:
  #Handle API error here, e.g. retry or log
  print(f"OpenAI API returned an API Error: {e}")
  pass
except openai.APIConnectionError as e:
  #Handle connection error here
  print(f"Failed to connect to OpenAI API: {e}")
  pass
except openai.RateLimitError as e:
  #Handle rate limit error (we recommend using exponential backoff)
  print(f"OpenAI API request exceeded rate limit: {e}")
  pass

e.g: openai/_exceptions.py

__all__ = [
    "BadRequestError",
    "AuthenticationError",
    "PermissionDeniedError",
    "NotFoundError",
    "ConflictError",
    "UnprocessableEntityError",
    "RateLimitError",
    "InternalServerError",
]

class APIError(OpenAIError):
    message: str
    request: httpx.Request

    body: object | None
    """The API response body.

    If the API responded with a valid JSON structure then this property will be the
    decoded result.

    If it isn't a valid JSON structure then this will be the raw response.

    If there was no response associated with this error then it will be `None`.
    """

    code: Optional[str]
    param: Optional[str]
    type: Optional[str]

hahuyhoang411 avatar Nov 14 '23 07:11 hahuyhoang411

@hahuyhoang411 Good point, we should have an epic that tracks localization for Jan

dan-menlo avatar Dec 11 '23 13:12 dan-menlo