TheoKanning / openai-java

OpenAI Api Client in Java
MIT License
4.68k stars 1.16k forks source link

Base URL with path segments is not supported #471

Open Vasniktel opened 4 months ago

Vasniktel commented 4 months ago

It is possible to specify a base URL with retrofit as follows:

var retrofit = OpenAiService.defaultRetrofit(client, om)
            .newBuilder()
            .baseUrl("https://api.groq.com/openai/")
            .build();

However, if baseUrl contains any path segments (e.g. /openai/ above) - they will be ignored because some OpenAiApi methods define absolute paths:https://github.com/TheoKanning/openai-java/blob/e7de81c29319d605703a874c3f1fa56f61122e8b/client/src/main/java/com/theokanning/openai/client/OpenAiApi.java#L69 A fix would be to remove all heading / to make v1/chat/completions.

Additionally, the behaviour of heading / is inconsistent: https://github.com/TheoKanning/openai-java/blob/e7de81c29319d605703a874c3f1fa56f61122e8b/client/src/main/java/com/theokanning/openai/client/OpenAiApi.java#L56

A temporary solution for now is to use a custom interceptor to manually insert missing path segments into every request.

wufg2002 commented 3 months ago

change @POST("/v1/completions") to @POST("v1/completions")

interface HxOpenAiApi : OpenAiApi { @Streaming @POST("v1/completions")
override fun createCompletionStream(@Body request: CompletionRequest?): Call<ResponseBody?>?

}