Skip to content

Commit

Permalink
Revert "Go back to using cast for adding user message"
Browse files Browse the repository at this point in the history
This reverts commit 529a5c9.
  • Loading branch information
jwilger committed Dec 19, 2023
1 parent 529a5c9 commit 981508f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/gpt_agent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule GptAgent do

defp ok(state, next), do: {:ok, state, next}
defp noreply(state), do: {:noreply, state}
defp noreply(state, next), do: {:noreply, state, next}
defp reply(state, reply, next), do: {:reply, reply, state, next}

defp send_callback(state, callback) do
send(state.callback_handler, {__MODULE__, state.pid, callback})
Expand Down Expand Up @@ -82,7 +82,7 @@ defmodule GptAgent do

defp heartbeat_interval_ms, do: Application.get_env(:gpt_agent, :heartbeat_interval_ms, 1000)

def handle_cast({:add_user_message, message}, state) do
def handle_call({:add_user_message, message}, _caller, state) do
{:ok, message} = NonblankString.new(message)

{:ok, %{body: %{"id" => id}}} =
Expand All @@ -94,7 +94,7 @@ defmodule GptAgent do
thread_id: state.thread_id,
content: message
})
|> noreply({:continue, :run})
|> reply(:ok, {:continue, :run})
end

def handle_info({:check_run_status, id}, state) do
Expand Down Expand Up @@ -149,6 +149,6 @@ defmodule GptAgent do
end

def add_user_message(pid, message) do
GenServer.cast(pid, {:add_user_message, message})
GenServer.call(pid, {:add_user_message, message})
end
end

0 comments on commit 981508f

Please sign in to comment.