Skip to content

Commit

Permalink
Merge pull request #45 from phillip-kruger/main
Browse files Browse the repository at this point in the history
Allow OpenAI custom server
  • Loading branch information
phillip-kruger authored Sep 12, 2024
2 parents fe9445f + af574c6 commit d52aa7e
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 28 deletions.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension to you project, example in maven:

Chappie is a Dev Mode only extension, so this does not add anything to your production application.

To use chappie, you need to configure it with either an OpenAI Api Key or have Ollama running locally.
To use chappie, you need to configure it with either an OpenAI Compatible Service or have Ollama running locally.

## Using OpenAI
To use OpenAI you need to provide an [OpenAI Api Key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key)
Expand All @@ -29,10 +29,35 @@ Example:
mvn quarkus:dev -Dquarkus.assistant.openai.api-key=sk....
```

## Using Podman Desktop AI
You can use Podman Desktop AI by setting the openai base-url and the api key to a dummy value.

Example:

```
mvn quarkus:dev -Dquarkus.assistant.openai.api-key=sk-dummy -Dquarkus.assistant.openai.base-url=http://localhost:46311/v1 -Dquarkus.assistant.openai.model-name=instructlab/granite-7b-lab-GGUF
```

Change the values to your own setup.

# Using MAAS

You can also use [Models as a Service on OpenShift AI](https://maas.apps.prod.rhoai.rh-aiservices-bu.com/)

Example:

```
mvn quarkus:dev -Dquarkus.assistant.openai.api-key=your-key-here -Dquarkus.assistant.openai.base-url=quarkus.assistant.openai.base-url=https://granite-8b-code-instruct-maas-apicast-production.apps.prod.rhoai.rh-aiservices-bu.com:443/v1 -Dquarkus.assistant.openai.model-name=granite-8b-code-instruct-128k
```

Change the values to your own setup.

## Using Ollama
To use Ollama you need to install and run ollama. See [ollama.com/download](https://ollama.com/download)

By default, Ollama will use the `codellama` model. You can configure this with `quarkus.assistant.ollama.model-name` property, example:
By default, Ollama will use the `codellama` model. You can configure this with `quarkus.assistant.ollama.model-name` property.

Example:

```
quarkus.assistant.ollama.model-name=instructlab/granite-7b-lab
Expand Down
2 changes: 1 addition & 1 deletion deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<name>Quarkus Chappie - Deployment</name>

