diff --git a/libraries-ai/pom.xml b/libraries-ai/pom.xml
index aa2ef19b4550..d16cd3d69aaf 100644
--- a/libraries-ai/pom.xml
+++ b/libraries-ai/pom.xml
@@ -28,12 +28,28 @@
neuroph
${neuroph.version}
+
+ com.theokanning.openai-gpt3-java
+ api
+ ${theokanning.gpt}
+
+
+ com.theokanning.openai-gpt3-java
+ client
+ ${theokanning.gpt}
+
+
+ com.theokanning.openai-gpt3-java
+ service
+ ${theokanning.gpt}
+
4.5.3
2.1.1
2.92
+ 0.18.2
\ No newline at end of file
diff --git a/libraries-ai/src/main/java/baeldungassistant/BaeldungLearningAssistant.java b/libraries-ai/src/main/java/baeldungassistant/BaeldungLearningAssistant.java
new file mode 100644
index 000000000000..a710f0b29a98
--- /dev/null
+++ b/libraries-ai/src/main/java/baeldungassistant/BaeldungLearningAssistant.java
@@ -0,0 +1,67 @@
+package baeldungassistant;
+
+import static com.theokanning.openai.utils.TikTokensUtil.ModelEnum.GPT_3_5_TURBO_0301;
+
+import com.theokanning.openai.completion.chat.ChatCompletionRequest;
+import com.theokanning.openai.completion.chat.ChatCompletionResult;
+import com.theokanning.openai.completion.chat.ChatMessage;
+import com.theokanning.openai.completion.chat.ChatMessageRole;
+import com.theokanning.openai.service.OpenAiService;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+
+class BaeldungLearningAssistant {
+
+ private static final String OPENAI_TOKEN = "OPENAI_TOKEN";
+ private static final String PROMPT = "You're helping me to create a curriculum"
+ + "to learn programming."
+ + "I want to use Baedlung website as the base."
+ + "I will tell you the topic,"
+ + "and you should return me the list of articles"
+ + "and tutorials with links."
+ + "Order the articles from beginner to more advanced,"
+ + "so I can learn them one-by-one."
+ + "Use only the articles from www.baeldung.com.";
+ private static final int MAX_TOKENS = 900;
+ private static final String GREETING = "Hello!\nWhat do you want to learn?\n";
+ private static final String MODEL = GPT_3_5_TURBO_0301.getName();
+
+ public static void main(String[] args) {
+ String token = System.getenv(OPENAI_TOKEN);
+ OpenAiService service = new OpenAiService(token);
+
+ List messages = new ArrayList<>();
+ ChatMessage systemMessage = new ChatMessage(ChatMessageRole.SYSTEM.value(), PROMPT);
+ messages.add(systemMessage);
+
+ System.out.print(GREETING);
+ Scanner scanner = new Scanner(System.in);
+ ChatMessage firstMsg = new ChatMessage(ChatMessageRole.USER.value(), scanner.nextLine());
+ messages.add(firstMsg);
+
+ while (true) {
+ ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest
+ .builder()
+ .model(MODEL)
+ .maxTokens(MAX_TOKENS)
+ .messages(messages)
+ .build();
+ ChatCompletionResult result = service.createChatCompletion(chatCompletionRequest);
+ long usedTokens = result.getUsage().getTotalTokens();
+ ChatMessage response = result.getChoices().get(0).getMessage();
+
+ messages.add(response);
+
+ System.out.println(response.getContent());
+ System.out.println("Total tokens used: " + usedTokens);
+ System.out.print("Anything else?\n");
+ String nextLine = scanner.nextLine();
+ if (nextLine.equalsIgnoreCase("exit")) {
+ System.exit(0);
+ }
+ messages.add(new ChatMessage(ChatMessageRole.USER.value(), nextLine));
+ }
+ }
+
+}