Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/chat_models/chat_anthropic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,8 @@ defmodule LangChain.ChatModels.ChatAnthropic do
error

other ->
message = "Unexpected and unhandled API response! #{inspect(other)}"
Logger.error(message)
{:error, LangChainError.exception(type: "unexpected_response", message: message)}
Logger.error("Unexpected and unhandled API response! #{inspect(other)}")
other
end
end

Expand Down Expand Up @@ -689,9 +688,16 @@ defmodule LangChain.ChatModels.ChatAnthropic do
error

other ->
message = "Unhandled and unexpected response from streamed post call. #{inspect(other)}"
Logger.error(message)
{:error, LangChainError.exception(type: "unexpected_response", message: message)}
Logger.error(
"Unhandled and unexpected response from streamed post call. #{inspect(other)}"
)

{:error,
LangChainError.exception(
type: "unexpected_response",
message: "Unexpected response",
original: other
)}
end
end

Expand Down
6 changes: 5 additions & 1 deletion lib/chat_models/chat_google_ai.ex
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,11 @@ defmodule LangChain.ChatModels.ChatGoogleAI do
)

{:error,
LangChainError.exception(type: "unexpected_response", message: "Unexpected response")}
LangChainError.exception(
type: "unexpected_response",
message: "Unexpected response",
original: other
)}
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/chat_models/chat_grok.ex
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,8 @@ defmodule LangChain.ChatModels.ChatGrok do
{:error,
LangChainError.exception(
type: :unexpected_response,
message: "Unexpected response: #{inspect(other)}"
message: "Unexpected response: #{inspect(other)}",
original: other
)}
end
end
Expand Down
8 changes: 7 additions & 1 deletion lib/chat_models/chat_mistral_ai.ex
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,13 @@ defmodule LangChain.ChatModels.ChatMistralAI do

other ->
Logger.error("Unhandled and unexpected response from streamed call. #{inspect(other)}")
{:error, LangChainError.exception(type: "unexpected_response", message: "Unexpected")}

{:error,
LangChainError.exception(
type: "unexpected_response",
message: "Unexpected",
original: other
)}
end
end

Expand Down
6 changes: 5 additions & 1 deletion lib/chat_models/chat_ollama_ai.ex
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,11 @@ defmodule LangChain.ChatModels.ChatOllamaAI do
)

{:error,
LangChainError.exception(type: "unexpected_response", message: "Unexpected response")}
LangChainError.exception(
type: "unexpected_response",
message: "Unexpected response",
original: other
)}
end
end

Expand Down
14 changes: 12 additions & 2 deletions lib/chat_models/chat_open_ai.ex
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,11 @@ defmodule LangChain.ChatModels.ChatOpenAI do
)

{:error,
LangChainError.exception(type: "unexpected_response", message: "Unexpected response")}
LangChainError.exception(
type: "unexpected_response",
message: "Unexpected response",
original: other
)}
end
end

Expand Down Expand Up @@ -1185,7 +1189,13 @@ defmodule LangChain.ChatModels.ChatOpenAI do

def do_process_response(_model, other) do
Logger.error("Trying to process an unexpected response. #{inspect(other)}")
{:error, LangChainError.exception(message: "Unexpected response", original: other)}

{:error,
LangChainError.exception(
type: "unexpected_response",
message: "Unexpected response",
original: other
)}
end

defp finish_reason_to_status(nil), do: :incomplete
Expand Down
14 changes: 12 additions & 2 deletions lib/chat_models/chat_open_ai_responses.ex
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,11 @@ defmodule LangChain.ChatModels.ChatOpenAIResponses do
)

{:error,
LangChainError.exception(type: "unexpected_response", message: "Unexpected response")}
LangChainError.exception(
type: "unexpected_response",
message: "Unexpected response",
original: other
)}
end
end

Expand Down Expand Up @@ -1137,7 +1141,13 @@ defmodule LangChain.ChatModels.ChatOpenAIResponses do

def do_process_response(_model, other) do
Logger.error("Trying to process an unexpected response. #{inspect(other)}")
{:error, LangChainError.exception(message: "Unexpected response")}

{:error,
LangChainError.exception(
type: "unexpected_response",
message: "Unexpected response",
original: other
)}
end

defp get_token_usage(%{"usage" => usage} = _response_body) when is_map(usage) do
Expand Down
6 changes: 5 additions & 1 deletion lib/chat_models/chat_orq.ex
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,11 @@ defmodule LangChain.ChatModels.ChatOrq do
)

{:error,
LangChainError.exception(type: "unexpected_response", message: "Unexpected response")}
LangChainError.exception(
type: "unexpected_response",
message: "Unexpected response",
original: other
)}
end
end

Expand Down
8 changes: 7 additions & 1 deletion lib/chat_models/chat_perplexity.ex
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,13 @@ defmodule LangChain.ChatModels.ChatPerplexity do

def do_process_response(_model, other) do
Logger.error("Trying to process an unexpected response. #{inspect(other)}")
{:error, LangChainError.exception(message: "Unexpected response")}

{:error,
LangChainError.exception(
type: "unexpected_response",
message: "Unexpected response",
original: other
)}
end

defp finish_reason_to_status(nil), do: :incomplete
Expand Down
6 changes: 5 additions & 1 deletion lib/chat_models/chat_vertex_ai.ex
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,11 @@ defmodule LangChain.ChatModels.ChatVertexAI do
)

{:error,
LangChainError.exception(type: "unexpected_response", message: "Unexpected response")}
LangChainError.exception(
type: "unexpected_response",
message: "Unexpected response",
original: other
)}
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/chat_models/chat_open_ai_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ defmodule LangChain.ChatModels.ChatOpenAITest do
{:error, %LangChainError{} = error} =
ChatOpenAI.do_process_response(model, "unexpected")

assert error.type == nil
assert error.type == "unexpected_response"
assert error.message == "Unexpected response"
end

Expand Down
2 changes: 1 addition & 1 deletion test/chat_models/chat_perplexity_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ defmodule LangChain.ChatModels.ChatPerplexityTest do
{:error, %LangChainError{} = error} =
ChatPerplexity.do_process_response(model, "unexpected")

assert error.type == nil
assert error.type == "unexpected_response"
assert error.message == "Unexpected response"
end
end
Expand Down