Skip to content

Commit

Permalink
fix: add api key auth (ollama)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlrobertoh committed Sep 5, 2024
1 parent 2722590 commit 6d71485
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/ee/carlrobert/llm/client/ollama/OllamaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,15 @@ private void processStreamRequest(
private HttpRequest buildPostHttpRequest(
Object request,
String path) throws JsonProcessingException {
return HttpRequest.newBuilder(URI.create(BASE_URL + path))
var requestBuilder = HttpRequest.newBuilder(URI.create(BASE_URL + path))
.POST(HttpRequest.BodyPublishers.ofString(new ObjectMapper().writeValueAsString(request)))
.header("Content-Type", "application/json")
.timeout(Duration.ofSeconds(30))
.header("Content-Type", "application/x-ndjson");

if (apiKey != null) {
requestBuilder.header("Authorization", "Bearer " + apiKey);
}

return requestBuilder.timeout(Duration.ofSeconds(30))
.build();
}

Expand Down

0 comments on commit 6d71485

Please sign in to comment.