Skip to content

Commit

Permalink
add json mode parameter to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusgreen committed Jun 1, 2024
1 parent 303ecba commit beecbfe
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions classes/ai/ai.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,23 @@ class ai {
*/
private string $endpoint;

/**
* response_format
* @var string
*/
private string $format;

/**
* Initialise default settings
*
* @param string $model
*/
public function __construct($model = null) {
public function __construct(?string $model = null, ?string $format = null) {
$this->model = $model ?? trim(explode(',', get_config('tool_aiconnect', 'model'))[0]);
$this->openaiapikey = get_config('tool_aiconnect', 'apikey');
$this->temperature = get_config('tool_aiconnect', 'temperature');
$this->endpoint = trim(get_config('tool_aiconnect', 'endpoint'));
$this->format = $format ?? '';
}

/**
Expand Down Expand Up @@ -148,14 +155,17 @@ public function prompt_completion($prompttext) {
* @param string $prompttext The prompt text.
* @return array The prompt data.
*/
private function get_prompt_data($prompttext): array {
private function get_prompt_data(string $prompttext): array {
$data = [
'model' => $this->model,
'temperature' => $this->temperature,
'messages' => [
['role' => 'system', 'content' => 'You: ' . $prompttext],
],
];
if ($this->format == 'json') {
$data['response_format'] = ['type' => 'json_object'];
}
return $data;
}
/**
Expand Down

0 comments on commit beecbfe

Please sign in to comment.