Welcome to DALL-E Cool!
This is a simple Spring Boot 3 app, generating images by leveraging DALL-E (an OpenAI project).
Just enter some text, hit Go, and you get an image generated by AI.
This app is best used with VMware Tanzu Application Platform (TAP): a platform to build and run your app on top of any Kubernetes distribution. You can also deploy this app without TAP, but then you'll have to write a Dockerfile to create a container, and write some YAML files to deploy the app to your Kubernetes cluster.
You need an API key from OpenAI in order to use DALL-E.
Sign up for a free account and get an API key.
Just run this command:
OPENAI_KEY=my-openai-api-key mvn spring-boot:runThe OpenAI API key is actually read from the property openai.key.
In this command, Spring Boot would use an environment variable to populate this property.
The app is available at http://localhost:8080.
Enter some text and hit Go: an image will be generated by DALL-E.
This app relies on servicebinding.io to load the OpenAI API key.
As a developer, you don't have to deal with sensitive data: it's up to the app operator to provide you with such things.
Create a Kubernetes secret to store your API key, by using this template:
apiVersion: v1
kind: Secret
metadata:
name: openai-binding
type: servicebinding.io/openai
stringData:
type: openai
provider: sample
key: my-openai-api-keyNote the use of type: openai. This value is used by
a custom service binding processor implementation
to set the openai.key property:
public class OpenAiBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
public static final String TYPE = "openai";
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
bindings.filterBindings(TYPE).forEach(binding -> {
properties.putIfAbsent("openai.key", binding.getSecret().get("key"));
});
}
}Usually, you rely on service bindings to connect your app to some database, message broker, etc. In this app, a custom service binding processor takes care of setting up the configuration for you.
Apply this configuration to the cluster:
kubectl -n $TAP_NS apply -f config/app-operatorThe OpenAI API key is now available as a service binding.
As a developer, deploy this app to TAP:
tanzu apps workload apply -f config/workload.yaml -n $TAP_NSYou're done!
Get the URL to access the app:
tanzu apps workload get dallecool -n $TAP_NS🚢 Knative Services
NAME READY URL
dallecool Ready https://dallecool.dev.apps.corp.comEnjoy!
Contributions are always welcome!
Feel free to open issues & send PR.
Copyright © 2023 VMware, Inc. or its affiliates.
This project is licensed under the Apache Software License version 2.0.
