Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusgreen committed May 20, 2024
1 parent bb02499 commit 97c2879
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
13 changes: 6 additions & 7 deletions classes/ai/ai.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ai {
* @param string $model
*/
public function __construct($model = null) {
$this->model = $model ?? trim(explode(',',get_config('tool_aiconnect','model'))[0]);
$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'));
Expand All @@ -87,9 +87,9 @@ private function make_request($data, $apikey, $multipart = null) {
'Empty API Key.');
}
$headers = $multipart ? [
"Content-Type: multipart/form-data"
"Content-Type: multipart/form-data",
] : [
"Content-Type: application/json;charset=utf-8"
"Content-Type: application/json;charset=utf-8",
];

$headers[] = "Authorization: Bearer $apikey";
Expand All @@ -100,11 +100,10 @@ private function make_request($data, $apikey, $multipart = null) {
];
$start = microtime(true);
$jsonresponse = $curl->post($this->endpoint, json_encode($data), $options);
$response = json_decode($jsonresponse,true);
$response = json_decode($jsonresponse, true);
if ($response == null) {
return ['curl_error' => $curl->get_info()->http_code, 'execution_time' => $executiontime];
}
xdebug_break();

if(isset($response['error'])){
throw new moodle_exception('endpointerror', 'tool_aiconnect', '', null,
Expand Down Expand Up @@ -149,7 +148,7 @@ 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($prompttext): array {
$data = [
'model' => $this->model,
'temperature' => $this->temperature,
Expand All @@ -159,7 +158,7 @@ private function get_prompt_data($prompttext) : array {
];
return $data;
}
public function get_models() : \stdClass {
public function get_models(): \stdClass {
$url = new \moodle_url($this->endpoint);
$ollama = true;
// Ollama url.
Expand Down
12 changes: 6 additions & 6 deletions tests/test_aiconnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function setUp(): void {
*
* @return void
*/
public function test_get_prompt_data() :void {
public function test_get_prompt_data(): void {
$this->assertTrue(true);
$mockai = $this->getMockBuilder(ai\ai::class)->getMock();
$getpromptdata = new \ReflectionMethod(
Expand All @@ -71,13 +71,13 @@ public function test_get_prompt_data() :void {
['myprompt']
);
$this->assertStringContainsString("You: myprompt", $result['messages'][0]['content']);
}
}

/**
* This doesn't do anything especially useful.
* @return void
*/
public function test_prompt_completion() :void {
* This doesn't do anything especially useful.
* @return void
*/
public function test_prompt_completion(): void {
$result = $this->ai->prompt_completion('query');
$this->assertIsArray($result);
}
Expand Down

0 comments on commit 97c2879

Please sign in to comment.