Skip to content

Commit

Permalink
Add helper initializers for content parts
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Feb 13, 2024
1 parent 97562b8 commit d77b933
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/main/java/io/github/stefanbratanov/jvm/openai/ChatMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ public String type() {

public record ImageUrl(String url, Optional<String> detail) {}
}

static TextContentPart textContentPart(String text) {
return new TextContentPart(text);
}

static ImageContentPart imageContentPart(String url) {
return new ImageContentPart(new ImageContentPart.ImageUrl(url, Optional.empty()));
}

static ImageContentPart imageContentPart(String url, String detail) {
return new ImageContentPart(new ImageContentPart.ImageUrl(url, Optional.of(detail)));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.stefanbratanov.jvm.openai;

import io.github.stefanbratanov.jvm.openai.ChatMessage.UserMessage.UserMessageWithContentParts.ContentPart;
import io.github.stefanbratanov.jvm.openai.ChatMessage.UserMessage.UserMessageWithContentParts.ContentPart.ImageContentPart;
import io.github.stefanbratanov.jvm.openai.CreateChatCompletionRequest.ResponseFormat;
import io.github.stefanbratanov.jvm.openai.ThreadMessage.Content.ImageFileContent;
import io.github.stefanbratanov.jvm.openai.ThreadMessage.Content.TextContent;
Expand Down Expand Up @@ -438,10 +437,10 @@ private ChatMessage randomChatMessage() {
randomInt(1, 5),
() ->
oneOf(
new ContentPart.TextContentPart(randomString(15)),
new ImageContentPart(
new ImageContentPart.ImageUrl(
randomString(7), Optional.of(oneOf("auto", "low", "high"))))),
ContentPart.textContentPart(randomString(15)),
ContentPart.imageContentPart(randomString(7)),
ContentPart.imageContentPart(
randomString(7), oneOf("auto", "low", "high"))),
ContentPart[]::new)),
ChatMessage.assistantMessage(randomString(10)),
ChatMessage.assistantMessage(
Expand Down

0 comments on commit d77b933

Please sign in to comment.