Skip to content

Commit

Permalink
Merge pull request #76 from tjake/fix-port
Browse files Browse the repository at this point in the history
Fix port
  • Loading branch information
tjake authored Oct 17, 2024
2 parents 6d3ab99 + 1864a0e commit 657ee0f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: Unit Test CI

on:
pull_request:
types: [ opened, synchronize, reopened ]
workflow_dispatch:
push:
branches:
- main
paths:
- .github/workflows/unit-tests.yaml
- '**.java'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import static com.github.tjake.jlama.model.ModelSupport.loadModel;

import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import com.github.tjake.jlama.model.functions.Generator;
Expand All @@ -26,8 +28,14 @@
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import picocli.CommandLine;
Expand Down Expand Up @@ -59,29 +67,36 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
public void run() {
try {
Path modelPath = SimpleBaseCommand.getModel(
modelName,
modelDirectory,
downloadSection.autoDownload,
downloadSection.branch,
downloadSection.authToken
);
modelName,
modelDirectory,
downloadSection.autoDownload,
downloadSection.branch,
downloadSection.authToken);

m = loadModel(
modelPath.toFile(),
workingDirectory,
advancedSection.workingMemoryType,
advancedSection.workingQuantizationType,
Optional.ofNullable(advancedSection.modelQuantization),
Optional.ofNullable(advancedSection.threadCount)
);
modelPath.toFile(),
workingDirectory,
advancedSection.workingMemoryType,
advancedSection.workingQuantizationType,
Optional.ofNullable(advancedSection.modelQuantization),
Optional.ofNullable(advancedSection.threadCount));

System.out.println("Chat UI: http://localhost:" + port);
System.out.println("OpenAI Chat API: http://localhost:" + port + "/chat/completions");

new SpringApplicationBuilder(ApiServiceCommand.class).lazyInitialization(true)
.properties("server.port", "" + port, "logging.level.org.springframework.web", "info")
.build()
.run();
// Use SpringApplicationBuilder with ApplicationContextInitializer to set the port dynamically
new SpringApplicationBuilder(ApiServiceCommand.class)
.initializers(applicationContext -> {
ConfigurableEnvironment environment = applicationContext.getEnvironment();
Map<String, Object> props = new HashMap<>();
props.put("server.port", port); // Set the port here before the server starts
environment.getPropertySources().addFirst(new MapPropertySource("customProps", props));
})
.properties("logging.level.org.springframework.web", "info")
.lazyInitialization(true)
.build()
.run();

} catch (Exception e) {
e.printStackTrace();
System.exit(2);
Expand Down

0 comments on commit 657ee0f

Please sign in to comment.