@@ -20,27 +20,27 @@ public class OpenAI extends AbstractApplication implements Provider {
20
20
21
21
@ Action ("openai" )
22
22
public Builder call () throws ApplicationException {
23
- if (this . context .getAttribute ("api" ) == null ) {
23
+ if (getContext () .getAttribute ("api" ) == null ) {
24
24
throw new ApplicationException ("API is required" );
25
25
}
26
26
Builder payload = null ;
27
27
String contentType = "application/json" ;
28
28
Object image = null , mask = null ;
29
- if (this . context . getAttribute ("content-type" ) != null && this . context .getAttribute ("content-type" ).toString ().equalsIgnoreCase ("multipart/form-data" )) {
29
+ if (getContext (). getAttribute ("content-type" ) != null && getContext () .getAttribute ("content-type" ).toString ().equalsIgnoreCase ("multipart/form-data" )) {
30
30
contentType = "multipart/form-data" ;
31
31
32
- if ((image = this . context .getAttribute ("image" )) != null && image .toString ().startsWith ("data:image/png;base64," )) {
32
+ if ((image = getContext () .getAttribute ("image" )) != null && image .toString ().startsWith ("data:image/png;base64," )) {
33
33
image = image .toString ().substring ("data:image/png;base64," .length ());
34
34
}
35
35
36
- if ((mask = this . context .getAttribute ("mask" )) != null && mask .toString ().startsWith ("data:image/png;base64," )) {
36
+ if ((mask = getContext () .getAttribute ("mask" )) != null && mask .toString ().startsWith ("data:image/png;base64," )) {
37
37
mask = mask .toString ().substring ("data:image/png;base64," .length ());
38
38
}
39
- } else if (this . context .getAttribute ("payload" ) == null ) {
39
+ } else if (getContext () .getAttribute ("payload" ) == null ) {
40
40
throw new ApplicationException ("Payload is required" );
41
41
}
42
42
43
- String api = this . context .getAttribute ("api" ).toString ();
43
+ String api = getContext () .getAttribute ("api" ).toString ();
44
44
45
45
// Replace YOUR_API_KEY with your actual API key
46
46
String API_KEY = this .config .get ("openai.api_key" );
@@ -52,8 +52,8 @@ public Builder call() throws ApplicationException {
52
52
HttpRequestBuilder builder = new HttpRequestBuilder ();
53
53
builder .setHeaders (headers ).setMethod (Method .POST );
54
54
55
- if (this . context .getAttribute ("payload" ) != null ) {
56
- payload = (Builder ) this . context .getAttribute ("payload" );
55
+ if (getContext () .getAttribute ("payload" ) != null ) {
56
+ payload = (Builder ) getContext () .getAttribute ("payload" );
57
57
if (contentType .equalsIgnoreCase ("multipart/form-data" )) {
58
58
builder .setParameter ("prompt" , payload .get ("prompt" ).toString ());
59
59
builder .setParameter ("user" , payload .get ("user" ).toString ());
0 commit comments