Add lombok and retrieve engine endpoint

This commit is contained in:
Theo Kanning 2020-09-14 21:29:30 -05:00
parent b38f8681b1
commit 13336e6cb6
6 changed files with 25 additions and 4 deletions

View File

@ -9,6 +9,10 @@ class OpenAiApiExample {
OpenAiService service = new OpenAiService(token);
System.out.println("Getting available engines");
service.getEngines().forEach((Engine e) -> System.out.println(e.id));
service.getEngines().forEach(System.out::println);
System.out.println("Getting ada engine");
Engine ada = service.getEngine("ada");
System.out.println(ada);
}
}

View File

@ -1,9 +1,12 @@
apply plugin: 'java-library'
dependencies {
api 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
implementation 'com.squareup.retrofit2:converter-jackson:2.5.0'
api 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'
implementation 'com.squareup.retrofit2:converter-jackson:2.9.0'
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
testImplementation 'junit:junit:4.13'
}

View File

@ -3,9 +3,13 @@ package openai;
import io.reactivex.Single;
import openai.engine.Engine;
import retrofit2.http.GET;
import retrofit2.http.Path;
public interface OpenAiApi {
@GET("v1/engines")
Single<OpenAiResponse<Engine>> getEngines();
@GET("/v1/engines/{engine_id}")
Single<Engine> getEngine(@Path("engine_id") String engineId);
}

View File

@ -1,7 +1,10 @@
package openai;
import lombok.Data;
import java.util.List;
@Data
public class OpenAiResponse<T> {
public List<T> data;
public String object;

View File

@ -42,4 +42,8 @@ public class OpenAiService {
public List<Engine> getEngines() {
return api.getEngines().blockingGet().data;
}
public Engine getEngine(String engineId) {
return api.getEngine(engineId).blockingGet();
}
}

View File

@ -1,5 +1,8 @@
package openai.engine;
import lombok.Data;
@Data
public class Engine {
public String id;
public String object;