Skip to content

Commit

Permalink
Pass api_key to request if present in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
michalwarda committed Dec 3, 2023
1 parent 1c2dac9 commit 00704a1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/chat_models/chat_open_ai.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ defmodule LangChain.ChatModels.ChatOpenAI do
]
@required_fields [:model]

@spec get_api_key() :: String.t()
defp get_api_key() do
@spec get_api_key(t) :: String.t()
defp get_api_key(%ChatOpenAI{api_key: api_key}) do
# if no API key is set default to `""` which will raise a Stripe API error
Config.resolve(:openai_key, "")
api_key || Config.resolve(:openai_key, "")
end

@spec get_org_id() :: String.t() | nil
Expand Down Expand Up @@ -246,7 +246,7 @@ defmodule LangChain.ChatModels.ChatOpenAI do
Req.new(
url: openai.endpoint,
json: for_api(openai, messages, functions),
auth: {:bearer, get_api_key()},
auth: {:bearer, get_api_key(openai)},
receive_timeout: openai.receive_timeout,
retry: :transient,
max_retries: 3,
Expand Down Expand Up @@ -331,7 +331,7 @@ defmodule LangChain.ChatModels.ChatOpenAI do
Req.new(
url: openai.endpoint,
json: for_api(openai, messages, functions),
auth: {:bearer, get_api_key()},
auth: {:bearer, get_api_key(openai)},
receive_timeout: openai.receive_timeout,
finch_request: finch_fun
)
Expand Down

0 comments on commit 00704a1

Please sign in to comment.