Skip to content

Commit

Permalink
use Req.post/2 rather than Req.post!/2 (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
petrus-jvrensburg authored Jun 24, 2024
1 parent e852691 commit f0a1460
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 8 additions & 5 deletions lib/instructor/adapters/llamacpp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ defmodule Instructor.Adapters.Llamacpp do
Stream.resource(
fn ->
Task.async(fn ->
Req.post!(url(),
Req.post(url(),
json: %{
grammar: grammar,
prompt: prompt,
Expand Down Expand Up @@ -96,7 +96,7 @@ defmodule Instructor.Adapters.Llamacpp do

defp do_chat_completion(prompt, grammar) do
response =
Req.post!(url(),
Req.post(url(),
json: %{
grammar: grammar,
prompt: prompt
Expand All @@ -105,11 +105,14 @@ defmodule Instructor.Adapters.Llamacpp do
)

case response do
%{status: 200, body: %{"content" => params}} ->
{:ok, %{status: 200, body: %{"content" => params}}} ->
{:ok, to_openai_response(params)}

_ ->
nil
{:ok, %{status: status}} ->
{:error, "Unexpected HTTP response code: #{status}"}

{:error, reason} ->
{:error, reason}
end
end

Expand Down
10 changes: 5 additions & 5 deletions lib/instructor/adapters/openai.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule Instructor.Adapters.OpenAI do
end
)

Req.post!(url(config), options)
Req.post(url(config), options)
send(pid, :done)
end)
end,
Expand All @@ -77,11 +77,11 @@ defmodule Instructor.Adapters.OpenAI do

defp do_chat_completion(params, config) do
options = Keyword.merge(http_options(config), json: params, auth: {:bearer, api_key(config)})
response = Req.post!(url(config), options)

case response.status do
200 -> {:ok, response.body}
_ -> {:error, response.body}
case Req.post(url(config), options) do
{:ok, %{status: 200, body: body}} -> {:ok, body}
{:ok, %{status: status}} -> {:error, "Unexpected HTTP response code: #{status}"}
{:error, reason} -> {:error, reason}
end
end

Expand Down

0 comments on commit f0a1460

Please sign in to comment.