From f2f17e6be948e2bc141254eade43e9d4ceb59298 Mon Sep 17 00:00:00 2001 From: spookysleeper Date: Sat, 8 Jul 2023 21:56:13 +0200 Subject: [PATCH 1/5] Move parsing to response.java --- .../java/com/frazik/instructgpt/Agent.java | 68 ++++-------------- .../frazik/instructgpt/response/Response.java | 71 +++++++++++++++++-- 2 files changed, 76 insertions(+), 63 deletions(-) diff --git a/lib/src/main/java/com/frazik/instructgpt/Agent.java b/lib/src/main/java/com/frazik/instructgpt/Agent.java index ff0a976..33c0ffb 100644 --- a/lib/src/main/java/com/frazik/instructgpt/Agent.java +++ b/lib/src/main/java/com/frazik/instructgpt/Agent.java @@ -196,32 +196,18 @@ public Response chat(String message, boolean runTool) { this.history.addNewPrompt("assistant", resp); try { - JsonNode parsedResp = this.loadJson(resp); - - if (parsedResp.has("name")) { - parsedResp = mapper.createObjectNode().set("command", parsedResp); - } - - String commandArgs = parsedResp.get("command").get("args").asText(); - String commandName = parsedResp.get("command").get("name").asText(); - - this.stagingTool = new HashMap<>(); - this.stagingTool.put("args", commandArgs); - this.stagingTool.put("name", commandName); - - this.stagingResponse = parsedResp; - // Parse the 'thoughts' and 'command' parts of the response into objects - if (parsedResp.has("thoughts") && parsedResp.has("command")) { - JsonNode thoughtsNode = parsedResp.get("thoughts"); - Thought thoughts = new Thought( - thoughtsNode.get("text").asText(), - thoughtsNode.get("reasoning").asText(), - thoughtsNode.get("plan").asText(), - thoughtsNode.get("criticism").asText(), - thoughtsNode.get("speak").asText() - ); - JsonNode commandNode = parsedResp.get("command"); - return new Response(thoughts, commandNode.get("name").asText()); + Response response = Response.getResponseFromRaw(resp); + if (response != null) { + JsonNode parsedResp = response.getParsedResp(); + String commandArgs = parsedResp.get("command").get("args").asText(); + String commandName = parsedResp.get("command").get("name").asText(); + + this.stagingTool = new HashMap<>(); + this.stagingTool.put("args", commandArgs); + this.stagingTool.put("name", commandName); + + this.stagingResponse = parsedResp; + return response; } } catch (Exception e) { @@ -231,36 +217,6 @@ public Response chat(String message, boolean runTool) { return null; } - private static final ObjectMapper mapper = new ObjectMapper(); - - private JsonNode loadJson(String s) throws Exception { - if (!s.contains("{") || !s.contains("}")) { - throw new Exception(); - } - try { - return mapper.readTree(s); - } catch (Exception e1) { - int startIndex = s.indexOf("{"); - int endIndex = s.indexOf("}") + 1; - String subString = s.substring(startIndex, endIndex); - try { - return mapper.readTree(subString); - } catch (Exception e2) { - subString += "}"; - try { - return mapper.readTree(subString); - } catch (Exception e3) { - subString = subString.replace("'", "\""); - try { - return mapper.readTree(subString); - } catch (Exception e4) { - throw new Exception(); - } - } - } - } - } - public String lastUserInput() { for (int i = history.getSize() - 1; i >= 0; i--) { Map msg = history.getValue(i); diff --git a/lib/src/main/java/com/frazik/instructgpt/response/Response.java b/lib/src/main/java/com/frazik/instructgpt/response/Response.java index f7d0d12..e9321c4 100644 --- a/lib/src/main/java/com/frazik/instructgpt/response/Response.java +++ b/lib/src/main/java/com/frazik/instructgpt/response/Response.java @@ -1,28 +1,85 @@ package com.frazik.instructgpt.response; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.Getter; + +@Getter public class Response { private final Thought thoughts; private final String command; - public Response(Thought thoughts, String command) { + private final JsonNode parsedResp; + + private static final ObjectMapper mapper = new ObjectMapper(); + + public Response(Thought thoughts, String command, JsonNode parsedResp) { this.thoughts = thoughts; this.command = command; + this.parsedResp = parsedResp; } public boolean hasThoughts() { return thoughts != null; } - public Thought getThoughts() { - return thoughts; - } - public boolean hasCommand() { return command != null; } - public String getCommand() { - return command; + public static Response getResponseFromRaw(String rawResponse) { + JsonNode parsedResp = loadJson(rawResponse); + + if (parsedResp == null) { + return null; + } + + if (parsedResp.has("name")) { + parsedResp = mapper.createObjectNode().set("command", parsedResp); + } + + // Parse the 'thoughts' and 'command' parts of the response into objects + if (parsedResp.has("thoughts") && parsedResp.has("command")) { + JsonNode thoughtsNode = parsedResp.get("thoughts"); + Thought thoughts = new Thought( + thoughtsNode.get("text").asText(), + thoughtsNode.get("reasoning").asText(), + thoughtsNode.get("plan").asText(), + thoughtsNode.get("criticism").asText(), + thoughtsNode.get("speak").asText() + ); + JsonNode commandNode = parsedResp.get("command"); + return new Response(thoughts, commandNode.get("name").asText(), parsedResp); + } + return null; + } + + private static JsonNode loadJson(String s) { + if (!s.contains("{") || !s.contains("}")) { + return null; + } + try { + return mapper.readTree(s); + } catch (Exception exc1) { + int startIndex = s.indexOf("{"); + int endIndex = s.indexOf("}") + 1; + String subString = s.substring(startIndex, endIndex); + try { + return mapper.readTree(subString); + } catch (Exception exc2) { + subString += "}"; + try { + return mapper.readTree(subString); + } catch (Exception exc3) { + subString = subString.replace("'", "\""); + try { + return mapper.readTree(subString); + } catch (Exception exc4) { + return null; + } + } + } + } } } From a7a5691b781905fc71dfa2cd4a0d2c60918a661b Mon Sep 17 00:00:00 2001 From: spookysleeper Date: Sat, 8 Jul 2023 23:21:58 +0200 Subject: [PATCH 2/5] Move parsing to response.java --- .../java/com/frazik/instructgpt/Agent.java | 41 +++++++------------ .../com/frazik/instructgpt/Constants.java | 2 - .../embedding/OpenAIEmbeddingProvider.java | 1 - .../instructgpt/memory/LocalMemory.java | 4 +- .../frazik/instructgpt/prompts/Prompt.java | 17 +++++++- .../main/resources/default_response_en.json | 13 ++++++ .../com/frazik/instructgpt/PromptTests.java | 1 + .../frazik/instructgpt/RegressionTests.java | 2 +- 8 files changed, 47 insertions(+), 34 deletions(-) create mode 100644 lib/src/main/resources/default_response_en.json diff --git a/lib/src/main/java/com/frazik/instructgpt/Agent.java b/lib/src/main/java/com/frazik/instructgpt/Agent.java index 33c0ffb..b67b104 100644 --- a/lib/src/main/java/com/frazik/instructgpt/Agent.java +++ b/lib/src/main/java/com/frazik/instructgpt/Agent.java @@ -1,7 +1,6 @@ package com.frazik.instructgpt; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.frazik.instructgpt.auto.Cli; import com.frazik.instructgpt.embedding.OpenAIEmbeddingProvider; import com.frazik.instructgpt.memory.LocalMemory; @@ -9,7 +8,6 @@ import com.frazik.instructgpt.prompts.Prompt; import com.frazik.instructgpt.prompts.PromptHistory; import com.frazik.instructgpt.response.Response; -import com.frazik.instructgpt.response.Thought; import com.frazik.instructgpt.tools.Browser; import com.frazik.instructgpt.tools.GoogleSearch; import com.frazik.instructgpt.tools.Tool; @@ -25,23 +23,18 @@ public class Agent { private final String name; private final String description; private final List goals; - private final Map subAgents; private final LocalMemory memory; private final PromptHistory history; private final List tools; private Map stagingTool; - private JsonNode stagingResponse; private final OpenAIModel openAIModel; - private final String responseFormat; - public Agent(String name, String description, List goals, String model) { this.history = new PromptHistory(); this.name = name; - this.description = description != null ? description : "A personal assistant that responds exclusively in JSON"; - this.goals = goals != null ? goals : new ArrayList<>(); - this.subAgents = new HashMap<>(); + this.description = description; + this.goals = goals; this.memory = new LocalMemory(new OpenAIEmbeddingProvider()); this.responseFormat = Constants.getDefaultResponseFormat(); this.tools = Arrays.asList(new Browser(), new GoogleSearch()); @@ -65,7 +58,7 @@ private List> getFullPrompt(String userInput) { // Build current date and time prompt Prompt currentTimePrompt = new Prompt.Builder("current_time") .withRole("system") - .formatted(0, ZonedDateTime.now().format(DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy"))) + .formattedWithCurrentTime(0) .build(); prompt.add(currentTimePrompt.getPrompt()); @@ -195,23 +188,18 @@ public Response chat(String message, boolean runTool) { this.history.addNewPrompt("user", message); this.history.addNewPrompt("assistant", resp); - try { - Response response = Response.getResponseFromRaw(resp); - if (response != null) { - JsonNode parsedResp = response.getParsedResp(); - String commandArgs = parsedResp.get("command").get("args").asText(); - String commandName = parsedResp.get("command").get("name").asText(); + Response response = Response.getResponseFromRaw(resp); + if (response != null) { + JsonNode parsedResp = response.getParsedResp(); + String commandArgs = parsedResp.get("command").get("args").asText(); + String commandName = parsedResp.get("command").get("name").asText(); - this.stagingTool = new HashMap<>(); - this.stagingTool.put("args", commandArgs); - this.stagingTool.put("name", commandName); - - this.stagingResponse = parsedResp; - return response; - } + this.stagingTool = new HashMap<>(); + this.stagingTool.put("args", commandArgs); + this.stagingTool.put("name", commandName); - } catch (Exception e) { - log.error("Error parsing response: " + resp, e); + this.stagingResponse = parsedResp; + return response; } return null; @@ -286,7 +274,6 @@ public Object runStagingTool() { public void clearState() { history.clear(); - subAgents.clear(); memory.clear(); } @@ -309,7 +296,7 @@ public String headerPrompt() { public String personaPrompt() { Prompt personaPrompt = new Prompt.Builder("persona") - .formatted(0, "name", "description") + .formatted(0, name, description) .build(); return personaPrompt.getContent(); } diff --git a/lib/src/main/java/com/frazik/instructgpt/Constants.java b/lib/src/main/java/com/frazik/instructgpt/Constants.java index ffaa44a..876712f 100644 --- a/lib/src/main/java/com/frazik/instructgpt/Constants.java +++ b/lib/src/main/java/com/frazik/instructgpt/Constants.java @@ -5,9 +5,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.frazik.instructgpt.prompts.Prompt; -import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; /** diff --git a/lib/src/main/java/com/frazik/instructgpt/embedding/OpenAIEmbeddingProvider.java b/lib/src/main/java/com/frazik/instructgpt/embedding/OpenAIEmbeddingProvider.java index 9b6d53d..dbfa542 100644 --- a/lib/src/main/java/com/frazik/instructgpt/embedding/OpenAIEmbeddingProvider.java +++ b/lib/src/main/java/com/frazik/instructgpt/embedding/OpenAIEmbeddingProvider.java @@ -7,7 +7,6 @@ import java.util.Collections; import java.util.List; -import java.util.Map; public class OpenAIEmbeddingProvider extends EmbeddingProvider { public static final String OPENAI_API_KEY = "OPENAI_API_KEY"; diff --git a/lib/src/main/java/com/frazik/instructgpt/memory/LocalMemory.java b/lib/src/main/java/com/frazik/instructgpt/memory/LocalMemory.java index b330f26..d7fbdbb 100644 --- a/lib/src/main/java/com/frazik/instructgpt/memory/LocalMemory.java +++ b/lib/src/main/java/com/frazik/instructgpt/memory/LocalMemory.java @@ -5,7 +5,9 @@ import org.nd4j.linalg.api.ndarray.INDArray; import org.nd4j.linalg.factory.Nd4j; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; @Slf4j diff --git a/lib/src/main/java/com/frazik/instructgpt/prompts/Prompt.java b/lib/src/main/java/com/frazik/instructgpt/prompts/Prompt.java index e786fee..9d3c613 100644 --- a/lib/src/main/java/com/frazik/instructgpt/prompts/Prompt.java +++ b/lib/src/main/java/com/frazik/instructgpt/prompts/Prompt.java @@ -3,8 +3,16 @@ import com.google.gson.Gson; import org.openqa.selenium.json.TypeToken; -import java.io.*; -import java.util.*; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class Prompt { private final String role; @@ -58,6 +66,11 @@ public Builder formatted(int i, Object... args) { prompts.set(i, String.format(prompts.get(i), args)); return this; } + + public Builder formattedWithCurrentTime(int i) { + String currentTime = ZonedDateTime.now().format(DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy")); + return formatted(i, currentTime); + } public Builder withRole(String role) { this.role = role; return this; diff --git a/lib/src/main/resources/default_response_en.json b/lib/src/main/resources/default_response_en.json new file mode 100644 index 0000000..e98f4b2 --- /dev/null +++ b/lib/src/main/resources/default_response_en.json @@ -0,0 +1,13 @@ +{ + "thoughts" : { + "reasoning" : "reasoning", + "speak" : "thoughts summary to say to user", + "text" : "thought", + "criticism" : "constructive self-criticism", + "plan" : "- short bulleted\n- list that conveys\n- long-term plan" + }, + "command" : { + "args" : "{\"arg name\": \"value\"}", + "name" : "command name" + } +} \ No newline at end of file diff --git a/lib/src/test/java/com/frazik/instructgpt/PromptTests.java b/lib/src/test/java/com/frazik/instructgpt/PromptTests.java index 87d41d4..8450f79 100644 --- a/lib/src/test/java/com/frazik/instructgpt/PromptTests.java +++ b/lib/src/test/java/com/frazik/instructgpt/PromptTests.java @@ -2,6 +2,7 @@ import com.frazik.instructgpt.prompts.Prompt; import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.assertTrue; public class PromptTests { diff --git a/lib/src/test/java/com/frazik/instructgpt/RegressionTests.java b/lib/src/test/java/com/frazik/instructgpt/RegressionTests.java index dcd477f..4ada821 100644 --- a/lib/src/test/java/com/frazik/instructgpt/RegressionTests.java +++ b/lib/src/test/java/com/frazik/instructgpt/RegressionTests.java @@ -2,8 +2,8 @@ import com.frazik.instructgpt.embedding.EmbeddingProvider; import com.frazik.instructgpt.embedding.OpenAIEmbeddingProvider; -import com.frazik.instructgpt.memory.Memory; import com.frazik.instructgpt.memory.LocalMemory; +import com.frazik.instructgpt.memory.Memory; import com.frazik.instructgpt.models.Model; import com.frazik.instructgpt.models.OpenAIModel; import com.frazik.instructgpt.response.Response; From b158c29568852a582ac77d367b6f432f8c15a077 Mon Sep 17 00:00:00 2001 From: spookysleeper Date: Sun, 9 Jul 2023 16:09:32 +0200 Subject: [PATCH 3/5] Fix issue with default prompt. --- .../java/com/frazik/instructgpt/Agent.java | 39 ++++++++++--------- .../frazik/instructgpt/prompts/Prompt.java | 36 +++++++++++++---- lib/src/main/resources/prompts_en.json | 3 ++ 3 files changed, 52 insertions(+), 26 deletions(-) diff --git a/lib/src/main/java/com/frazik/instructgpt/Agent.java b/lib/src/main/java/com/frazik/instructgpt/Agent.java index b67b104..098f5a9 100644 --- a/lib/src/main/java/com/frazik/instructgpt/Agent.java +++ b/lib/src/main/java/com/frazik/instructgpt/Agent.java @@ -15,8 +15,6 @@ import lombok.extern.slf4j.Slf4j; import org.json.JSONObject; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; import java.util.*; @Slf4j public class Agent { @@ -29,14 +27,12 @@ public class Agent { private Map stagingTool; private JsonNode stagingResponse; private final OpenAIModel openAIModel; - private final String responseFormat; public Agent(String name, String description, List goals, String model) { this.history = new PromptHistory(); this.name = name; this.description = description; this.goals = goals; this.memory = new LocalMemory(new OpenAIEmbeddingProvider()); - this.responseFormat = Constants.getDefaultResponseFormat(); this.tools = Arrays.asList(new Browser(), new GoogleSearch()); this.openAIModel = new OpenAIModel(model); } @@ -290,10 +286,17 @@ public String headerPrompt() { } prompt.add(resourcesPrompt()); prompt.add(evaluationPrompt()); - prompt.add(this.responseFormat); + prompt.add(defaultResponsePrompt()); return newLineDelimited(prompt); } + public String defaultResponsePrompt() { + String defaultResponse = Prompt.getDefaultResponse(); + Prompt defaultResponsePrompt = new Prompt.Builder("use_only_defined_format") + .formatted(0, defaultResponse) + .build(); + return defaultResponsePrompt.getContent(); + } public String personaPrompt() { Prompt personaPrompt = new Prompt.Builder("persona") .formatted(0, name, description) @@ -316,6 +319,19 @@ public String constraintsPrompt() { return constraintsPrompt.getContent(); } + public String resourcesPrompt() { + Prompt resourcesPrompt = new Prompt.Builder("resources") + .build(); + return resourcesPrompt.getContent(); + } + + public String evaluationPrompt() { + Prompt evaluationPrompt = new Prompt.Builder("evaluation") + .delimited() + .build(); + return evaluationPrompt.getContent(); + } + /** * The given code snippet represents a method called tools_prompt() that generates a prompt for a list of tools in a specific format. Here's a breakdown of what the code does: * It initializes an empty list called prompt to store the lines of the prompt. @@ -354,19 +370,6 @@ public String toolsPrompt() { return newLineDelimited(prompt); } - public String resourcesPrompt() { - Prompt resourcesPrompt = new Prompt.Builder("resources") - .build(); - return resourcesPrompt.getContent(); - } - - public String evaluationPrompt() { - Prompt evaluationPrompt = new Prompt.Builder("evaluation") - .delimited() - .build(); - return evaluationPrompt.getContent(); - } - private static String newLineDelimited(List prompt) { return String.join("\n", prompt) + "\n"; } diff --git a/lib/src/main/java/com/frazik/instructgpt/prompts/Prompt.java b/lib/src/main/java/com/frazik/instructgpt/prompts/Prompt.java index 9d3c613..eb3ec32 100644 --- a/lib/src/main/java/com/frazik/instructgpt/prompts/Prompt.java +++ b/lib/src/main/java/com/frazik/instructgpt/prompts/Prompt.java @@ -1,5 +1,8 @@ package com.frazik.instructgpt.prompts; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import com.google.gson.Gson; import org.openqa.selenium.json.TypeToken; @@ -17,10 +20,20 @@ public class Prompt { private final String role; private final String content; - private static Map> promptsBundle = new HashMap<>(); + private static final Map> promptsBundle; + private static final Map> defaultResponsesJson; + + private static final ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); + static { - readPromptJson(); + // Use generic types to prepare for future expansion + TypeToken>> promptsToken = new TypeToken>>() {}; + promptsBundle = readPromptJson(promptsToken, "prompts_en.json"); + // Use generic types to prepare for future expansion + TypeToken>> defaultResponsesToken = + new TypeToken>>() {}; + defaultResponsesJson = readPromptJson(defaultResponsesToken, "default_response_en.json"); } public Prompt(String role, String content) { @@ -31,6 +44,14 @@ public Prompt(String role, String content) { public String getContent() { return content; } + + public static String getDefaultResponse() { + try { + return objectMapper.writeValueAsString(defaultResponsesJson); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } public Map getPrompt() { Map prompt = new HashMap<>(); prompt.put("role", role); @@ -82,19 +103,18 @@ public Prompt build() { } } - private static void readPromptJson() { + private static T readPromptJson(TypeToken token, String jsonFileName) { try { - InputStream inputStream = Prompt.class.getClassLoader().getResourceAsStream("prompts_en.json"); + InputStream inputStream = Prompt.class.getClassLoader().getResourceAsStream(jsonFileName); if (inputStream == null) { - throw new FileNotFoundException("prompts_en.json file not found."); + throw new FileNotFoundException(jsonFileName + " file not found."); } InputStreamReader reader = new InputStreamReader(inputStream); - TypeToken>> token = new TypeToken>>() {}; - promptsBundle = new Gson().fromJson(reader, token.getType()); + return new Gson().fromJson(reader, token.getType()); } catch (IOException e) { - throw new RuntimeException("Error reading prompts_en.json file.", e); + throw new RuntimeException("Error reading " + jsonFileName, e); } } } diff --git a/lib/src/main/resources/prompts_en.json b/lib/src/main/resources/prompts_en.json index cf82c6f..2112884 100644 --- a/lib/src/main/resources/prompts_en.json +++ b/lib/src/main/resources/prompts_en.json @@ -53,5 +53,8 @@ ], "response": [ "Response from %s:\n%s" + ], + "use_only_defined_format" : [ + "You should only respond in JSON format as described below \nResponse Format: \n%s\nEnsure the response can be parsed by Java JSON ObjectMapper\n\n" ] } From e7a142493fa8e4193ccbd9393fa3e4f4c389b842 Mon Sep 17 00:00:00 2001 From: spookysleeper Date: Sun, 9 Jul 2023 16:16:22 +0200 Subject: [PATCH 4/5] Remove class. --- .../com/frazik/instructgpt/Constants.java | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 lib/src/main/java/com/frazik/instructgpt/Constants.java diff --git a/lib/src/main/java/com/frazik/instructgpt/Constants.java b/lib/src/main/java/com/frazik/instructgpt/Constants.java deleted file mode 100644 index 876712f..0000000 --- a/lib/src/main/java/com/frazik/instructgpt/Constants.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.frazik.instructgpt; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.frazik.instructgpt.prompts.Prompt; - -import java.util.HashMap; -import java.util.Map; - -/** - * Credits: Auto-GPT (...) - */ -public class Constants { - private static final ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); - - public static String getDefaultResponseFormat() { - Prompt seedInput = new Prompt.Builder("seed").build(); - - Map thoughtsMap = new HashMap<>(); - thoughtsMap.put("text", "thought"); - thoughtsMap.put("reasoning", "reasoning"); - thoughtsMap.put("plan", "- short bulleted\n- list that conveys\n- long-term plan"); - thoughtsMap.put("criticism", "constructive self-criticism"); - thoughtsMap.put("speak", "thoughts summary to say to user"); - - Map commandMap = new HashMap<>(); - commandMap.put("name", "command name"); - commandMap.put("args", "{\"arg name\": \"value\"}"); - - Map defaultResponseMap = new HashMap<>(); - defaultResponseMap.put("thoughts", thoughtsMap); - defaultResponseMap.put("command", commandMap); - - try { - String defaultJSONFormat = objectMapper.writeValueAsString(defaultResponseMap); - return String.format("You should only respond in JSON format as described below \nResponse Format: \n%s\nEnsure the response can be parsed by Java JSON ObjectMapper\n\n", defaultJSONFormat); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } -} From 51bb1ae1cad4b3e6463204ee8ae447a1f519744f Mon Sep 17 00:00:00 2001 From: spookysleeper Date: Sun, 9 Jul 2023 16:50:27 +0200 Subject: [PATCH 5/5] Format. --- lib/src/main/java/com/frazik/instructgpt/prompts/Prompt.java | 2 -- lib/src/main/java/com/frazik/instructgpt/response/Response.java | 1 - 2 files changed, 3 deletions(-) diff --git a/lib/src/main/java/com/frazik/instructgpt/prompts/Prompt.java b/lib/src/main/java/com/frazik/instructgpt/prompts/Prompt.java index eb3ec32..63037b0 100644 --- a/lib/src/main/java/com/frazik/instructgpt/prompts/Prompt.java +++ b/lib/src/main/java/com/frazik/instructgpt/prompts/Prompt.java @@ -22,10 +22,8 @@ public class Prompt { private final String content; private static final Map> promptsBundle; private static final Map> defaultResponsesJson; - private static final ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT); - static { // Use generic types to prepare for future expansion TypeToken>> promptsToken = new TypeToken>>() {}; diff --git a/lib/src/main/java/com/frazik/instructgpt/response/Response.java b/lib/src/main/java/com/frazik/instructgpt/response/Response.java index e9321c4..3939be4 100644 --- a/lib/src/main/java/com/frazik/instructgpt/response/Response.java +++ b/lib/src/main/java/com/frazik/instructgpt/response/Response.java @@ -81,5 +81,4 @@ private static JsonNode loadJson(String s) { } } } - }