Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add openai-api built from openapi spec #43

Merged
merged 3 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 21 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 All @@ -85,6 +51,27 @@
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/static</outputDirectory>
<resources>
<resource>
<directory>src/main/webapp/</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</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() {
return m;
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/ui/**")
.addResourceLocations("classpath:/static/ui/");
}

@Override
public void run() {
try {
m = loadModel(
model,
workingDirectory,
workingMemoryType,
workingQuantizationType,
Optional.ofNullable(modelQuantization),
Optional.ofNullable(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", "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.

Loading
Loading