Skip to content

Commit

Permalink
Fix bug due to not setting running? false
Browse files Browse the repository at this point in the history
I missed that I needed to set the state of the agent to "not running"
after handling failed runs that will not be retried but there were two
cases where I was not.
  • Loading branch information
jwilger committed Feb 23, 2024
1 parent 6390ce3 commit 5ae9a41
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/gpt_agent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ defmodule GptAgent do

state
|> Map.update!(:rate_limit_retry_attempt, &(&1 + 1))
|> Map.put(:running?, false)
|> publish_event(
RateLimited.new!(
run_id: id,
Expand Down Expand Up @@ -520,6 +521,7 @@ defmodule GptAgent do
log("Run ID #{inspect(id)} failed due to OpenAI account quota reached.")

state
|> Map.put(:running?, false)
|> publish_event(
OrganizationQuotaExceeded.new!(
run_id: id,
Expand Down
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: "9.2.0",
version: "9.2.1",
elixir: "~> 1.16",
start_permanent: Mix.env() == :prod,
aliases: aliases(),
Expand Down
9 changes: 9 additions & 0 deletions test/gpt_agent_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,8 @@ defmodule GptAgentTest do

refute_receive {^pid, %RunFailed{}}, @retry_delay - 10

assert :sys.get_state(pid).running?

assert_receive {^pid,
%RateLimited{
run_id: ^run_id,
Expand All @@ -1194,6 +1196,7 @@ defmodule GptAgentTest do
20

refute_receive {^pid, %RunFailed{}}, @retry_delay - 10
assert :sys.get_state(pid).running?

assert_receive {^pid,
%RateLimited{
Expand All @@ -1210,6 +1213,8 @@ defmodule GptAgentTest do
thread_id: ^thread_id,
assistant_id: ^assistant_id
}}

refute :sys.get_state(pid).running?
end

@tag capture_log: true
Expand Down Expand Up @@ -1272,6 +1277,8 @@ defmodule GptAgentTest do
message:
"You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors."
}}

refute :sys.get_state(pid).running?
end

@tag capture_log: true
Expand Down Expand Up @@ -1328,6 +1335,8 @@ defmodule GptAgentTest do
code: ^code,
message: ^message
}}

refute :sys.get_state(pid).running?
end
end

Expand Down

0 comments on commit 5ae9a41

Please sign in to comment.