blob: 57339f6ad491aacda46d668d1bd97e807e9ddf96 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.llm.clients;
import ai.vespa.llm.InferenceParameters;
import ai.vespa.llm.completion.StringPrompt;
import com.yahoo.container.jdisc.SecretStoreProvider;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.Map;
public class OpenAITest {
private static final String apiKey = "<your-api-key>";
@Test
@Disabled
public void testOpenAIGeneration() {
var config = new LlmClientConfig.Builder().build();
var openai = new OpenAI(config, new SecretStoreProvider().get());
var options = Map.of(
"maxTokens", "10"
);
var prompt = StringPrompt.from("why are ducks better than cats?");
var future = openai.completeAsync(prompt, new InferenceParameters(apiKey, options::get), completion -> {
System.out.print(completion.text());
}).exceptionally(exception -> {
System.out.println("Error: " + exception);
return null;
});
future.join();
}
}
|