Packages

Sans-IO OpenAI API client for Gleam, ported from async-openai

Current section

Files

Jump to
glopenai src glopenai@config.erl
Raw

src/glopenai@config.erl

-module(glopenai@config).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glopenai/config.gleam").
-export([with_api_base/2, with_org_id/2, with_project_id/2, with_header/3, new_azure/4, new/1]).
-export_type([config/0, azure_config/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type config() :: {config,
binary(),
binary(),
gleam@option:option(binary()),
gleam@option:option(binary()),
list({binary(), binary()})}.
-type azure_config() :: {azure_config, binary(), binary(), binary(), binary()}.
-file("src/glopenai/config.gleam", 29).
?DOC(" Set a custom API base URL (e.g. for proxies or compatible APIs).\n").
-spec with_api_base(config(), binary()) -> config().
with_api_base(Config, Api_base) ->
{config,
Api_base,
erlang:element(3, Config),
erlang:element(4, Config),
erlang:element(5, Config),
erlang:element(6, Config)}.
-file("src/glopenai/config.gleam", 34).
?DOC(" Set the organization ID header (OpenAI-Organization).\n").
-spec with_org_id(config(), binary()) -> config().
with_org_id(Config, Org_id) ->
{config,
erlang:element(2, Config),
erlang:element(3, Config),
{some, Org_id},
erlang:element(5, Config),
erlang:element(6, Config)}.
-file("src/glopenai/config.gleam", 39).
?DOC(" Set the project ID header (OpenAI-Project).\n").
-spec with_project_id(config(), binary()) -> config().
with_project_id(Config, Project_id) ->
{config,
erlang:element(2, Config),
erlang:element(3, Config),
erlang:element(4, Config),
{some, Project_id},
erlang:element(6, Config)}.
-file("src/glopenai/config.gleam", 44).
?DOC(" Add a custom header to all requests.\n").
-spec with_header(config(), binary(), binary()) -> config().
with_header(Config, Key, Value) ->
{config,
erlang:element(2, Config),
erlang:element(3, Config),
erlang:element(4, Config),
erlang:element(5, Config),
[{Key, Value} | erlang:element(6, Config)]}.
-file("src/glopenai/config.gleam", 59).
?DOC(" Create a new Azure config.\n").
-spec new_azure(binary(), binary(), binary(), binary()) -> azure_config().
new_azure(Api_base, Api_key, Deployment_id, Api_version) ->
{azure_config, Api_base, Api_key, Deployment_id, Api_version}.
-file("src/glopenai/config.gleam", 18).
?DOC(" Create a new config with the given API key and the default base URL.\n").
-spec new(binary()) -> config().
new(Api_key) ->
{config, <<"https://api.openai.com/v1"/utf8>>, Api_key, none, none, []}.