-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OPIK-611] support gemini models in playground #987
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9808016
OPIK-611 gemini infra
idoberko2 fa8923e
OPIK-611 get service gemini failing test
idoberko2 95f736e
OPIK-611 get service gemini failing test green
idoberko2 56fddcd
OPIK-611 gemini e2e failing test
idoberko2 cba5773
OPIK-611 gemini e2e failing test green [WIP - only create]
idoberko2 f99d3c7
OPIK-611 refactor
idoberko2 fb16a15
OPIK-611 gemini e2e failing tests green
idoberko2 5ffa213
OPIK-611 refactor
idoberko2 e652cdb
OPIK-611 post rebase adjustments
idoberko2 676fa76
OPIK-611 move client generation to a module
idoberko2 c2fa7ad
OPIK-611 anthropic mappers
idoberko2 5f364f2
OPIK-611 gemini mappers
idoberko2 959f130
OPIK-611 mappers coverage
idoberko2 44304b9
OPIK-611 pr comments
idoberko2 1c46000
OPIK-611 pr comments
idoberko2 4d69881
OPIK-611 refactor
idoberko2 db57fa6
OPIK-611 minor fixes
idoberko2 138ca1b
OPIK-611 pr comments
idoberko2 46fc67f
OPIK-611 changed gemini model creation to map struct
idoberko2 396c28c
OPIK-611 fix test
idoberko2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure these values are as complete as possible and also aligned with the FrontEnd choices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I double checked against the gemini documentation (link in comments). Will update the FE ticket accordingly.