Skip to content

Commit

Permalink
feat: Integrate gpt-4o-mini into OdinRunes for image context support
Browse files Browse the repository at this point in the history
- Added support for gpt-4o-mini in the latest version of OdinRunes.
- Enabled the functionality to supply images within the context for enhanced capabilities.
  • Loading branch information
leonid20000 committed Jul 20, 2024
1 parent d6d2df7 commit 7f1a8af
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 192 deletions.
27 changes: 14 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>com.odinware</groupId>
<artifactId>OdinRunes</artifactId>
<version>1.3-SNAPSHOT</version>
<version>1.5-SNAPSHOT</version>


<dependencies>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>5.10.0</version> <!-- Replace with the latest version -->
<version>5.12.0</version> <!-- Replace with the latest version -->
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -30,12 +30,12 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.14</version> <!-- Use the latest version -->
<version>1.5.6</version> <!-- Use the latest version -->
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.11.0</version> <!-- Replace with the latest version -->
<version>1.12.0</version> <!-- Replace with the latest version -->
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand All @@ -45,30 +45,31 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20231013</version> <!-- Use the latest version available -->
<version>20240303</version> <!-- Use the latest version available -->
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>5.0.0-alpha.12</version> <!-- Use the latest version available -->
<version>5.0.0-alpha.14</version> <!-- Use the latest version available -->
</dependency>

<!-- Jackson for JSON parsing -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.16.1</version> <!-- Use the latest version available -->
<version>2.17.2</version> <!-- Use the latest version available -->
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.1</version> <!-- Replace with the latest version -->
<version>2.17.2</version> <!-- Replace with the latest version -->
</dependency>





<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -84,32 +85,32 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.1</version>
<version>5.11.0-M2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.1</version>
<version>5.11.0-M2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.1</version>
<version>5.11.0-M2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.8.0</version> <!-- Use the latest version available -->
<version>5.12.0</version> <!-- Use the latest version available -->
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.1</version>
<version>5.11.0-M2</version>
<scope>test</scope>
</dependency>

Expand Down
170 changes: 0 additions & 170 deletions pom.xml.versionsBackup

This file was deleted.

22 changes: 21 additions & 1 deletion src/main/java/org/odinware/odinrunes/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import java.util.ArrayList;
import java.util.List;
import java.io.Serializable;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Base64;
/**
* The Context class represents the context in which the GPT request is made.
* It contains captured data and user options that will be used to construct the request.
Expand Down Expand Up @@ -79,12 +83,28 @@ public CapturedData(String capturedText, String captureMethod) {
this.captureMethod = captureMethod;
}

public String getRawCapturedText(){
return capturedText;
}
public String getCapturedText() {
if(getCaptureMethod().equals("File (Live)")){
String fileContent=TextHelper.readIntoString(capturedText);
if(fileContent == null){
return "ERROR READING FROM FILE";
} else return fileContent;
} else if(getCaptureMethod().equals("Image File (Live)")){
try{
File file = new File(capturedText);
// Read the file into a byte array
byte[] fileContent = Files.readAllBytes(file.toPath());

// Encode the byte array into a Base64 string
String encodedString = Base64.getEncoder().encodeToString(fileContent);
return encodedString;
} catch (IOException e) {
e.printStackTrace();
return "";
}
} else return capturedText;

}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/odinware/odinrunes/GptOpsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public static void streamResponse(TextHelper odinSays, Context context, JSONObje

// Switch case based on gptProvider value
switch (gptProvider) {
case "OpenAI (gpt-4o-mini)":
// Code to handle OpenAI (gpt-4o-mini) provider
customWellsOfWisdom = new OpenAIWellsOfWisdom();
logger.info("Using OpenAI (gpt-4o-mini)");
break;
case "OpenAI (gpt-3.5-turbo)":
// Code to handle OpenAI (gpt-3.5-turbo) provider
customWellsOfWisdom = new OpenAIWellsOfWisdom();
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/org/odinware/odinrunes/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Main {
private static final Logger logger = Logger.getLogger(GraphicalInteractionsHelper.class.getName());

private static Context context = new Context();
private static JSONObject gptSettingsJsonObject = new JSONObject("{\"temperature\":0.8,\"gptProvider\":\"OpenAI (gpt-3.5-turbo)\"}");
private static JSONObject gptSettingsJsonObject = new JSONObject("{\"temperature\":0.8,\"gptProvider\":\"OpenAI (gpt-4o-mini)\"}");
private static JFrame frame;
private static JPanel mainPanel;
private static JPanel settingsPanel;
Expand Down Expand Up @@ -114,7 +114,7 @@ private static void createAndShowGUI() {
mainComponentsPanel.setLayout(new FlowLayout());

// Create the first dropdown menu
String[] options = {"Clipboard", "Regionshot (OCR)", "Scrollshot (OCR)", "File (Live)","Photo (Coming Soon)"};
String[] options = {"Clipboard", "Regionshot (OCR)", "Scrollshot (OCR)", "Text File (Live)","Image File (Live)"};
final JComboBox<String> firstDropdown = new JComboBox<>(options);
firstDropdown.setBackground(new Color(189, 219, 225)); // RGB values for a blue-grey shade

Expand Down Expand Up @@ -156,7 +156,7 @@ public void run() {
logger.info(selectedArgument);
toggleSettingsPanelVisibility();
if(!settingsVisible) toggleSettingsPanelVisibility();
} else if (selectedFunction.equals("File (Live)")) {
} else if (selectedFunction.equals("Text File (Live)")) {
JFileChooser fileChooser = new JFileChooser();
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
Expand All @@ -169,6 +169,19 @@ public void run() {
context.addCapturedData(tempFile.getAbsolutePath(), "File (Live)");
}
}
} else if (selectedFunction.equals("Image File (Live)")) {
JFileChooser fileChooser = new JFileChooser();
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File tempFile = fileChooser.getSelectedFile();
if(!tempFile.exists()) {
// Do something with the selected file, e.g., display its path
JOptionPane.showMessageDialog(frame, "ERROR: Something is wrong with the selected file: " + tempFile.getAbsolutePath());
}else{
JOptionPane.showMessageDialog(frame, "OK: I will pass the latest content of the selected image source as part of the context to your specified GPT provider. (Only multimodal GPT providers) \nThis means that any changes to the file will also be automatically reflected in the context. \nThe selected file: " + tempFile.getAbsolutePath());
context.addCapturedData(tempFile.getAbsolutePath(), "Image File (Live)");
}
}
}

// Add logic to handle the result or display a message.
Expand Down Expand Up @@ -305,7 +318,7 @@ private static void toggleSettingsPanelVisibility() {


// Create an array of options for the dropdown
String[] options = {"OpenAI (gpt-3.5-turbo)", "Google's VertexAI (chat-bison)", "Google's VertexAI (gemini-pro)", "Ollama"};
String[] options = {"OpenAI (gpt-4o-mini)", "OpenAI (gpt-3.5-turbo)", "Google's VertexAI (chat-bison)", "Google's VertexAI (gemini-pro)", "Ollama"};

// Create a JComboBox with the options array
final JComboBox<String> dropdown = new JComboBox<>(options);
Expand Down
Loading

0 comments on commit 7f1a8af

Please sign in to comment.