Skip to content
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

re #323 remove guava because that's not contained in Sling 12 anymore. #324

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,6 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<!-- HTTP -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -39,7 +40,6 @@
import org.slf4j.LoggerFactory;

import com.composum.sling.nodes.ai.AIService;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;

@Component(
Expand Down Expand Up @@ -76,17 +76,25 @@ public String prompt(@Nullable String systemmsg, @Nonnull String usermsg, @Nulla
if (!isAvailable()) {
throw new AIServiceNotAvailableException();
}
Map<String, Object> systemMessage = systemmsg != null ?
ImmutableMap.of("role", "system", "content", systemmsg) : null;

Map<String, String> userMessage = ImmutableMap.of("role", "user", "content", usermsg);
Map<String, String> userMessage = new LinkedHashMap<>();
userMessage.put("role", "user");
userMessage.put("content", usermsg);

Map<String, Object> request = new HashMap<>();
request.put("model", StringUtils.defaultString(config.defaultModel(), DEFAULT_MODEL));
request.put("messages", systemMessage != null ? asList(systemMessage, userMessage) : asList(userMessage));
if (systemmsg != null) {
Map<String, Object> systemMessage = new LinkedHashMap<>();
systemMessage.put("role", "system");
systemMessage.put("content", systemmsg);
request.put("messages", asList(systemMessage, userMessage));
} else {
request.put("messages", asList(userMessage));
}
request.put("temperature", 0);
if (responseFormat == ResponseFormat.JSON) {
request.put("response_format", ImmutableMap.of("type", "json_object"));
Map<String, String> responseFormatMap = new LinkedHashMap<>();
responseFormatMap.put("type", "json_object");
request.put("response_format", responseFormatMap);
}

String requestJson = gson.toJson(request);
Expand Down
Loading