-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add openai-api built from openapi spec
- Loading branch information
Showing
21 changed files
with
3,796 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
jlama-cli/src/main/java/com/github/tjake/jlama/cli/commands/ApiServiceCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2024 T Jake Luciani | ||
* | ||
* The Jlama Project licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.github.tjake.jlama.cli.commands; | ||
|
||
import com.github.tjake.jlama.model.AbstractModel; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.SpringBootConfiguration; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import picocli.CommandLine; | ||
|
||
import java.util.Optional; | ||
|
||
import static com.github.tjake.jlama.model.ModelSupport.loadModel; | ||
|
||
@CommandLine.Command(name = "restapi", description = "Starts a openai compatible rest api for interacting with this model") | ||
@SpringBootApplication(scanBasePackages = {"com.github.tjake.jlama.net.openai", "com.github.tjake.jlama.cli.commands"}) | ||
@SpringBootConfiguration | ||
@Configuration | ||
public class ApiServiceCommand extends BaseCommand implements WebMvcConfigurer { | ||
private static final Logger logger = LoggerFactory.getLogger(ApiServiceCommand.class); | ||
|
||
@CommandLine.Option( | ||
names = {"-p", "--port"}, | ||
description = "http port (default: ${DEFAULT-VALUE})", | ||
defaultValue = "8080") | ||
int port = 8080; | ||
|
||
static volatile AbstractModel m; | ||
|
||
@Bean | ||
public AbstractModel getModelBean() { | ||
logger.info("Here! {}", m); | ||
return m; | ||
} | ||
|
||
@Override | ||
public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||
registry.addResourceHandler("/ui/**") | ||
.addResourceLocations("/resources/"); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
m = loadModel( | ||
model, | ||
workingDirectory, | ||
workingMemoryType, | ||
workingQuantizationType, | ||
Optional.ofNullable(modelQuantization), | ||
Optional.ofNullable(threadCount)); | ||
|
||
logger.info("m = {}", m); | ||
|
||
System.out.println("Chat UI: http://localhost:" + port + "/ui/index.html"); | ||
|
||
new SpringApplicationBuilder(ApiServiceCommand.class) | ||
.lazyInitialization(true) | ||
.properties("server.port", ""+port, "logging.level.org.springframework.web", "debug") | ||
.build() | ||
.run(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
System.exit(2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
jlama-cli/src/main/java/com/github/tjake/jlama/cli/commands/ServeCommand.java
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
jlama-cli/src/main/java/com/github/tjake/jlama/cli/serve/EmbedResource.java
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
jlama-cli/src/main/java/com/github/tjake/jlama/cli/serve/GenerateParams.java
This file was deleted.
Oops, something went wrong.
78 changes: 0 additions & 78 deletions
78
jlama-cli/src/main/java/com/github/tjake/jlama/cli/serve/GenerateResource.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.