Deprecated Client#completion and removed redundant question parameter

This commit is contained in:
extio-de
2025-06-27 17:35:48 +02:00
parent 5b5f56fa15
commit bef3ef1468
9 changed files with 29 additions and 86 deletions

View File

@@ -5,7 +5,11 @@ import de.extio.lmlib.profile.ModelProfile.ModelProvider;
public interface Client {
Completion completion(ModelCategory modelCategory, String system, String question, String fullText);
/**
* @deprecated use {@link #conversation(ModelCategory, Conversation)} instead. Conversation can be converted from a system and text by Conversation.create(system, text)
*/
@Deprecated
Completion completion(ModelCategory modelCategory, String system, String text);
Completion conversation(ModelCategory modelCategory, Conversation conversation);

View File

@@ -50,8 +50,8 @@ public class ClientService {
}
@Override
public Completion completion(final ModelCategory modelCategory, final String system, final String question, final String fullText) {
return this.client.completion(modelCategory, system, question, fullText);
public Completion completion(final ModelCategory modelCategory, final String system, final String text) {
return this.client.completion(modelCategory, system, text);
}
@Override

View File

@@ -90,21 +90,7 @@ public final class AzureAiClient implements Client {
}
@Override
public Completion completion(final ModelCategory modelCategory, final String system, final String question, final String fullText) {
String text = "";
if (!question.isEmpty() && !fullText.isEmpty()) {
text = question + "\n" + fullText;
}
else if (!question.isEmpty()) {
text = question;
}
else if (!fullText.isEmpty()) {
text = fullText;
}
else {
throw new IllegalArgumentException("Either question or fullText must be set");
}
public Completion completion(final ModelCategory modelCategory, final String system, final String text) {
return this.conversation(modelCategory, Conversation.create(system, text));
}

View File

@@ -31,8 +31,8 @@ public class CachedClient implements Client {
}
@Override
public Completion completion(final ModelCategory modelCategory, final String system, final String question, final String fullText) {
return this.getCachedResponse(modelCategory, () -> this.client.completion(modelCategory, system, question, fullText), system, question, fullText);
public Completion completion(final ModelCategory modelCategory, final String system, final String text) {
return this.getCachedResponse(modelCategory, () -> this.client.completion(modelCategory, system, text), system, text);
}
@Override

View File

@@ -68,21 +68,7 @@ public class TextCompletionClient implements Client, DisposableBean {
}
@Override
public Completion completion(final ModelCategory modelCategory, final String system, final String question, final String fullText) {
String text = "";
if (!question.isEmpty() && !fullText.isEmpty()) {
text = question + "\n" + fullText;
}
else if (!question.isEmpty()) {
text = question;
}
else if (!fullText.isEmpty()) {
text = fullText;
}
else {
throw new IllegalArgumentException("Either question or fullText must be set");
}
public Completion completion(final ModelCategory modelCategory, final String system, final String text) {
return this.conversation(modelCategory, Conversation.create(system, text));
}

View File

@@ -3,17 +3,21 @@ package de.extio.lmlib.grader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.extio.lmlib.client.Client;
import de.extio.lmlib.client.ClientService;
import de.extio.lmlib.profile.ModelCategory;
public class Grader {
private static final Logger LOGGER = LoggerFactory.getLogger(Grader.class);
private static final Logger LOGGER = LoggerFactory.getLogger(Grader.class);
public static boolean assessScoreBinary(final String question, final String text, final ClientService clientService) {
LOGGER.info(question);
final var client = clientService.getClient(ModelCategory.MEDIUM);
return assessScoreBinary(question, text, client);
}
public static boolean assessScoreBinary(final String question, final String text, final Client client) {
LOGGER.info(question);
var score = 0;
while (Math.abs(score) < 3) {
@@ -24,8 +28,8 @@ public class Grader {
Please provide a binary response 'true' or 'false' for the following text.
'true' means that the text provides a truthful answer to the question, while 'false' means that it does not.
Only provide the response as a single word and no preamble and no explanation.""",
"Here is the text:\n" + text,
"\nHere is the user question: " + question);
"Here is the text:\n" + text + "\n\n" +
"Here is the user question: " + question);
LOGGER.info(completion.response());
score += Boolean.parseBoolean(completion.response().strip()) ? 1 : -1;
if (Math.abs(score) == 2) {