Skip to content

Commit

Permalink
Add set_assistant_id/2 function
Browse files Browse the repository at this point in the history
Allows the assistant_id to be changed after the agent is started.
  • Loading branch information
jwilger committed Feb 15, 2024
1 parent 69f24df commit 039f50b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/gpt_agent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ defmodule GptAgent do
@callback submit_tool_output(pid(), Types.tool_name(), Types.tool_output()) ::
Types.result(:invalid_tool_call_id)
@callback run_in_progress?(pid()) :: boolean()
@callback set_assistant_id(pid(), Types.assistant_id()) :: Types.success()

defp noreply(%__MODULE__{} = state), do: {:noreply, state, state.timeout_ms}
defp noreply(%__MODULE__{} = state, next), do: {:noreply, state, next}
Expand Down Expand Up @@ -591,5 +592,10 @@ defmodule GptAgent do
def run_in_progress?(pid) do
GenServer.call(pid, :run_in_progress?)
end

@impl true
def set_assistant_id(pid, assistant_id) do
GenServer.cast(pid, {:set_assistant_id, assistant_id})
end
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule GptAgent.MixProject do
def project do
[
app: :gpt_agent,
version: "6.1.0",
version: "6.2.0",
elixir: "~> 1.16",
start_permanent: Mix.env() == :prod,
aliases: aliases(),
Expand Down
17 changes: 17 additions & 0 deletions test/gpt_agent_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1380,4 +1380,21 @@ defmodule GptAgentTest do
refute GptAgent.run_in_progress?(pid)
end
end

describe "set_assistant_id/2" do
test "updates the assistant_id in the agent's state", %{
assistant_id: assistant_id,
thread_id: thread_id
} do
{:ok, pid} =
GptAgent.connect(thread_id: thread_id, last_message_id: nil, assistant_id: assistant_id)

assert %GptAgent{assistant_id: ^assistant_id} = :sys.get_state(pid)

new_assistant_id = UUID.uuid4()
:ok = GptAgent.set_assistant_id(pid, new_assistant_id)

assert %GptAgent{assistant_id: ^new_assistant_id} = :sys.get_state(pid)
end
end
end

0 comments on commit 039f50b

Please sign in to comment.