Skip to content

Commit bd9815b

Browse files
committed
fix(openai): error messages for 400 and 404
1 parent 42e85ef commit bd9815b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/providers/open_ai.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ defmodule HyperLLM.Provider.OpenAI do
4848
See `HyperLLM.Chat.completion/3` for more information.
4949
"""
5050
@spec completion(HyperLLM.Provider.completion_params(), HyperLLM.Provider.completion_config()) ::
51-
{:ok, binary()} | {:error, binary()}
51+
{:ok, map()} | {:error, binary()}
5252
@impl HyperLLM.Provider
5353
def completion(params, config \\ []) do
5454
if !Map.has_key?(params, :messages) do
@@ -71,13 +71,13 @@ defmodule HyperLLM.Provider.OpenAI do
7171
{:ok, body}
7272

7373
%{status: 400, body: body} ->
74-
{:error, body.error.message}
74+
{:error, get_in(body["error"]["message"])}
7575

7676
%{status: 401} ->
7777
{:error, "OpenAI API key is invalid"}
7878

79-
%{status: 404} ->
80-
{:error, "OpenAI API not found"}
79+
%{status: 404, body: body} ->
80+
{:error, get_in(body["error"]["message"])}
8181

8282
%{status: 500} ->
8383
{:error, "OpenAI Server error"}

0 commit comments

Comments
 (0)