Skip to content

Commit

Permalink
re #323 remove guava because that's not contained in Sling 12 anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
stoerr committed Mar 21, 2024
1 parent 475b7a0 commit ace6364
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
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

0 comments on commit ace6364

Please sign in to comment.