-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OPIK-611] support gemini models in playground (#987)
* OPIK-611 gemini infra * OPIK-611 get service gemini failing test * OPIK-611 get service gemini failing test green * OPIK-611 gemini e2e failing test * OPIK-611 gemini e2e failing test green [WIP - only create] * OPIK-611 refactor * OPIK-611 gemini e2e failing tests green * OPIK-611 refactor * OPIK-611 post rebase adjustments * OPIK-611 move client generation to a module * OPIK-611 anthropic mappers * OPIK-611 gemini mappers * OPIK-611 mappers coverage * OPIK-611 pr comments * OPIK-611 pr comments * OPIK-611 refactor * OPIK-611 minor fixes * OPIK-611 pr comments * OPIK-611 changed gemini model creation to map struct * OPIK-611 fix test
- Loading branch information
Showing
22 changed files
with
720 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...opik-backend/src/main/java/com/comet/opik/domain/llmproviders/ChunkedResponseHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.comet.opik.domain.llmproviders; | ||
|
||
import dev.ai4j.openai4j.chat.ChatCompletionChoice; | ||
import dev.ai4j.openai4j.chat.ChatCompletionResponse; | ||
import dev.ai4j.openai4j.chat.Delta; | ||
import dev.ai4j.openai4j.chat.Role; | ||
import dev.ai4j.openai4j.shared.Usage; | ||
import dev.langchain4j.data.message.AiMessage; | ||
import dev.langchain4j.model.StreamingResponseHandler; | ||
import dev.langchain4j.model.output.Response; | ||
import lombok.NonNull; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.Consumer; | ||
|
||
public record ChunkedResponseHandler( | ||
@NonNull Consumer<ChatCompletionResponse> handleMessage, | ||
@NonNull Runnable handleClose, | ||
@NonNull Consumer<Throwable> handleError, | ||
@NonNull String model) implements StreamingResponseHandler<AiMessage> { | ||
|
||
@Override | ||
public void onNext(@NonNull String content) { | ||
handleMessage.accept(ChatCompletionResponse.builder() | ||
.model(model) | ||
.choices(List.of(ChatCompletionChoice.builder() | ||
.delta(Delta.builder() | ||
.content(content) | ||
.role(Role.ASSISTANT) | ||
.build()) | ||
.build())) | ||
.build()); | ||
} | ||
|
||
@Override | ||
public void onComplete(@NonNull Response<AiMessage> response) { | ||
handleMessage.accept(ChatCompletionResponse.builder() | ||
.model(model) | ||
.choices(List.of(ChatCompletionChoice.builder() | ||
.delta(Delta.builder() | ||
.content("") | ||
.role(Role.ASSISTANT) | ||
.build()) | ||
.build())) | ||
.usage(Usage.builder() | ||
.promptTokens(response.tokenUsage().inputTokenCount()) | ||
.completionTokens(response.tokenUsage().outputTokenCount()) | ||
.totalTokens(response.tokenUsage().totalTokenCount()) | ||
.build()) | ||
.id(Optional.ofNullable(response.metadata().get("id")).map(Object::toString).orElse(null)) | ||
.build()); | ||
handleClose.run(); | ||
} | ||
|
||
@Override | ||
public void onError(@NonNull Throwable throwable) { | ||
handleError.accept(throwable); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
apps/opik-backend/src/main/java/com/comet/opik/domain/llmproviders/GeminiModelName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.comet.opik.domain.llmproviders; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
/* | ||
Langchain4j doesn't provide gemini models enum. | ||
This information is taken from: https://ai.google.dev/gemini-api/docs/models/gemini | ||
*/ | ||
@RequiredArgsConstructor | ||
public enum GeminiModelName { | ||
GEMINI_2_0_FLASH("gemini-2.0-flash-exp"), | ||
GEMINI_1_5_FLASH("gemini-1.5-flash"), | ||
GEMINI_1_5_FLASH_8B("gemini-1.5-flash-8b"), | ||
GEMINI_1_5_PRO("gemini-1.5-pro"), | ||
GEMINI_1_0_PRO("gemini-1.0-pro"), | ||
TEXT_EMBEDDING("text-embedding-004"), | ||
AQA("aqa"); | ||
|
||
private final String value; | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.