cortex.cpp
cortex.cpp copied to clipboard
feat: [Add Response Code to Nitro REST API for Localization Support]
Current Behavior
{"message":"Model unloaded successfully"}
{"message":"No model loaded"}
Expected Behavior
{"message":"Model unloaded successfully", "code": "ModelUnloadedSuccessfully"}
{"message":"No model loaded", "code": "NoModelLoaded"}
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 Good point, we should have an epic that tracks localization for Jan