forked from Mirror/ollama4j
		
	Refactor stream handler and update test model usage
Simplified ConsoleOutputStreamHandler to print messages directly without substring logic. Updated WithAuth integration test to use the THINKING_MODEL ('gpt-oss:20b') instead of GENERAL_PURPOSE_MODEL ('gemma3:270m') for model pulling and generation.
			
			
This commit is contained in:
		@@ -3,12 +3,8 @@ package io.github.ollama4j.impl;
 | 
				
			|||||||
import io.github.ollama4j.models.generate.OllamaStreamHandler;
 | 
					import io.github.ollama4j.models.generate.OllamaStreamHandler;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class ConsoleOutputStreamHandler implements OllamaStreamHandler {
 | 
					public class ConsoleOutputStreamHandler implements OllamaStreamHandler {
 | 
				
			||||||
    private final StringBuffer response = new StringBuffer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void accept(String message) {
 | 
					    public void accept(String message) {
 | 
				
			||||||
        String substr = message.substring(response.length());
 | 
					        System.out.print(message);
 | 
				
			||||||
        response.append(substr);
 | 
					 | 
				
			||||||
        System.out.print(substr);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,6 +44,7 @@ public class WithAuth {
 | 
				
			|||||||
    private static final String BEARER_AUTH_TOKEN = "secret-token";
 | 
					    private static final String BEARER_AUTH_TOKEN = "secret-token";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static final String GENERAL_PURPOSE_MODEL = "gemma3:270m";
 | 
					    private static final String GENERAL_PURPOSE_MODEL = "gemma3:270m";
 | 
				
			||||||
 | 
					    private static final String THINKING_MODEL = "gpt-oss:20b";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static OllamaContainer ollama;
 | 
					    private static OllamaContainer ollama;
 | 
				
			||||||
@@ -152,7 +153,7 @@ public class WithAuth {
 | 
				
			|||||||
            throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
 | 
					            throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
 | 
				
			||||||
        api.setBearerAuth(BEARER_AUTH_TOKEN);
 | 
					        api.setBearerAuth(BEARER_AUTH_TOKEN);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        api.pullModel(GENERAL_PURPOSE_MODEL);
 | 
					        api.pullModel(THINKING_MODEL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        String prompt = "The sun is shining brightly and is directly overhead at the zenith, casting my shadow over my foot, so it must be noon.";
 | 
					        String prompt = "The sun is shining brightly and is directly overhead at the zenith, casting my shadow over my foot, so it must be noon.";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -169,7 +170,7 @@ public class WithAuth {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
        format.put("required", List.of("isNoon"));
 | 
					        format.put("required", List.of("isNoon"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        OllamaResult result = api.generate(GENERAL_PURPOSE_MODEL, prompt, format);
 | 
					        OllamaResult result = api.generate(THINKING_MODEL, prompt, format);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        assertNotNull(result);
 | 
					        assertNotNull(result);
 | 
				
			||||||
        assertNotNull(result.getResponse());
 | 
					        assertNotNull(result.getResponse());
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user