@Test
    public void testCompletion() {
        Function<Prompt, List<Completion>> completer = in ->
            switch (in.asString()) {
                case "Complete this: " -> List.of(Completion.from("The completion"));
                default -> throw new RuntimeException("Cannot complete '" + in + "'");
        };
        var llm = new MockLanguageModel.Builder().completer(completer).build();

        String input = "Complete this: ";
        StringPrompt prompt = StringPrompt.from(input);
        InferenceParameters options = new InferenceParameters(s -> "");
        for (int i = 0; i < 10; i++) {
            var completion = llm.complete(prompt, options).get(0);
            prompt = prompt.append(completion);
            if (completion.finishReason() == Completion.FinishReason.stop) break;
        }
        assertEquals("Complete this: The completion", prompt.asString());
    }
Tests completion with a mock completer.

@author bratseth
vespajlib/src/test/java/ai/vespa/llm/completion/CompletionTest.java