-
Notifications
You must be signed in to change notification settings - Fork 7
/
AzureOpenAiChatCompletionsChainIT.java
57 lines (44 loc) · 2.09 KB
/
AzureOpenAiChatCompletionsChainIT.java
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
52
53
54
55
56
57
package io.github.cupybara.javalangchains.chains.llm.azure.chat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collections;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Test;
import io.github.cupybara.javalangchains.chains.Chain;
import io.github.cupybara.javalangchains.chains.llm.openai.chat.OpenAiChatCompletionsParameters;
/**
* Integration Tests for the {@link AzureOpenAiChatCompletionsChain}
*/
class AzureOpenAiChatCompletionsChainIT {
private static final Logger LOGGER = LogManager.getLogger();
@Test
void testRun() {
final AzureOpenAiChatCompletionsChain chain = new AzureOpenAiChatCompletionsChain(
"my-azure-resource-name", "gpt-35-turbo", "2023-05-15",
"Hello, this is ${name}. What was my name again?",
new OpenAiChatCompletionsParameters(), System.getenv("AZURE_OPENAI_API_KEY"));
final String name = "Manuel";
final String result = chain.run(Collections.singletonMap("name", name));
LOGGER.info(result);
assertNotNull(result, "got no result from OpenAiChatCompletionsChain");
assertTrue(result.contains(name), "The answer did not contain the name");
}
@Test
void testChainedRun() {
final OpenAiChatCompletionsParameters parameters = new OpenAiChatCompletionsParameters();
final Chain<Map<String, String>, String> chain = new AzureOpenAiChatCompletionsChain(
"my-azure-resource-name", "gpt-35-turbo", "2023-05-15",
"Hello, this is ${name}. What was my name again?",
parameters, System.getenv("AZURE_OPENAI_API_KEY"))
.chain(prev -> Collections.singletonMap("result", prev))
.chain(new AzureOpenAiChatCompletionsChain(
"my-azure-resource-name", "gpt-35-turbo", "2023-05-15",
"What was the question for the following answer: ${result}",
parameters, System.getenv("AZURE_OPENAI_API_KEY")));
final String result = chain.run(Collections.singletonMap("name", "Manuel"));
LOGGER.info(result);
assertNotNull(result, "got no result from chain");
}
}