Skip to content
Open
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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Joshua W. (@Tigjaw)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
* Create API key at https://beta.openai.com/account/api-keys
* Store the key in application.properties file in cloned project.
* Start it as Spring Boot application.
* For chatting with ChatGPT: http://localhost:8080/
* For drawing images with DALL-E: http://localhost:8080/image
* Browser opens index.html automatically, hosted at:
* http://localhost:8080/ (for chatting with ChatGPT)
* http://localhost:8080/image (for drawing images with DALL-E)

## Setup proxy
If you need a proxy to communicate with Internet (ChatGPT API is in Internet), adapt ChatGptController.java like this:
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/de/bsi/openai/BrowserLauncher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.bsi.openai;

import java.awt.Desktop;
import java.net.URI;

import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
public class BrowserLauncher {

@EventListener(ApplicationReadyEvent.class)
public void launchBrowser() {

System.setProperty("java.awt.headless", "false");

Desktop desktop = Desktop.getDesktop();

try {
desktop.browse(new URI("http://localhost:8080"));
} catch (Exception e) {
}

}

}
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
openai.api_key=Generate this at openai.com
openai.api_key=Generate this at openai.com
38 changes: 23 additions & 15 deletions src/main/resources/templates/image.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head th:fragment="head">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>DALL-E & Spring demo</title>
<link rel="stylesheet" th:href="@{/css/main.css}" />
<meta charset="utf-8" />
<meta name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>DALL-E & Spring demo</title>
<link rel="stylesheet" th:href="@{/css/main.css}" />
</head>
<body>
<main role="main" class="container">
<div>
<a href="http://localhost:8080"> Use ChatGPT</a>
</div>
<div class="starter-template">
<h1>DALL-E API at<br/>agile-coding.blogspot.com</h1>
<h1>
DALL-E API at<br />agile-coding.blogspot.com
</h1>
<h2>Describe image</h2>
<form th:action="@{/image}" method="post">
<fieldset>
<div class="form-group">
<input type="text" name="prompt" th:value="${request}" required autofocus/>
</div>
<div class="row">
<input type="submit" value="Send" />
</div>
</fieldset>
<fieldset>
<div class="form-group">
<input type="text" name="prompt" th:value="${request}" required
autofocus />
</div>
<div class="row">
<input type="submit" value="Send" />
</div>
</fieldset>
</form>
<h2 th:if="${imageUri != null}" >DALL-E draw for you: </h2>
<img th:if="${imageUri != null}" th:src="${imageUri}" alt="Picture drawn by DALL-E" />
<h2 th:if="${imageUri != null}">DALL-E draw for you:</h2>
<img th:if="${imageUri != null}" th:src="${imageUri}"
alt="Picture drawn by DALL-E" />
</div>
</main>
</body>
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
</head>
<body>
<main role="main" class="container">
<div>
<a href="http://localhost:8080/image"> Use DALL-E</a>
</div>
<div class="starter-template">
<h1>ChatGPT API at<br/>agile-coding.blogspot.com</h1>
<h2>Send message to ChatGPT</h2>
Expand Down