Я могу получить доступ, используя baseURL https://api.openai.com/, но получаю исключение 404 при попытке доступа к OpenRouter. Я использую приведенный ниже код, чтобы указать baseURL, используя пример в выпуске 454 openai-java. Я пробовал baseURL https://openrouter.ai/api/v1/chat/completions/ и https://openrouter.ai/api. /в1/. Я опробовал три бесплатные модели, во всех из которых указано, что нужно использовать базовый URL-адрес завершения.
Вот код, который я использую. Исключение возникает в последней строке.
String userKey = "";
String model = "mistralai/mistral-7b-instruct:free"; // tried two others
String baseURL = "https://openrouter.ai/api/v1/chat/completions/"; // tried https://openrouter.ai/api/v1/, https://api.openai.com/ works
ObjectMapper mapper = OpenAiService.defaultObjectMapper();
OkHttpClient client = OpenAiService.defaultClient(userKey, Duration.ofSeconds(30))
.newBuilder()
.build();
Retrofit retrofit = null;
try {
retrofit = OpenAiService.defaultRetrofit(client, mapper)
.newBuilder()
.baseUrl(new URL(baseURL))
.build();
} catch (MalformedURLException e) {
e.printStackTrace();
return;
}
OpenAiApi api = retrofit.create(OpenAiApi.class);
OpenAiService service = new OpenAiService(api);
CompletionRequest completionRequest = CompletionRequest.builder()
.model(model)
.prompt("Somebody once told me the world is gonna roll me")
.echo(true)
.user("testing")
.n(3)
.build();
service.createCompletion(completionRequest).getChoices().forEach(System.out::println); // HTTP 404
Подробнее здесь: https://stackoverflow.com/questions/784 ... openrouter