Skip to content

Commit

Permalink
Add openai-api built from openapi spec
Browse files Browse the repository at this point in the history
  • Loading branch information
tjake committed Aug 9, 2024
1 parent f145fba commit c887807
Show file tree
Hide file tree
Showing 21 changed files with 3,796 additions and 337 deletions.
34 changes: 0 additions & 34 deletions jlama-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,6 @@
<artifactId>JColor</artifactId>
<version>5.5.1</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>${resteasy.version}</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-undertow</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>me.dinowernli</groupId>
<artifactId>java-grpc-prometheus</artifactId>
<version>0.6.0</version>
</dependency>
<dependency>
<groupId>com.github.tjake</groupId>
<artifactId>jlama-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void main(String[] args) {
cli.addSubcommand("quantize", new QuantizeCommand());
cli.addSubcommand("chat", new ChatCommand());
cli.addSubcommand("complete", new CompleteCommand());
cli.addSubcommand("serve", new ServeCommand());
cli.addSubcommand("restapi", new ApiServiceCommand());
cli.addSubcommand("cluster-coordinator", new ClusterCoordinatorCommand());
cli.addSubcommand("cluster-worker", new ClusterWorkerCommand());

Expand Down
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@
*/
package com.github.tjake.jlama.cli.commands;

import static com.github.tjake.jlama.cli.commands.ServeCommand.APPLICATION_PATH;
import static io.undertow.Handlers.resource;

import com.github.tjake.jlama.cli.serve.JlamaRestApi;

import com.github.tjake.jlama.net.Coordinator;
import io.undertow.Undertow;
import io.undertow.server.handlers.resource.ClassPathResourceManager;
import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer;
import picocli.CommandLine;

@CommandLine.Command(
Expand Down Expand Up @@ -62,7 +57,7 @@ public void run() {
})
.start();

UndertowJaxrsServer ut = new UndertowJaxrsServer();
/*UndertowJaxrsServer ut = new UndertowJaxrsServer();
ut.deploy(new JlamaRestApi(c), APPLICATION_PATH);
ut.addResourcePrefixPath(
"/ui",
Expand All @@ -71,7 +66,7 @@ public void run() {
.addWelcomeFiles("index.html"));
System.out.println("Chat UI: http://localhost:" + port + "/ui/index.html");
ut.start(Undertow.builder().addHttpListener(port, "0.0.0.0"));
ut.start(Undertow.builder().addHttpListener(port, "0.0.0.0"));*/

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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit c887807

Please sign in to comment.