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

64 lines
1.4 KiB
PHP

<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Openai\Utilities;
use Joomla\CMS\Http\Http as JoomlaHttp;
use Joomla\Registry\Registry;
/**
* The Openai Http
*
* @since 3.2.0
*/
final class Http extends JoomlaHttp
{
/**
* 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);
}
}