diff --git a/public/ai/provider/ollama/classes/abstract_processor.php b/public/ai/provider/ollama/classes/abstract_processor.php index c09b519917d..4e59ed4059d 100644 --- a/public/ai/provider/ollama/classes/abstract_processor.php +++ b/public/ai/provider/ollama/classes/abstract_processor.php @@ -143,7 +143,7 @@ abstract class abstract_processor extends process_base { $errormessage = $response->getReasonPhrase(); } else { $bodyobj = json_decode($response->getBody()->getContents()); - $errormessage = $bodyobj->error->message; + $errormessage = $bodyobj->error; } return \core_ai\error\factory::create($status, $errormessage)->get_error_details(); diff --git a/public/ai/provider/ollama/tests/process_explain_text_test.php b/public/ai/provider/ollama/tests/process_explain_text_test.php index ffc39acc412..c0a63e1fecd 100644 --- a/public/ai/provider/ollama/tests/process_explain_text_test.php +++ b/public/ai/provider/ollama/tests/process_explain_text_test.php @@ -151,12 +151,21 @@ final class process_explain_text_test extends \advanced_testcase { $responses = [ 500 => new Response(500, ['Content-Type' => 'application/json']), 503 => new Response(503, ['Content-Type' => 'application/json']), - 401 => new Response(401, ['Content-Type' => 'application/json'], - '{"error": {"message": "Invalid Authentication"}}'), - 404 => new Response(404, ['Content-Type' => 'application/json'], - '{"error": {"message": "You must be a member of an organization to use the API"}}'), - 429 => new Response(429, ['Content-Type' => 'application/json'], - '{"error": {"message": "Rate limit reached for requests"}}'), + 401 => new Response( + 401, + ['Content-Type' => 'application/json'], + json_encode(['error' => 'Invalid Authentication']), + ), + 404 => new Response( + 404, + ['Content-Type' => 'application/json'], + json_encode(['error' => 'You must be a member of an organization to use the API']), + ), + 429 => new Response( + 429, + ['Content-Type' => 'application/json'], + json_encode(['error' => 'Rate limit reached for requests']), + ), ]; $processor = new process_explain_text($this->provider, $this->action); @@ -317,7 +326,7 @@ final class process_explain_text_test extends \advanced_testcase { $mock->append(new Response( 401, ['Content-Type' => 'application/json'], - json_encode(['error' => ['message' => 'Invalid Authentication']]), + json_encode(['error' => 'Invalid Authentication']), )); $processor = new process_explain_text($this->provider, $this->action); diff --git a/public/ai/provider/ollama/tests/process_generate_text_test.php b/public/ai/provider/ollama/tests/process_generate_text_test.php index 8a5e23148e2..ee82e43b7f3 100644 --- a/public/ai/provider/ollama/tests/process_generate_text_test.php +++ b/public/ai/provider/ollama/tests/process_generate_text_test.php @@ -153,17 +153,17 @@ final class process_generate_text_test extends \advanced_testcase { 401 => new Response( 401, ['Content-Type' => 'application/json'], - json_encode(['error' => ['message' => 'Invalid Authentication']]), + json_encode(['error' => 'Invalid Authentication']), ), 404 => new Response( 404, ['Content-Type' => 'application/json'], - json_encode(['error' => ['message' => 'You must be a member of an organization to use the API']]), + json_encode(['error' => 'You must be a member of an organization to use the API']), ), 429 => new Response( 429, ['Content-Type' => 'application/json'], - json_encode(['error' => ['message' => 'Rate limit reached for requests']]), + json_encode(['error' => 'Rate limit reached for requests']), ), ]; @@ -326,7 +326,7 @@ final class process_generate_text_test extends \advanced_testcase { $mock->append(new Response( 401, ['Content-Type' => 'application/json'], - json_encode(['error' => ['message' => 'Invalid Authentication']]), + json_encode(['error' => 'Invalid Authentication']), )); $processor = new process_generate_text($this->provider, $this->action); diff --git a/public/ai/provider/ollama/tests/process_summarise_text_test.php b/public/ai/provider/ollama/tests/process_summarise_text_test.php index 6b12b6ed559..95027125268 100644 --- a/public/ai/provider/ollama/tests/process_summarise_text_test.php +++ b/public/ai/provider/ollama/tests/process_summarise_text_test.php @@ -151,12 +151,21 @@ final class process_summarise_text_test extends \advanced_testcase { $responses = [ 500 => new Response(500, ['Content-Type' => 'application/json']), 503 => new Response(503, ['Content-Type' => 'application/json']), - 401 => new Response(401, ['Content-Type' => 'application/json'], - '{"error": {"message": "Invalid Authentication"}}'), - 404 => new Response(404, ['Content-Type' => 'application/json'], - '{"error": {"message": "You must be a member of an organization to use the API"}}'), - 429 => new Response(429, ['Content-Type' => 'application/json'], - '{"error": {"message": "Rate limit reached for requests"}}'), + 401 => new Response( + 401, + ['Content-Type' => 'application/json'], + json_encode(['error' => 'Invalid Authentication']), + ), + 404 => new Response( + 404, + ['Content-Type' => 'application/json'], + json_encode(['error' => 'You must be a member of an organization to use the API']), + ), + 429 => new Response( + 429, + ['Content-Type' => 'application/json'], + json_encode(['error' => 'Rate limit reached for requests']), + ), ]; $processor = new process_summarise_text($this->provider, $this->action); @@ -317,7 +326,7 @@ final class process_summarise_text_test extends \advanced_testcase { $mock->append(new Response( 401, ['Content-Type' => 'application/json'], - json_encode(['error' => ['message' => 'Invalid Authentication']]), + json_encode(['error' => 'Invalid Authentication']), )); $processor = new process_summarise_text($this->provider, $this->action);