Deprecated Client#completion and removed redundant question parameter
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -33,8 +33,7 @@ public class AzureAiClientTest {
|
||||
final var completion = this.client.completion(
|
||||
ModelCategory.MEDIUM,
|
||||
"You are a clever story teller",
|
||||
"Continue this story:",
|
||||
"Once upon a time, there was a spaceship travelling to a black hole. The crew were cats!");
|
||||
"Continue this story:\nOnce upon a time, there was a spaceship travelling to a black hole. The crew were cats!");
|
||||
LOGGER.info(completion.toString());
|
||||
}
|
||||
|
||||
@@ -43,8 +42,7 @@ public class AzureAiClientTest {
|
||||
final var completion = this.client.completion(
|
||||
ModelCategory.LARGE,
|
||||
"You are a clever story teller",
|
||||
"Continue this story:",
|
||||
"Once upon a time, there was a spaceship travelling to a black hole. The crew were cats!");
|
||||
"Continue this story:\nOnce upon a time, there was a spaceship travelling to a black hole. The crew were cats!");
|
||||
LOGGER.info(completion.response());
|
||||
}
|
||||
|
||||
@@ -64,7 +62,6 @@ public class AzureAiClientTest {
|
||||
final var completion = this.client.completion(
|
||||
null,
|
||||
"You are a helpful assistant",
|
||||
"",
|
||||
"Count the numbers: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4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 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9");
|
||||
LOGGER.info(completion.response());
|
||||
}
|
||||
|
||||
@@ -48,8 +48,7 @@ public class CachedClientTest {
|
||||
var completion = this.clientService.getClient(ModelCategory.MEDIUM).completion(
|
||||
ModelCategory.MEDIUM,
|
||||
"You are a funny person",
|
||||
"Tell me a cat joke",
|
||||
"");
|
||||
"Tell me a cat joke");
|
||||
LOGGER.info(completion.toString());
|
||||
assertFalse(completion.cached());
|
||||
assertEquals(1, completion.requests());
|
||||
@@ -59,8 +58,7 @@ public class CachedClientTest {
|
||||
completion = this.clientService.getClient(ModelCategory.MEDIUM).completion(
|
||||
ModelCategory.MEDIUM,
|
||||
"You are a funny person",
|
||||
"Tell me a cat joke",
|
||||
"");
|
||||
"Tell me a cat joke");
|
||||
LOGGER.info(completion.toString());
|
||||
assertTrue(completion.cached());
|
||||
assertEquals(0, completion.requests());
|
||||
@@ -69,8 +67,7 @@ public class CachedClientTest {
|
||||
completion = this.clientService.getClient(ModelCategory.MEDIUM).completion(
|
||||
ModelCategory.MEDIUM,
|
||||
"You are a funny person",
|
||||
"Tell me a dog joke",
|
||||
"");
|
||||
"Tell me a dog joke");
|
||||
LOGGER.info(completion.toString());
|
||||
assertFalse(completion.cached());
|
||||
assertEquals(1, completion.requests());
|
||||
|
||||
@@ -22,6 +22,7 @@ import de.extio.lmlib.client.Conversation;
|
||||
import de.extio.lmlib.client.Conversation.Turn;
|
||||
import de.extio.lmlib.client.Conversation.TurnType;
|
||||
import de.extio.lmlib.client.oai.textcompletion.TextCompletionClient;
|
||||
import de.extio.lmlib.grader.Grader;
|
||||
import de.extio.lmlib.profile.ModelCategory;
|
||||
|
||||
//@Disabled("This test requires a running Llama server")
|
||||
@@ -41,12 +42,11 @@ public class TextCompletionClientTest {
|
||||
final var completion = this.client.completion(
|
||||
null,
|
||||
"You are a helpful assistant",
|
||||
"",
|
||||
"Say the color is green");
|
||||
|
||||
LOGGER.info(completion.response());
|
||||
|
||||
assertTrue(this.assessScoreBinary("Does the text mention the color green?", completion.response()));
|
||||
assertTrue(Grader.assessScoreBinary("Does the text mention the color green?", completion.response(), this.client));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,7 +58,7 @@ public class TextCompletionClientTest {
|
||||
|
||||
LOGGER.info(completion.response());
|
||||
|
||||
assertTrue(this.assessScoreBinary("Does the text mention a color?", completion.response()));
|
||||
assertTrue(Grader.assessScoreBinary("Does the text mention a color?", completion.response(), this.client));
|
||||
}
|
||||
|
||||
@Disabled
|
||||
@@ -74,8 +74,7 @@ public class TextCompletionClientTest {
|
||||
final var completion = this.client.completion(
|
||||
null,
|
||||
"You are counting machine",
|
||||
"How many numbers do you count?",
|
||||
sb.toString());
|
||||
"How many numbers do you count?\n" + sb.toString());
|
||||
LOGGER.info(completion.response());
|
||||
}
|
||||
|
||||
@@ -123,7 +122,6 @@ public class TextCompletionClientTest {
|
||||
final var completion = this.client.completion(
|
||||
null,
|
||||
"You are a helpful assistant",
|
||||
"",
|
||||
"How do I calculate the annual profit margin?");
|
||||
LOGGER.info(completion.response());
|
||||
}
|
||||
@@ -135,7 +133,6 @@ public class TextCompletionClientTest {
|
||||
final var completion = this.client.completion(
|
||||
null,
|
||||
"You are a helpful assistant",
|
||||
"",
|
||||
"How do I calculate the operating profit ratio?");
|
||||
LOGGER.info(completion.response());
|
||||
}
|
||||
@@ -147,7 +144,6 @@ public class TextCompletionClientTest {
|
||||
final var completion = this.client.completion(
|
||||
null,
|
||||
"You are a helpful assistant",
|
||||
"",
|
||||
"How do I calculate the return of investment?");
|
||||
LOGGER.info(completion.response());
|
||||
}
|
||||
@@ -159,7 +155,6 @@ public class TextCompletionClientTest {
|
||||
final var completion = this.client.completion(
|
||||
null,
|
||||
"You are a helpful assistant",
|
||||
"",
|
||||
"How do I calculate the return on net worth?");
|
||||
LOGGER.info(completion.response());
|
||||
}
|
||||
@@ -171,30 +166,4 @@ public class TextCompletionClientTest {
|
||||
|
||||
static record Tasks(Runnable task1, Runnable task2, Runnable task3, Runnable task4) {
|
||||
}
|
||||
|
||||
private boolean assessScoreBinary(final String question, final String text) {
|
||||
LOGGER.info(question);
|
||||
|
||||
var score = 0;
|
||||
while (Math.abs(score) < 3) {
|
||||
final var completion = this.client.completion(
|
||||
ModelCategory.MEDIUM,
|
||||
"""
|
||||
You are a grader assessing the truthfulness of a given text to a user question.
|
||||
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);
|
||||
LOGGER.info(completion.response());
|
||||
score += Boolean.parseBoolean(completion.response().strip()) ? 1 : -1;
|
||||
if (Math.abs(score) == 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final var result = score > 0;
|
||||
LOGGER.info("->" + String.valueOf(result));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user