Skip to content

Commit

Permalink
Merge pull request #43 from chrisgreg/add-retry-strategy-to-api-request
Browse files Browse the repository at this point in the history
Add retry strategy to OpenAI Chat API requests
  • Loading branch information
brainlid authored Dec 1, 2023
2 parents 3b1d07d + a94ecfb commit 0b9ffcf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/chat_models/chat_open_ai.ex
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ defmodule LangChain.ChatModels.ChatOpenAI do
#
# Executes the callback function passing the response only parsed to the data
# structures.
# Retries the request up to 3 times on transient errors with a 1 second delay
@doc false
@spec do_api_request(t(), [Message.t()], [Function.t()], (any() -> any())) ::
list() | struct() | {:error, String.t()}
Expand All @@ -242,7 +243,10 @@ defmodule LangChain.ChatModels.ChatOpenAI do
url: openai.endpoint,
json: for_api(openai, messages, functions),
auth: {:bearer, get_api_key()},
receive_timeout: openai.receive_timeout
receive_timeout: openai.receive_timeout,
retry: :transient,
max_retries: 3,
retry_delay: fn attempt -> :timer.sleep(300 * attempt) end
)

req
Expand Down

0 comments on commit 0b9ffcf

Please sign in to comment.