@@ -507,6 +507,7 @@ public function getSummary() {
507507 !empty (OLLAMA_URL ) &&
508508 !empty (OLLAMA_MODEL )
509509 ) {
510+ $ this ->log ->info ('Trying to get summary from Ollama API for ' . $ this ->url );
510511 $ model_is_available = false ;
511512 $ ollama_tags_url = OLLAMA_URL . '/api/tags ' ;
512513 $ curl_options = array (
@@ -551,19 +552,24 @@ public function getSummary() {
551552 $ curl_response = curlURL ($ ollama_api_url , $ curl_options ) ?? '' ;
552553 if (!$ curl_response ) {
553554 $ this ->log ->error ('Ollama API response is empty or invalid ' );
554- $ summary = '' ;
555- }
556- $ response = json_decode ($ curl_response , true );
557- if (!empty ($ response ['response ' ]) && strlen ($ response ['response ' ]) > 100 ) {
558- $ summary = $ response ['response ' ];
559- $ summary_provider = 'ollama ' ;
560- $ summary_model = OLLAMA_MODEL ;
561- $ this ->log ->info ("Summary for URL $ this ->url generated by Ollama model $ summary_model " );
555+ } else {
556+ $ response = json_decode ($ curl_response , true );
557+ if (!$ response ) {
558+ $ this ->log ->error ('Ollama API response is not valid JSON ' );
559+ } elseif (!empty ($ response ['response ' ]) && strlen ($ response ['response ' ]) > 100 ) {
560+ $ summary = $ response ['response ' ];
561+ $ summary_provider = 'ollama ' ;
562+ $ summary_model = OLLAMA_MODEL ;
563+ $ this ->log ->info ("Summary for URL $ this ->url generated by Ollama model $ summary_model " );
564+ } else {
565+ $ this ->log ->error ('Ollama API response does not contain valid summary content ' );
566+ }
562567 }
563568 }
564569 }
565570 }
566571 if (!$ summary && !empty (OPENAI_API_KEY )) {
572+ $ this ->log ->info ('Trying to get summary from OpenAI API for ' . $ this ->url );
567573 $ openai_url = 'https://api.openai.com/v1/chat/completions ' ;
568574 $ openai_model = OPENAI_API_MODEL ?? 'gpt-4o-mini ' ;
569575 $ curl_options = array (
@@ -599,6 +605,12 @@ public function getSummary() {
599605 $ summary_provider = 'openai ' ;
600606 $ summary_model = $ openai_model ;
601607 $ this ->log ->info ("Summary for URL $ this ->url generated by OpenAI model $ summary_model " );
608+ } else {
609+ if (!empty ($ response ['error ' ]['message ' ])) {
610+ $ this ->log ->error ('OpenAI API response contains an error: ' . $ response ['error ' ]['message ' ]);
611+ } else {
612+ $ this ->log ->error ('OpenAI API response does not contain valid summary content ' );
613+ }
602614 }
603615 }
604616 if (!$ summary ) {
0 commit comments