File tree 2 files changed +11
-4
lines changed
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) {
93
93
$ response = $ curl ->post ("https://api.openai.com/v1/chat/completions " , json_encode ($ curlbody ));
94
94
$ response = json_decode ($ response );
95
95
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
+
96
103
return [
97
- "id " => $ response ->id ,
98
- "message " => $ response -> choices [ 0 ]-> message -> content
104
+ "id " => property_exists ( $ response, ' id ' ) ? $ response ->id : ' error ' ,
105
+ "message " => $ message
99
106
];
100
107
}
101
108
}
Original file line number Diff line number Diff line change 25
25
defined ('MOODLE_INTERNAL ' ) || die ();
26
26
27
27
$ plugin ->component = 'block_openai_chat ' ;
28
- $ plugin ->version = 2024010300 ;
28
+ $ plugin ->version = 2024012300 ;
29
29
$ plugin ->requires = 2022041600 ;
30
30
$ 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