TheoKanning / openai-java

OpenAI Api Client in Java
MIT License
4.78k stars 1.21k forks source link

Provide statically typed model selection #74

Open yeikel opened 1 year ago

yeikel commented 1 year ago

It would be a nice-to-have to provide a mechanism to access models in a statically typed fashion rather than using the hard coded Strings.

From the onboarding example, rather than :


CompletionRequest completionRequest = CompletionRequest.builder()
        .prompt("Somebody once told me the world is gonna roll me")
        .model("ada")
        .echo(true)
        .build();

It would be nice to be able to do something like :


CompletionRequest completionRequest = CompletionRequest.builder()
        .prompt("Somebody once told me the world is gonna roll me")
        .model(Model.ada)
        .echo(true)
        .build();

With the current setup, it fails at runtime with a 404 when the model is invalid


Exception in thread "main" retrofit2.adapter.rxjava2.HttpException: HTTP 404 
    at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:57)
    at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:38)
    at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:48)
    at io.reactivex.Observable.subscribe(Observable.java:10151)
cryptoapebot commented 1 year ago

I know the list models here. https://api.openai.com/v1/models

Also the moderation model automatically gets mapped. "text-moderation-latest" to text-moderation-004.

It would be useful to have Model.ada.latest etc.