File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -93,9 +93,16 @@ private function make_api_call($history) {
9393 $ response = $ curl ->post ("https://api.openai.com/v1/chat/completions " , json_encode ($ curlbody ));
9494 $ response = json_decode ($ response );
9595
96+ $ message = null ;
97+ if (property_exists ($ response , 'error ' )) {
98+ $ message = 'ERROR: ' . $ response ->error ->message ;
99+ } else {
100+ $ message = $ response ->choices [0 ]->message ->content ;
101+ }
102+
96103 return [
97- "id " => $ response ->id ,
98- "message " => $ response -> choices [ 0 ]-> message -> content
104+ "id " => property_exists ( $ response, ' id ' ) ? $ response ->id : ' error ' ,
105+ "message " => $ message
99106 ];
100107 }
101108}
Original file line number Diff line number Diff line change 2525defined ('MOODLE_INTERNAL ' ) || die ();
2626
2727$ plugin ->component = 'block_openai_chat ' ;
28- $ plugin ->version = 2024010300 ;
28+ $ plugin ->version = 2024012300 ;
2929$ plugin ->requires = 2022041600 ;
3030$ plugin ->maturity = MATURITY_STABLE ;
31- $ plugin ->release = '2.0.0 ' ;
31+ $ plugin ->release = '2.0.1 ' ;
You can’t perform that action at this time.
0 commit comments