mirror of
https://github.com/amithkoujalgi/ollama4j.git
synced 2025-10-14 09:28:58 +02:00
Refactor integration tests and update Makefile targets
Refactored OllamaAPIIntegrationTest to simplify stream handlers and remove unused StringBuffer variables. Updated Makefile to ensure formatting is applied before running test targets. Adjusted logback.xml pattern to use full logger name for improved logging clarity.
This commit is contained in:
parent
300f1691e7
commit
ba3d8925f2
6
Makefile
6
Makefile
@ -23,15 +23,15 @@ full-build: apply-formatting
|
|||||||
@echo "\033[0;34mPerforming full build...\033[0m"
|
@echo "\033[0;34mPerforming full build...\033[0m"
|
||||||
@mvn -B clean install
|
@mvn -B clean install
|
||||||
|
|
||||||
unit-tests:
|
unit-tests: apply-formatting
|
||||||
@echo "\033[0;34mRunning unit tests...\033[0m"
|
@echo "\033[0;34mRunning unit tests...\033[0m"
|
||||||
@mvn clean test -Punit-tests
|
@mvn clean test -Punit-tests
|
||||||
|
|
||||||
integration-tests:
|
integration-tests: apply-formatting
|
||||||
@echo "\033[0;34mRunning integration tests (local)...\033[0m"
|
@echo "\033[0;34mRunning integration tests (local)...\033[0m"
|
||||||
@export USE_EXTERNAL_OLLAMA_HOST=false && mvn clean verify -Pintegration-tests
|
@export USE_EXTERNAL_OLLAMA_HOST=false && mvn clean verify -Pintegration-tests
|
||||||
|
|
||||||
integration-tests-remote:
|
integration-tests-remote: apply-formatting
|
||||||
@echo "\033[0;34mRunning integration tests (remote)...\033[0m"
|
@echo "\033[0;34mRunning integration tests (remote)...\033[0m"
|
||||||
@export USE_EXTERNAL_OLLAMA_HOST=true && export OLLAMA_HOST=http://192.168.29.229:11434 && mvn clean verify -Pintegration-tests -Dgpg.skip=true
|
@export USE_EXTERNAL_OLLAMA_HOST=true && export OLLAMA_HOST=http://192.168.29.229:11434 && mvn clean verify -Pintegration-tests -Dgpg.skip=true
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ import org.testcontainers.ollama.OllamaContainer;
|
|||||||
|
|
||||||
@OllamaToolService(providers = {AnnotatedTool.class})
|
@OllamaToolService(providers = {AnnotatedTool.class})
|
||||||
@TestMethodOrder(OrderAnnotation.class)
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
@SuppressWarnings({"HttpUrlsUsage", "SpellCheckingInspection"})
|
@SuppressWarnings({"HttpUrlsUsage", "SpellCheckingInspection", "FieldCanBeLocal", "ConstantValue"})
|
||||||
class OllamaAPIIntegrationTest {
|
class OllamaAPIIntegrationTest {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(OllamaAPIIntegrationTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(OllamaAPIIntegrationTest.class);
|
||||||
|
|
||||||
@ -105,11 +105,8 @@ class OllamaAPIIntegrationTest {
|
|||||||
@Order(1)
|
@Order(1)
|
||||||
void testVersionAPI()
|
void testVersionAPI()
|
||||||
throws URISyntaxException, IOException, OllamaBaseException, InterruptedException {
|
throws URISyntaxException, IOException, OllamaBaseException, InterruptedException {
|
||||||
// String expectedVersion = ollama.getDockerImageName().split(":")[1];
|
String version = api.getVersion();
|
||||||
String actualVersion = api.getVersion();
|
assertNotNull(version);
|
||||||
assertNotNull(actualVersion);
|
|
||||||
// assertEquals(expectedVersion, actualVersion, "Version should match the Docker
|
|
||||||
// image version");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -225,7 +222,6 @@ class OllamaAPIIntegrationTest {
|
|||||||
throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
|
throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
|
||||||
api.pullModel(GENERAL_PURPOSE_MODEL);
|
api.pullModel(GENERAL_PURPOSE_MODEL);
|
||||||
boolean raw = false;
|
boolean raw = false;
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
OllamaResult result =
|
OllamaResult result =
|
||||||
api.generate(
|
api.generate(
|
||||||
GENERAL_PURPOSE_MODEL,
|
GENERAL_PURPOSE_MODEL,
|
||||||
@ -233,15 +229,11 @@ class OllamaAPIIntegrationTest {
|
|||||||
+ " Lisa?",
|
+ " Lisa?",
|
||||||
raw,
|
raw,
|
||||||
new OptionsBuilder().build(),
|
new OptionsBuilder().build(),
|
||||||
(s) -> {
|
LOG::info);
|
||||||
LOG.info(s);
|
|
||||||
sb.append(s);
|
|
||||||
});
|
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertNotNull(result.getResponse());
|
assertNotNull(result.getResponse());
|
||||||
assertFalse(result.getResponse().isEmpty());
|
assertFalse(result.getResponse().isEmpty());
|
||||||
assertEquals(sb.toString(), result.getResponse());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -522,10 +514,10 @@ class OllamaAPIIntegrationTest {
|
|||||||
api.chat(
|
api.chat(
|
||||||
requestModel,
|
requestModel,
|
||||||
new OllamaChatStreamObserver(
|
new OllamaChatStreamObserver(
|
||||||
(s) -> {
|
s -> {
|
||||||
LOG.info(s.toUpperCase());
|
LOG.info(s.toUpperCase());
|
||||||
},
|
},
|
||||||
(s) -> {
|
s -> {
|
||||||
LOG.info(s.toLowerCase());
|
LOG.info(s.toLowerCase());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -670,10 +662,10 @@ class OllamaAPIIntegrationTest {
|
|||||||
api.chat(
|
api.chat(
|
||||||
requestModel,
|
requestModel,
|
||||||
new OllamaChatStreamObserver(
|
new OllamaChatStreamObserver(
|
||||||
(s) -> {
|
s -> {
|
||||||
LOG.info(s.toUpperCase());
|
LOG.info(s.toUpperCase());
|
||||||
},
|
},
|
||||||
(s) -> {
|
s -> {
|
||||||
LOG.info(s.toLowerCase());
|
LOG.info(s.toLowerCase());
|
||||||
}));
|
}));
|
||||||
assertNotNull(chatResult);
|
assertNotNull(chatResult);
|
||||||
@ -706,10 +698,10 @@ class OllamaAPIIntegrationTest {
|
|||||||
api.chat(
|
api.chat(
|
||||||
requestModel,
|
requestModel,
|
||||||
new OllamaChatStreamObserver(
|
new OllamaChatStreamObserver(
|
||||||
(s) -> {
|
s -> {
|
||||||
LOG.info(s.toUpperCase());
|
LOG.info(s.toUpperCase());
|
||||||
},
|
},
|
||||||
(s) -> {
|
s -> {
|
||||||
LOG.info(s.toLowerCase());
|
LOG.info(s.toLowerCase());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -827,8 +819,6 @@ class OllamaAPIIntegrationTest {
|
|||||||
|
|
||||||
File imageFile = getImageFileFromClasspath("roses.jpg");
|
File imageFile = getImageFileFromClasspath("roses.jpg");
|
||||||
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
|
|
||||||
OllamaResult result =
|
OllamaResult result =
|
||||||
api.generateWithImages(
|
api.generateWithImages(
|
||||||
VISION_MODEL,
|
VISION_MODEL,
|
||||||
@ -836,14 +826,10 @@ class OllamaAPIIntegrationTest {
|
|||||||
List.of(imageFile),
|
List.of(imageFile),
|
||||||
new OptionsBuilder().build(),
|
new OptionsBuilder().build(),
|
||||||
null,
|
null,
|
||||||
(s) -> {
|
LOG::info);
|
||||||
LOG.info(s);
|
|
||||||
sb.append(s);
|
|
||||||
});
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertNotNull(result.getResponse());
|
assertNotNull(result.getResponse());
|
||||||
assertFalse(result.getResponse().isEmpty());
|
assertFalse(result.getResponse().isEmpty());
|
||||||
assertEquals(sb.toString(), result.getResponse());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -874,30 +860,24 @@ class OllamaAPIIntegrationTest {
|
|||||||
void testGenerateWithThinkingAndStreamHandler()
|
void testGenerateWithThinkingAndStreamHandler()
|
||||||
throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
|
throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
|
||||||
api.pullModel(THINKING_TOOL_MODEL);
|
api.pullModel(THINKING_TOOL_MODEL);
|
||||||
|
|
||||||
boolean raw = false;
|
boolean raw = false;
|
||||||
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
OllamaResult result =
|
OllamaResult result =
|
||||||
api.generate(
|
api.generate(
|
||||||
THINKING_TOOL_MODEL,
|
THINKING_TOOL_MODEL,
|
||||||
"Who are you?",
|
"Who are you?",
|
||||||
raw,
|
raw,
|
||||||
new OptionsBuilder().build(),
|
new OptionsBuilder().build(),
|
||||||
(thinkingToken) -> {
|
thinkingToken -> {
|
||||||
sb.append(thinkingToken);
|
LOG.info(thinkingToken.toUpperCase());
|
||||||
LOG.info(thinkingToken);
|
|
||||||
},
|
},
|
||||||
(resToken) -> {
|
resToken -> {
|
||||||
sb.append(resToken);
|
LOG.info(resToken.toLowerCase());
|
||||||
LOG.info(resToken);
|
|
||||||
});
|
});
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertNotNull(result.getResponse());
|
assertNotNull(result.getResponse());
|
||||||
assertFalse(result.getResponse().isEmpty());
|
assertFalse(result.getResponse().isEmpty());
|
||||||
assertNotNull(result.getThinking());
|
assertNotNull(result.getThinking());
|
||||||
assertFalse(result.getThinking().isEmpty());
|
assertFalse(result.getThinking().isEmpty());
|
||||||
assertEquals(sb.toString(), result.getThinking() + result.getResponse());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getImageFileFromClasspath(String fileName) {
|
private File getImageFileFromClasspath(String fileName) {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %msg%n</pattern>
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger %msg%n</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user