Skip to content

Commit

Permalink
Merge pull request #107 from amokan/add-openai-project-id-arg
Browse files Browse the repository at this point in the history
feat: Adds option to provide an OpenAI project id
  • Loading branch information
restlessronin authored Oct 11, 2024
2 parents 3ece85f + dfda65c commit a5346ab
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/openai_ex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule OpenaiEx do
"""
defstruct token: nil,
organization: nil,
project: nil,
beta: nil,
base_url: "https://api.openai.com/v1",
receive_timeout: 15_000,
Expand All @@ -22,17 +23,22 @@ defmodule OpenaiEx do
See https://platform.openai.com/docs/api-reference/authentication for details.
"""
def new(token, organization \\ nil) do
def new(token, organization \\ nil, project \\ nil) do
headers =
[{"Authorization", "Bearer #{token}"}] ++
if(is_nil(organization),
do: [],
else: [{"OpenAI-Organization", organization}]
) ++
if(is_nil(project),
do: [],
else: [{"OpenAI-Project", project}]
)

%OpenaiEx{
token: token,
organization: organization,
project: project,
_http_headers: headers
}
end
Expand Down

0 comments on commit a5346ab

Please sign in to comment.