openai/src/4c58b254-aea5-40aa-b54d-9586a1690451/code.power

36 lines
824 B
Plaintext

/**
* Constructor.
*
* @param string|null $token The Openai API token.
* @param string|null $org The Openai API Organization token.
*
* @since 3.2.0
* @throws \InvalidArgumentException
**/
public function __construct(?string $token, ?string $org = null)
{
// setup config
$config = [
'userAgent' => 'JoomlaOpenai/3.0',
'headers' => [
'Content-Type' => 'application/json'
]
];
// add the token if given
if (is_string($token))
{
$config['headers']['Authorization'] = 'Bearer ' . $token;
}
// add the organization token if given
if (is_string($org))
{
$config['headers']['OpenAI-Organization'] = $org;
}
$options = new Registry($config);
// run parent constructor
parent::__construct($options);
}