aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/ai/vespa/llm/test/MockLanguageModel.java
blob: db1b42fbbac44d332f7912a13922002beb8ae607 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.llm.test;

import ai.vespa.llm.LanguageModel;
import ai.vespa.llm.completion.Completion;
import ai.vespa.llm.completion.Prompt;
import com.yahoo.api.annotations.Beta;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * @author bratseth
 */
@Beta
public class MockLanguageModel implements LanguageModel {

    private final Function<Prompt, List<Completion>> completer;

    public MockLanguageModel(Builder builder) {
        completer = builder.completer;
    }

    @Override
    public List<Completion> complete(Prompt prompt) {
        return completer.apply(prompt);
    }

    @Override
    public CompletableFuture<Completion.FinishReason> completeAsync(Prompt prompt, Consumer<Completion> action) {
        throw new RuntimeException("Not implemented");
    }

    public static class Builder {

        private Function<Prompt, List<Completion>> completer = prompt -> List.of(Completion.from(""));

        public Builder completer(Function<Prompt, List<Completion>> completer) {
            this.completer = completer;
            return this;
        }

        public Builder() {}

        public MockLanguageModel build() { return new MockLanguageModel(this); }

    }

}