<properties>
<chappie-server.version>0.0.12</chappie-server.version>
<chappie-server.version>0.0.13</chappie-server.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void pages(List<ChappiePageBuildItem> chappiePageBuildItems,
BuildProducer<CardPageBuildItem> cardPageProducer,
ChappieConfig config) {

if (config.openai().apiKey().isPresent()) {
if (config.openai().apiKey().isPresent() || config.openai().baseUrl().isPresent()) {
configuredOpenAiPage(chappiePageBuildItems, cardPageProducer, config);
} else if (ollamaBuildItem.isPresent()) {
configuredOllamaPage(chappiePageBuildItems, cardPageProducer, config);
Expand All @@ -32,7 +32,9 @@ void pages(List<ChappiePageBuildItem> chappiePageBuildItems,
private void configuredOpenAiPage(List<ChappiePageBuildItem> chappiePageBuildItems,
BuildProducer<CardPageBuildItem> cardPageProducer,
ChappieConfig config) {
configuredPage(chappiePageBuildItems, cardPageProducer, "OpenAI", config.openai().modelName());

configuredPage(chappiePageBuildItems, cardPageProducer, "OpenAI ",
config.openai().baseUrl().orElse(config.openai().modelName()));
}

private void configuredOllamaPage(List<ChappiePageBuildItem> chappiePageBuildItems,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void createContainer(BuildProducer<DevServicesResultBuildItem> devService
Optional<OllamaBuildItem> ollamaBuildItem,
ChappieConfig config) {

if (process == null && (config.openai().apiKey().isPresent() || ollamaBuildItem.isPresent())) {
if (process == null && (config.openai().apiKey().isPresent() || config.openai().baseUrl().isPresent()
|| ollamaBuildItem.isPresent())) {

Map<String, String> properties = new HashMap<>();
int port = findAvailablePort(4315);
Expand All @@ -54,14 +55,25 @@ public void createContainer(BuildProducer<DevServicesResultBuildItem> devService
properties.put("quarkus.http.host", "localhost");
properties.put("quarkus.http.port", String.valueOf(port));

if (config.openai().apiKey().isPresent()) {
properties.put("chappie.openai.api-key", config.openai().apiKey().get());
if (config.devservices().log()) {
properties.put("chappie.log.request", "true");
properties.put("chappie.log.response", "true");
}

properties.put("chappie.timeout", config.devservices().timeout());
if (config.openai().apiKey().isPresent() || config.openai().baseUrl().isPresent()) {
config.openai().apiKey().ifPresent((t) -> {
properties.put("chappie.openai.api-key", t);
});
config.openai().baseUrl().ifPresent((t) -> {
properties.put("chappie.openai.base-url", t);
});

properties.put("chappie.openai.model-name", config.openai().modelName());

} else if (ollamaBuildItem.isPresent()) {
properties.put("chappie.ollama.base-url", ollamaBuildItem.get().getUrl());
properties.put("chappie.ollama.model-name", config.ollama().modelName());
properties.put("chappie.ollama.timeout", config.ollama().timeout());

}

String extVersion = extensionVersionBuildItem.getVersion();
Expand Down Expand Up @@ -96,7 +108,6 @@ public void createContainer(BuildProducer<DevServicesResultBuildItem> devService
}

chappieClientProducer.produce(new ChappieClientBuildItem(chappieClient));

}

@BuildStep
Expand Down Expand Up @@ -204,10 +215,7 @@ private void runServer(String version, Map<String, String> properties, boolean l
for (Map.Entry<String, String> es : properties.entrySet()) {
command.add("-D" + es.getKey() + "=" + es.getValue());
}
if (log) {
command.add("-Dchappie.log.request=true");
command.add("-Dchappie.log.response=true");
}

command.add("-jar");
command.add(chappieServer.toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ public interface DevServicesConfig {
*/
Optional<Integer> port();

/**
* The version to use
*/
@WithDefault("0.0.12")
String version();

/**
* The base url for chappie
*/
Expand All @@ -36,4 +30,9 @@ public interface DevServicesConfig {
*/
Optional<Long> processId();

/**
* Timeout for the request
*/
@WithDefault("PT120S")
String timeout();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public interface OpenAIConfig {
*/
Optional<String> apiKey();

/**
* Your OpenAI Base Url
*/
Optional<String> baseUrl();

/**
* The Model to use
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,4 @@ public interface OllamaConfig {
@WithDefault("true")
boolean preload();

/**
* Timeout for the request
*/
@WithDefault("PT120S")
String timeout();

}
17 changes: 16 additions & 1 deletion sample/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
#quarkus.assistant.ollama.model-name=instructlab/granite-7b-lab
#quarkus.assistant.devservices.log=true

# Local podman ai
#quarkus.assistant.openai.base-url=http://localhost:46311/v1
#quarkus.assistant.openai.model-name=instructlab/granite-7b-lab-GGUF
#quarkus.assistant.openai.api-key=sk-dummy

# Mike's server
#quarkus.assistant.openai.base-url=https://sno-llama31-llama-serving.apps.sno.sandbox1771.opentlc.com/v1
#quarkus.assistant.openai.model-name=Meta-Llama-3.1-8B-Instruct-Q8_0.gguf
#quarkus.assistant.openai.api-key=sk-dummy

# MOOS
#quarkus.assistant.openai.base-url=https://granite-8b-code-instruct-maas-apicast-production.apps.prod.rhoai.rh-aiservices-bu.com:443/v1
#quarkus.assistant.openai.model-name=granite-8b-code-instruct-128k
#quarkus.assistant.openai.api-key=your-key-here

0 comments on commit d52aa7e

Please sign in to comment.