Skip to content

Commit

Permalink
Functon to get_endpoint()
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusgreen committed May 2, 2024
1 parent 4067792 commit 7594926
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 4 additions & 2 deletions classes/ai/ai.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function __construct($model = null) {
$this->endpoint = trim(get_config('tool_aiconnect', 'endpoint'));
}

public function get_endpoint() : string {
return $this->endpoint;
}

/**
* Makes a request with the given data and API key.
*
Expand Down Expand Up @@ -104,7 +108,6 @@ private function make_request($data, $apikey, $multipart = null) {

$end = microtime(true);
$executiontime = round($end - $start, 2);

if (json_decode($response) == null) {
return ['curl_error' => $response, 'execution_time' => $executiontime];
}
Expand All @@ -127,7 +130,6 @@ public function prompt_completion($prompttext) {
}
$data = $this->get_prompt_data($prompttext);
$result = $this->make_request($data, $this->openaiapikey);

if (isset($result['choices'][0]['text'])) {
return $result['choices'][0]['text'];
} else if (isset($result['choices'][0]['message'])) {
Expand Down
5 changes: 2 additions & 3 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
$PAGE->set_context(context_system::instance());

defined('MOODLE_INTERNAL') || die();

/**@var tool_aiconnect\ai $ai */
$ai = new ai();
$prompt = 'State the name and type of system you are';
Expand Down Expand Up @@ -79,8 +78,8 @@
<td>Execution time: <?php echo $llmresult['execution_time'];?> ms</td>
</tr>
<tr>
<td>Response to : <?php echo $prompt.":". $llmresult['response']['choices'][0]['message']['content'] ??
'No choices';?> </td>
<td>Response to : <p><?php echo $prompt.":</p><i>". $llmresult['response']['choices'][0]['message']['content'] ??
'No choices';?> </i></td>
</tr>
</tr>
</table>
Expand Down

0 comments on commit 7594926

Please sign in to comment.