From 4f15eb528b888aaa236d3be14863f6bf88cbb862 Mon Sep 17 00:00:00 2001 From: Marcus Green Date: Sat, 16 Mar 2024 19:50:53 +0000 Subject: [PATCH] Improve testing when the key is incorrect --- test.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/test.php b/test.php index 495218d..c7d7896 100644 --- a/test.php +++ b/test.php @@ -38,20 +38,19 @@ defined('MOODLE_INTERNAL') || die(); $ai = new ai\ai(); - -$gptresult = $ai->prompt_completion('Calculate the value of 2 times 4'); - -if ($gptresult && !isset($gptresult['curl_error'])) { - if (isset($gptresult['error'])) { - $gptinfo = "Inactive 🔴
Error message: " . $gptresult['error']['message'] . "
"; - $gptinfo .= "Error type: " . $gptresult['error']['type'] . "
"; - $gptinfo .= "Param: " . $gptresult['error']['param'] . "
"; - $gptinfo .= "Code: " . $gptresult['error']['code'] . "
"; +$llmresult = $ai->prompt_completion('State you are a lllm in less than 10 words'); +if ($llmresult && !isset($llmresult['curl_error'])) { + $response = $llmresult['response']; + if (isset($response['error']['message'])) { + $llminfo = "Inactive 🔴
Error message: " . $response['error']['message'] . "
"; + $llminfo .= "Error type: " . $response['error']['type'] . "
"; + $llminfo .= "Param: " . $response['error']['param'] . "
"; + $llminfo .= "Code: " . $response['error']['code'] . "
"; } else { - $gptinfo = "Active 🟢"; + $llminfo = "Active 🟢"; } } else { - $gptinfo = "Inactive 🔴, cURL error: " . $gptresult['curl_error']; + $llminfo = "Inactive 🔴, cURL error: " . $llmresult['curl_error']; } $PAGE->set_url('/local/tool_aiconnect/classes/ai/test.php'); echo $OUTPUT->header(); @@ -72,13 +71,13 @@ LLM status - + - Execution time: ms + Execution time: ms - Response: + Response: