diff --git a/smallville/pom.xml b/smallville/pom.xml index cf4ff4f..8a88222 100644 --- a/smallville/pom.xml +++ b/smallville/pom.xml @@ -176,5 +176,12 @@ SimpleNLG 4.5.0 + + + com.google.code.gson + gson + 2.10.1 + + \ No newline at end of file diff --git a/smallville/src/main/java/io/github/nickm980/smallville/Smallville.java b/smallville/src/main/java/io/github/nickm980/smallville/Smallville.java index a646662..9677ea7 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/Smallville.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/Smallville.java @@ -8,9 +8,9 @@ import com.beust.jcommander.JCommander; -import io.github.nickm980.smallville.api.server.SmallvilleServer; +import io.github.nickm980.smallville.api.SmallvilleServer; import io.github.nickm980.smallville.config.CommandLineArgs; -import io.github.nickm980.smallville.config.Config; +import io.github.nickm980.smallville.config.SmallvilleConfig; import io.github.nickm980.smallville.llm.ChatGPT; import io.github.nickm980.smallville.nlp.LocalNLP; @@ -20,7 +20,7 @@ public class Smallville { public static void main(String[] args) throws IOException { configureLogs(); - + CommandLineArgs options = loadArgs(args); int port = options.getPort(); @@ -29,14 +29,16 @@ public static void main(String[] args) throws IOException { Settings.setApiKey(key); LOG.info("Starting server..."); - + loadConfig(); LocalNLP.preLoad(); - - startServer(port); + startServer(port); + + Updater.checkLatestVersion(); LOG.info("Smallville server started on port " + port); + } private static CommandLineArgs loadArgs(String[] args) { @@ -48,8 +50,8 @@ private static CommandLineArgs loadArgs(String[] args) { } private static void loadConfig() { - Config.getConfig(); - Config.getPrompts(); + SmallvilleConfig.getConfig(); + SmallvilleConfig.getPrompts(); } private static void configureLogs() { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/Updater.java b/smallville/src/main/java/io/github/nickm980/smallville/Updater.java new file mode 100644 index 0000000..9f88655 --- /dev/null +++ b/smallville/src/main/java/io/github/nickm980/smallville/Updater.java @@ -0,0 +1,44 @@ +package io.github.nickm980.smallville; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +public class Updater { + + private static final String VERSION = "v1.0.0"; + private final static Logger LOG = LoggerFactory.getLogger(Updater.class); + + private Updater() { + + } + + public static void checkLatestVersion() { + OkHttpClient client = new OkHttpClient(); + String url = "https://api.github.com/repos/nickm980/smallville/releases/latest"; + Request request = new Request.Builder().url(url).build(); + + try { + Response response = client.newCall(request).execute(); + // Check if the request was successful + if (response.isSuccessful()) { + String body = response.body().string(); + + Gson gson = new Gson(); + JsonObject jsonObject = gson.fromJson(body, JsonObject.class); + String tag = jsonObject.get("tag_name").getAsString(); + + if (VERSION.compareTo(tag) < 0) { + LOG.warn("Your version of smallville " + VERSION + " is outdated. Latest version: " + tag); + } + } + } catch (Exception e) { + LOG.debug(e.getStackTrace().toString()); + } + } +} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/World.java b/smallville/src/main/java/io/github/nickm980/smallville/World.java index 2c17b55..5ea406c 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/World.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/World.java @@ -12,14 +12,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.Conversation; +import io.github.nickm980.smallville.entities.Dialog; +import io.github.nickm980.smallville.entities.Location; +import io.github.nickm980.smallville.entities.SimulatedLocation; +import io.github.nickm980.smallville.entities.SimulatedObject; import io.github.nickm980.smallville.exceptions.LocationNotFoundException; import io.github.nickm980.smallville.exceptions.SmallvilleException; -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.models.Conversation; -import io.github.nickm980.smallville.models.Dialog; -import io.github.nickm980.smallville.models.Location; -import io.github.nickm980.smallville.models.SimulatedLocation; -import io.github.nickm980.smallville.models.SimulatedObject; /** * Creates an interactive Simulation for Generative Agents diff --git a/smallville/src/main/java/io/github/nickm980/smallville/api/server/ExceptionRoutes.java b/smallville/src/main/java/io/github/nickm980/smallville/api/ExceptionRoutes.java similarity index 97% rename from smallville/src/main/java/io/github/nickm980/smallville/api/server/ExceptionRoutes.java rename to smallville/src/main/java/io/github/nickm980/smallville/api/ExceptionRoutes.java index b25ed3c..000a3cc 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/api/server/ExceptionRoutes.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/api/ExceptionRoutes.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.api.server; +package io.github.nickm980.smallville.api; import java.util.Map; import java.util.NoSuchElementException; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/api/server/SimulationService.java b/smallville/src/main/java/io/github/nickm980/smallville/api/SimulationService.java similarity index 80% rename from smallville/src/main/java/io/github/nickm980/smallville/api/server/SimulationService.java rename to smallville/src/main/java/io/github/nickm980/smallville/api/SimulationService.java index 4223802..560bf7e 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/api/server/SimulationService.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/api/SimulationService.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.api.server; +package io.github.nickm980.smallville.api; import java.util.ArrayList; import java.util.Comparator; @@ -11,27 +11,19 @@ import io.github.nickm980.smallville.Util; import io.github.nickm980.smallville.World; -import io.github.nickm980.smallville.api.AgentStateResponse; -import io.github.nickm980.smallville.api.ConversationResponse; -import io.github.nickm980.smallville.api.CreateAgentRequest; -import io.github.nickm980.smallville.api.CreateLocationRequest; -import io.github.nickm980.smallville.api.CreateMemoryRequest; -import io.github.nickm980.smallville.api.CreateObjectRequest; -import io.github.nickm980.smallville.api.LocationStateResponse; -import io.github.nickm980.smallville.api.MemoryResponse; -import io.github.nickm980.smallville.api.ModelMapper; +import io.github.nickm980.smallville.api.dto.*; +import io.github.nickm980.smallville.entities.AccessTime; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.AgentLocation; +import io.github.nickm980.smallville.entities.Conversation; +import io.github.nickm980.smallville.entities.ObjectState; +import io.github.nickm980.smallville.entities.SimulatedLocation; +import io.github.nickm980.smallville.entities.SimulatedObject; +import io.github.nickm980.smallville.entities.memory.Characteristic; import io.github.nickm980.smallville.exceptions.AgentNotFoundException; import io.github.nickm980.smallville.exceptions.LocationNotFoundException; import io.github.nickm980.smallville.exceptions.SmallvilleException; import io.github.nickm980.smallville.llm.LLM; -import io.github.nickm980.smallville.models.AccessTime; -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.models.AgentLocation; -import io.github.nickm980.smallville.models.Conversation; -import io.github.nickm980.smallville.models.ObjectState; -import io.github.nickm980.smallville.models.SimulatedLocation; -import io.github.nickm980.smallville.models.SimulatedObject; -import io.github.nickm980.smallville.models.memory.Characteristic; import io.github.nickm980.smallville.update.UpdateService; public class SimulationService { @@ -154,4 +146,8 @@ public void createObject(CreateObjectRequest request) { world.save(object); } + + public void setGoal(String name, String goal) { + world.getAgent(name).orElseThrow().setGoal(goal); + } } diff --git a/smallville/src/main/java/io/github/nickm980/smallville/api/server/SmallvilleServer.java b/smallville/src/main/java/io/github/nickm980/smallville/api/SmallvilleServer.java similarity index 89% rename from smallville/src/main/java/io/github/nickm980/smallville/api/server/SmallvilleServer.java rename to smallville/src/main/java/io/github/nickm980/smallville/api/SmallvilleServer.java index ff2b85e..acfc615 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/api/server/SmallvilleServer.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/api/SmallvilleServer.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.api.server; +package io.github.nickm980.smallville.api; import java.io.StringWriter; import java.util.HashMap; @@ -9,14 +9,7 @@ import com.github.mustachejava.MustacheFactory; import io.github.nickm980.smallville.World; -import io.github.nickm980.smallville.api.AgentStateResponse; -import io.github.nickm980.smallville.api.AskQuestionRequest; -import io.github.nickm980.smallville.api.ConversationResponse; -import io.github.nickm980.smallville.api.CreateAgentRequest; -import io.github.nickm980.smallville.api.CreateLocationRequest; -import io.github.nickm980.smallville.api.CreateMemoryRequest; -import io.github.nickm980.smallville.api.CreateObjectRequest; -import io.github.nickm980.smallville.api.LocationStateResponse; +import io.github.nickm980.smallville.api.dto.*; import io.github.nickm980.smallville.llm.LLM; import io.javalin.Javalin; @@ -92,6 +85,17 @@ public void start(int port) { ctx.json(Map.of("answer", res)); }); + app.post("/agents/{name}/goal", (ctx) -> { + SetGoalRequest request = ctx + .bodyValidator(SetGoalRequest.class) + .check((req) -> exists(req.getGoal()), "{goal} cannot be blank") + .get(); + + service.setGoal(ctx.pathParam("name"), request.getGoal()); + + ctx.json(Map.of("success", true)); + }); + app.post("/agents", (ctx) -> { CreateAgentRequest request = ctx .bodyValidator(CreateAgentRequest.class) diff --git a/smallville/src/main/java/io/github/nickm980/smallville/api/AgentStateResponse.java b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/AgentStateResponse.java similarity index 94% rename from smallville/src/main/java/io/github/nickm980/smallville/api/AgentStateResponse.java rename to smallville/src/main/java/io/github/nickm980/smallville/api/dto/AgentStateResponse.java index d797b08..0d5640a 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/api/AgentStateResponse.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/AgentStateResponse.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.api; +package io.github.nickm980.smallville.api.dto; public class AgentStateResponse { private String name; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/api/AskQuestionRequest.java b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/AskQuestionRequest.java similarity index 81% rename from smallville/src/main/java/io/github/nickm980/smallville/api/AskQuestionRequest.java rename to smallville/src/main/java/io/github/nickm980/smallville/api/dto/AskQuestionRequest.java index 3e65eb8..80a7212 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/api/AskQuestionRequest.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/AskQuestionRequest.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.api; +package io.github.nickm980.smallville.api.dto; public class AskQuestionRequest { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/api/ConversationResponse.java b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/ConversationResponse.java similarity index 85% rename from smallville/src/main/java/io/github/nickm980/smallville/api/ConversationResponse.java rename to smallville/src/main/java/io/github/nickm980/smallville/api/dto/ConversationResponse.java index f91a658..ee754a6 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/api/ConversationResponse.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/ConversationResponse.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.api; +package io.github.nickm980.smallville.api.dto; import java.util.Map; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/api/CreateAgentRequest.java b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/CreateAgentRequest.java similarity index 93% rename from smallville/src/main/java/io/github/nickm980/smallville/api/CreateAgentRequest.java rename to smallville/src/main/java/io/github/nickm980/smallville/api/dto/CreateAgentRequest.java index 9467a58..9a6e561 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/api/CreateAgentRequest.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/CreateAgentRequest.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.api; +package io.github.nickm980.smallville.api.dto; import java.util.List; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/api/CreateLocationRequest.java b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/CreateLocationRequest.java similarity index 79% rename from smallville/src/main/java/io/github/nickm980/smallville/api/CreateLocationRequest.java rename to smallville/src/main/java/io/github/nickm980/smallville/api/dto/CreateLocationRequest.java index 9906c32..4c8117c 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/api/CreateLocationRequest.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/CreateLocationRequest.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.api; +package io.github.nickm980.smallville.api.dto; public class CreateLocationRequest { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/api/CreateMemoryRequest.java b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/CreateMemoryRequest.java similarity index 92% rename from smallville/src/main/java/io/github/nickm980/smallville/api/CreateMemoryRequest.java rename to smallville/src/main/java/io/github/nickm980/smallville/api/dto/CreateMemoryRequest.java index 728e3b1..b048621 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/api/CreateMemoryRequest.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/CreateMemoryRequest.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.api; +package io.github.nickm980.smallville.api.dto; public class CreateMemoryRequest { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/api/CreateObjectRequest.java b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/CreateObjectRequest.java similarity index 91% rename from smallville/src/main/java/io/github/nickm980/smallville/api/CreateObjectRequest.java rename to smallville/src/main/java/io/github/nickm980/smallville/api/dto/CreateObjectRequest.java index ffe61a9..eee36e1 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/api/CreateObjectRequest.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/CreateObjectRequest.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.api; +package io.github.nickm980.smallville.api.dto; public class CreateObjectRequest { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/api/LocationStateResponse.java b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/LocationStateResponse.java similarity index 87% rename from smallville/src/main/java/io/github/nickm980/smallville/api/LocationStateResponse.java rename to smallville/src/main/java/io/github/nickm980/smallville/api/dto/LocationStateResponse.java index 575fc90..9c72989 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/api/LocationStateResponse.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/LocationStateResponse.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.api; +package io.github.nickm980.smallville.api.dto; public class LocationStateResponse { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/api/MemoryResponse.java b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/MemoryResponse.java similarity index 94% rename from smallville/src/main/java/io/github/nickm980/smallville/api/MemoryResponse.java rename to smallville/src/main/java/io/github/nickm980/smallville/api/dto/MemoryResponse.java index e693126..a96e3b0 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/api/MemoryResponse.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/MemoryResponse.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.api; +package io.github.nickm980.smallville.api.dto; import java.time.LocalDateTime; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/api/ModelMapper.java b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/ModelMapper.java similarity index 74% rename from smallville/src/main/java/io/github/nickm980/smallville/api/ModelMapper.java rename to smallville/src/main/java/io/github/nickm980/smallville/api/dto/ModelMapper.java index ae7d8e0..3ee5506 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/api/ModelMapper.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/ModelMapper.java @@ -1,17 +1,17 @@ -package io.github.nickm980.smallville.api; +package io.github.nickm980.smallville.api.dto; import java.util.HashMap; import java.util.Map; -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.models.Conversation; -import io.github.nickm980.smallville.models.Dialog; -import io.github.nickm980.smallville.models.Location; -import io.github.nickm980.smallville.models.SimulatedObject; -import io.github.nickm980.smallville.models.memory.Characteristic; -import io.github.nickm980.smallville.models.memory.Memory; -import io.github.nickm980.smallville.models.memory.Plan; -import io.github.nickm980.smallville.models.memory.TemporalMemory; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.Conversation; +import io.github.nickm980.smallville.entities.Dialog; +import io.github.nickm980.smallville.entities.Location; +import io.github.nickm980.smallville.entities.SimulatedObject; +import io.github.nickm980.smallville.entities.memory.Characteristic; +import io.github.nickm980.smallville.entities.memory.Memory; +import io.github.nickm980.smallville.entities.memory.Plan; +import io.github.nickm980.smallville.entities.memory.TemporalMemory; public class ModelMapper { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/api/dto/SetGoalRequest.java b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/SetGoalRequest.java new file mode 100644 index 0000000..65b1510 --- /dev/null +++ b/smallville/src/main/java/io/github/nickm980/smallville/api/dto/SetGoalRequest.java @@ -0,0 +1,14 @@ +package io.github.nickm980.smallville.api.dto; + +public class SetGoalRequest { + + private String goal; + + public String getGoal() { + return goal; + } + + public void setGoal(String goal) { + this.goal = goal; + } +} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/config/GeneralConfig.java b/smallville/src/main/java/io/github/nickm980/smallville/config/GeneralConfig.java index 79f6377..77b8ee0 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/config/GeneralConfig.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/config/GeneralConfig.java @@ -4,6 +4,24 @@ public class GeneralConfig { private String apiPath; private String timeFormat; + private String fullTimeFormat; + private String yesterdayFormat; + + public String getYesterdayFormat() { + return yesterdayFormat; + } + + public void setYesterdayFormat(String yesterdayFormat) { + this.yesterdayFormat = yesterdayFormat; + } + + public String getFullTimeFormat() { + return fullTimeFormat; + } + + public void setFullTimeFormat(String fullTimeFormat) { + this.fullTimeFormat = fullTimeFormat; + } public String getTimeFormat() { return timeFormat; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/config/PromptsConfig.java b/smallville/src/main/java/io/github/nickm980/smallville/config/PromptsConfig.java deleted file mode 100644 index 5eb2b80..0000000 --- a/smallville/src/main/java/io/github/nickm980/smallville/config/PromptsConfig.java +++ /dev/null @@ -1,117 +0,0 @@ -package io.github.nickm980.smallville.config; - -public class PromptsConfig { - - private String createConversationWith; - private String createReactionSuggestion; - private String createCurrentPlanPrompt; - private String createMemoryRankPrompt; - private String createFuturePlansPrompt; - private String createAskQuestionPrompt; - private String createPastAndPresent; - private String createObjectUpdates; - private String pickLocation; - private String createShortTermPlans; - private String createMidTermPlans; - private String agentSummaryDescription; - - public String getAgentSummaryDescription() { - return agentSummaryDescription; - } - - public void setAgentSummaryDescription(String agentSummaryDescription) { - this.agentSummaryDescription = agentSummaryDescription; - } - - public String getCreateMidTermPlans() { - return createMidTermPlans; - } - - public void setCreateMidTermPlans(String createMidTermPlans) { - this.createMidTermPlans = createMidTermPlans; - } - - public PromptsConfig() { - } - - public String getCreateConversationWith() { - return createConversationWith; - } - - public void setCreateConversationWith(String createConversationWith) { - this.createConversationWith = createConversationWith; - } - - public String getCreateReactionSuggestion() { - return createReactionSuggestion; - } - - public void setCreateReactionSuggestion(String createReactionSuggestion) { - this.createReactionSuggestion = createReactionSuggestion; - } - - public String getCreateCurrentPlanPrompt() { - return createCurrentPlanPrompt; - } - - public void setCreateCurrentPlanPrompt(String createCurrentPlanPrompt) { - this.createCurrentPlanPrompt = createCurrentPlanPrompt; - } - - public String getCreateMemoryRankPrompt() { - return createMemoryRankPrompt; - } - - public void setCreateMemoryRankPrompt(String createMemoryRankPrompt) { - this.createMemoryRankPrompt = createMemoryRankPrompt; - } - - public String getCreateFuturePlansPrompt() { - return createFuturePlansPrompt; - } - - public void setCreateFuturePlansPrompt(String createFuturePlansPrompt) { - this.createFuturePlansPrompt = createFuturePlansPrompt; - } - - public String getCreateAskQuestionPrompt() { - return createAskQuestionPrompt; - } - - public void setCreateAskQuestionPrompt(String createAskQuestionPrompt) { - this.createAskQuestionPrompt = createAskQuestionPrompt; - } - - public String getCreatePastAndPresent() { - return createPastAndPresent; - } - - public void setCreatePastAndPresent(String createPastAndPresent) { - this.createPastAndPresent = createPastAndPresent; - } - - public String getCreateObjectUpdates() { - return createObjectUpdates; - } - - public void setCreateObjectUpdates(String createObjectUpdates) { - this.createObjectUpdates = createObjectUpdates; - } - - public String getPickLocation() { - return pickLocation; - } - - public void setPickLocation(String pickLocation) { - this.pickLocation = pickLocation; - } - - public String getCreateShortTermPlans() { - return createShortTermPlans; - } - - public void setCreateShortTermPlans(String createShortTermPlans) { - this.createShortTermPlans = createShortTermPlans; - } - -} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/config/Config.java b/smallville/src/main/java/io/github/nickm980/smallville/config/SmallvilleConfig.java similarity index 74% rename from smallville/src/main/java/io/github/nickm980/smallville/config/Config.java rename to smallville/src/main/java/io/github/nickm980/smallville/config/SmallvilleConfig.java index b13ddae..95d3f1a 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/config/Config.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/config/SmallvilleConfig.java @@ -10,19 +10,21 @@ import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.Yaml; -public class Config { - private static PromptsConfig prompts; +import io.github.nickm980.smallville.config.prompts.Prompts; + +public class SmallvilleConfig { + private static Prompts prompts; private static GeneralConfig config; - private static final Logger LOG = LoggerFactory.getLogger(Config.class); + private static final Logger LOG = LoggerFactory.getLogger(SmallvilleConfig.class); - private Config() { + private SmallvilleConfig() { } - public static PromptsConfig getPrompts() { + public static Prompts getPrompts() { if (prompts == null) { LOG.info("Loading prompts"); - prompts = loadFile("prompts.yaml", PromptsConfig.class); + prompts = loadFile("prompts.yaml", Prompts.class); } return prompts; @@ -52,7 +54,7 @@ private static T loadFile(String file, Class clazz) { } } else { LOG.debug("Loading default configuration"); - inputStream = Config.class.getResourceAsStream("/" + file); + inputStream = SmallvilleConfig.class.getResourceAsStream("/" + file); } if (inputStream == null) { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/AgentPrompts.java b/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/AgentPrompts.java new file mode 100644 index 0000000..5c9f347 --- /dev/null +++ b/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/AgentPrompts.java @@ -0,0 +1,32 @@ +package io.github.nickm980.smallville.config.prompts; + +public class AgentPrompts { + + private String characteristics; + private String summary; + private String askQuestion; + + public String getAskQuestion() { + return askQuestion; + } + + public void setAskQuestion(String askQuestion) { + this.askQuestion = askQuestion; + } + + public String getCharacteristics() { + return characteristics; + } + + public void setCharacteristics(String characteristics) { + this.characteristics = characteristics; + } + + public String getSummary() { + return summary; + } + + public void setSummary(String summary) { + this.summary = summary; + } +} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/MiscPrompts.java b/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/MiscPrompts.java new file mode 100644 index 0000000..7aa9ec6 --- /dev/null +++ b/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/MiscPrompts.java @@ -0,0 +1,41 @@ +package io.github.nickm980.smallville.config.prompts; + +public class MiscPrompts { + + private String rankMemories; + private String combineSentences; + private String debug; + private String relationship; + + public String getRelationship() { + return relationship; + } + + public void setRelationship(String relationship) { + this.relationship = relationship; + } + + public String getRankMemories() { + return rankMemories; + } + + public void setRankMemories(String rankMemories) { + this.rankMemories = rankMemories; + } + + public String getCombineSentences() { + return combineSentences; + } + + public void setCombineSentences(String combineSentences) { + this.combineSentences = combineSentences; + } + + public String getDebug() { + return debug; + } + + public void setDebug(String debug) { + this.debug = debug; + } +} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/PlanPrompts.java b/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/PlanPrompts.java new file mode 100644 index 0000000..30ac786 --- /dev/null +++ b/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/PlanPrompts.java @@ -0,0 +1,41 @@ +package io.github.nickm980.smallville.config.prompts; + +public class PlanPrompts { + + private String shortTerm; + private String longTerm; + private String midTerm; + private String current; + + public String getShortTerm() { + return shortTerm; + } + + public void setShortTerm(String shortTerm) { + this.shortTerm = shortTerm; + } + + public String getLongTerm() { + return longTerm; + } + + public void setLongTerm(String longTerm) { + this.longTerm = longTerm; + } + + public String getMidTerm() { + return midTerm; + } + + public void setMidTerm(String midTerm) { + this.midTerm = midTerm; + } + + public String getCurrent() { + return current; + } + + public void setCurrent(String current) { + this.current = current; + } +} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/Prompts.java b/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/Prompts.java new file mode 100644 index 0000000..80e8ed6 --- /dev/null +++ b/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/Prompts.java @@ -0,0 +1,50 @@ +package io.github.nickm980.smallville.config.prompts; + +public class Prompts { + + private ReactionPrompts reactions; + private WorldPrompts world; + private PlanPrompts plans; + private AgentPrompts agent; + private MiscPrompts misc; + + public ReactionPrompts getReactions() { + return reactions; + } + + public void setReactions(ReactionPrompts reactions) { + this.reactions = reactions; + } + + public WorldPrompts getWorld() { + return world; + } + + public void setWorld(WorldPrompts activity) { + this.world = activity; + } + + public PlanPrompts getPlans() { + return plans; + } + + public void setPlans(PlanPrompts plans) { + this.plans = plans; + } + + public AgentPrompts getAgent() { + return agent; + } + + public void setAgent(AgentPrompts agent) { + this.agent = agent; + } + + public MiscPrompts getMisc() { + return misc; + } + + public void setMisc(MiscPrompts misc) { + this.misc = misc; + } +} \ No newline at end of file diff --git a/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/ReactionPrompts.java b/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/ReactionPrompts.java new file mode 100644 index 0000000..362db57 --- /dev/null +++ b/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/ReactionPrompts.java @@ -0,0 +1,23 @@ +package io.github.nickm980.smallville.config.prompts; + +public class ReactionPrompts { + + private String reaction; + private String conversation; + + public String getReaction() { + return reaction; + } + + public void setReaction(String reaction) { + this.reaction = reaction; + } + + public String getConversation() { + return conversation; + } + + public void setConversation(String conversation) { + this.conversation = conversation; + } +} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/WorldPrompts.java b/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/WorldPrompts.java new file mode 100644 index 0000000..2689a74 --- /dev/null +++ b/smallville/src/main/java/io/github/nickm980/smallville/config/prompts/WorldPrompts.java @@ -0,0 +1,23 @@ +package io.github.nickm980.smallville.config.prompts; + +public class WorldPrompts { + + private String location; + private String objectStates; + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getObjectStates() { + return objectStates; + } + + public void setObjectStates(String objectStates) { + this.objectStates = objectStates; + } +} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/AccessTime.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/AccessTime.java similarity index 92% rename from smallville/src/main/java/io/github/nickm980/smallville/models/AccessTime.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/AccessTime.java index 9ae4c11..970013f 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/AccessTime.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/AccessTime.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.models; +package io.github.nickm980.smallville.entities; import java.time.LocalDateTime; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/ActionHistory.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/ActionHistory.java similarity index 92% rename from smallville/src/main/java/io/github/nickm980/smallville/models/ActionHistory.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/ActionHistory.java index c6e0bf4..c82f9aa 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/ActionHistory.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/ActionHistory.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.models; +package io.github.nickm980.smallville.entities; public class ActionHistory { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/Agent.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/Agent.java similarity index 79% rename from smallville/src/main/java/io/github/nickm980/smallville/models/Agent.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/Agent.java index b850542..1c4256b 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/Agent.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/Agent.java @@ -1,9 +1,9 @@ -package io.github.nickm980.smallville.models; +package io.github.nickm980.smallville.entities; import java.util.List; -import io.github.nickm980.smallville.models.memory.Characteristic; -import io.github.nickm980.smallville.models.memory.MemoryStream; -import io.github.nickm980.smallville.models.memory.Plan; +import io.github.nickm980.smallville.entities.memory.Characteristic; +import io.github.nickm980.smallville.entities.memory.MemoryStream; +import io.github.nickm980.smallville.entities.memory.Plan; public class Agent { @@ -11,6 +11,7 @@ public class Agent { private String name; private ActionHistory currentAction; private AgentLocation location; + private String goal = ""; public Agent(String name, List characteristics, String currentAction, AgentLocation location) { this.name = name; @@ -39,7 +40,7 @@ public void setCurrentActivity(String description) { public SimulatedObject getObject() { return location.getObject(); } - + public SimulatedLocation getLocation() { return location.getLocation(); } @@ -71,4 +72,12 @@ public void addPlans(List plans) { public List getPlans() { return memories.getPlans(); } + + public void setGoal(String goal) { + this.goal = goal; + } + + public String getGoal() { + return goal; + } } \ No newline at end of file diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/AgentLocation.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/AgentLocation.java similarity index 93% rename from smallville/src/main/java/io/github/nickm980/smallville/models/AgentLocation.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/AgentLocation.java index 5220a69..77018fc 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/AgentLocation.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/AgentLocation.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.models; +package io.github.nickm980.smallville.entities; import javax.annotation.Nullable; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/Conversation.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/Conversation.java similarity index 95% rename from smallville/src/main/java/io/github/nickm980/smallville/models/Conversation.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/Conversation.java index fec8ca0..bc694c1 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/Conversation.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/Conversation.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.models; +package io.github.nickm980.smallville.entities; import java.time.LocalDateTime; import java.util.ArrayList; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/Dialog.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/Dialog.java similarity index 90% rename from smallville/src/main/java/io/github/nickm980/smallville/models/Dialog.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/Dialog.java index 01c7342..c9f4b6f 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/Dialog.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/Dialog.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.models; +package io.github.nickm980.smallville.entities; public class Dialog implements NaturalLanguageConvertible { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/Location.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/Location.java similarity index 64% rename from smallville/src/main/java/io/github/nickm980/smallville/models/Location.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/Location.java index 305ae56..11d0a08 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/Location.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/Location.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.models; +package io.github.nickm980.smallville.entities; public interface Location extends NaturalLanguageConvertible { String getName(); diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/NaturalLanguageConvertible.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/NaturalLanguageConvertible.java similarity index 95% rename from smallville/src/main/java/io/github/nickm980/smallville/models/NaturalLanguageConvertible.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/NaturalLanguageConvertible.java index 566818d..1a6e54c 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/NaturalLanguageConvertible.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/NaturalLanguageConvertible.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.models; +package io.github.nickm980.smallville.entities; /** * An interface for objects that can be converted to a natural language string diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/ObjectState.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/ObjectState.java similarity index 90% rename from smallville/src/main/java/io/github/nickm980/smallville/models/ObjectState.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/ObjectState.java index c5801b0..1e43338 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/ObjectState.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/ObjectState.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.models; +package io.github.nickm980.smallville.entities; import java.util.List; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/SimulatedLocation.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/SimulatedLocation.java similarity index 86% rename from smallville/src/main/java/io/github/nickm980/smallville/models/SimulatedLocation.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/SimulatedLocation.java index dc4b11f..82cb0e3 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/SimulatedLocation.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/SimulatedLocation.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.models; +package io.github.nickm980.smallville.entities; import java.util.ArrayList; import java.util.List; @@ -36,13 +36,11 @@ public String getName() { @Override public String asNaturalLanguage() { - String childrenStr = ""; - - for (Location location : children) { - childrenStr += location.asNaturalLanguage() + ", "; + if (children.isEmpty()) { + return name; } - return name + " has " + childrenStr; + return name + " has " + String.join(";", children.stream().map(c -> c.getName()).toList()); } public List getObjects() { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/SimulatedObject.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/SimulatedObject.java similarity index 92% rename from smallville/src/main/java/io/github/nickm980/smallville/models/SimulatedObject.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/SimulatedObject.java index 3a6b62f..e594044 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/SimulatedObject.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/SimulatedObject.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.models; +package io.github.nickm980.smallville.entities; public class SimulatedObject implements Location { private ObjectState state; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/Characteristic.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/Characteristic.java similarity index 88% rename from smallville/src/main/java/io/github/nickm980/smallville/models/memory/Characteristic.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/memory/Characteristic.java index 85eb47d..6ec578e 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/Characteristic.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/Characteristic.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.models.memory; +package io.github.nickm980.smallville.entities.memory; /** * A Characteristic is a type of memory given to an agent before the simulation diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/Memory.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/Memory.java similarity index 96% rename from smallville/src/main/java/io/github/nickm980/smallville/models/memory/Memory.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/memory/Memory.java index 9e32772..142f252 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/Memory.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/Memory.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.models.memory; +package io.github.nickm980.smallville.entities.memory; import io.github.nickm980.smallville.math.SmallvilleMath; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/MemoryStream.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/MemoryStream.java similarity index 96% rename from smallville/src/main/java/io/github/nickm980/smallville/models/memory/MemoryStream.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/memory/MemoryStream.java index 8698fdb..0cafc9f 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/MemoryStream.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/MemoryStream.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.models.memory; +package io.github.nickm980.smallville.entities.memory; import java.time.LocalDateTime; import java.util.ArrayList; @@ -72,7 +72,7 @@ public List getPlans() { return memory instanceof Plan; }).map(memory -> { return (Plan) memory; - }).sorted(new TemporalMemoryComparator()).collect(Collectors.toList()); + }).sorted(new TemporalMemory.TemporalComparator()).collect(Collectors.toList()); } public void addAll(List memories) { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/Observation.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/Observation.java similarity index 90% rename from smallville/src/main/java/io/github/nickm980/smallville/models/memory/Observation.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/memory/Observation.java index df56cfe..2346d05 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/Observation.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/Observation.java @@ -1,10 +1,10 @@ -package io.github.nickm980.smallville.models.memory; +package io.github.nickm980.smallville.entities.memory; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; +import io.github.nickm980.smallville.entities.AccessTime; import io.github.nickm980.smallville.math.SmallvilleMath; -import io.github.nickm980.smallville.models.AccessTime; /** * Observations are past events (including dialog / conversations) that the diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/Plan.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/Plan.java similarity index 89% rename from smallville/src/main/java/io/github/nickm980/smallville/models/memory/Plan.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/memory/Plan.java index d0525fe..ddc8c95 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/Plan.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/Plan.java @@ -1,11 +1,11 @@ -package io.github.nickm980.smallville.models.memory; +package io.github.nickm980.smallville.entities.memory; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; +import io.github.nickm980.smallville.entities.AccessTime; +import io.github.nickm980.smallville.entities.NaturalLanguageConvertible; import io.github.nickm980.smallville.math.SmallvilleMath; -import io.github.nickm980.smallville.models.AccessTime; -import io.github.nickm980.smallville.models.NaturalLanguageConvertible; /** * Plans are basically just memories in the future tense. There are more events diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/PlanType.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/PlanType.java similarity index 52% rename from smallville/src/main/java/io/github/nickm980/smallville/models/memory/PlanType.java rename to smallville/src/main/java/io/github/nickm980/smallville/entities/memory/PlanType.java index 993e4d4..9810bea 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/PlanType.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/PlanType.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.models.memory; +package io.github.nickm980.smallville.entities.memory; public enum PlanType { SHORT_TERM, MID_TERM, LONG_TERM diff --git a/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/TemporalMemory.java b/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/TemporalMemory.java new file mode 100644 index 0000000..39e331a --- /dev/null +++ b/smallville/src/main/java/io/github/nickm980/smallville/entities/memory/TemporalMemory.java @@ -0,0 +1,17 @@ +package io.github.nickm980.smallville.entities.memory; + +import java.time.LocalDateTime; +import java.util.Comparator; + +public interface TemporalMemory { + LocalDateTime getTime(); + + public static class TemporalComparator implements Comparator { + + @Override + public int compare(TemporalMemory o1, TemporalMemory o2) { + return o1.getTime().compareTo(o2.getTime()); + } + + } +} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/llm/ChatGPT.java b/smallville/src/main/java/io/github/nickm980/smallville/llm/ChatGPT.java index f956196..d22db7b 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/llm/ChatGPT.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/llm/ChatGPT.java @@ -11,7 +11,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.github.nickm980.smallville.Settings; -import io.github.nickm980.smallville.config.Config; +import io.github.nickm980.smallville.config.SmallvilleConfig; import io.github.nickm980.smallville.exceptions.SmallvilleException; import io.github.nickm980.smallville.prompts.Prompt; import okhttp3.OkHttpClient; @@ -25,6 +25,8 @@ public class ChatGPT implements LLM { @Override public String sendChat(Prompt prompt, double temperature) { + long start = System.currentTimeMillis(); + OkHttpClient client = new OkHttpClient.Builder() .connectTimeout(10, TimeUnit.SECONDS) .writeTimeout(3, TimeUnit.MINUTES) @@ -55,7 +57,7 @@ public String sendChat(Prompt prompt, double temperature) { RequestBody body = RequestBody.create(json.getBytes()); Request request = new Request.Builder() - .url(Config.getConfig().getApiPath()) + .url(SmallvilleConfig.getConfig().getApiPath()) .addHeader("Content-Type", "application/json") .addHeader("Authorization", "Bearer " + Settings.getApiKey()) .post(body) @@ -82,6 +84,8 @@ public String sendChat(Prompt prompt, double temperature) { e.printStackTrace(); } + long end = System.currentTimeMillis(); + LOG.info("[Chat] Response took " + String.valueOf(start - end) + "ms"); return result; } diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/TemporalMemory.java b/smallville/src/main/java/io/github/nickm980/smallville/models/memory/TemporalMemory.java deleted file mode 100644 index 138c575..0000000 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/TemporalMemory.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.github.nickm980.smallville.models.memory; - -import java.time.LocalDateTime; - -public interface TemporalMemory { - LocalDateTime getTime(); -} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/TemporalMemoryComparator.java b/smallville/src/main/java/io/github/nickm980/smallville/models/memory/TemporalMemoryComparator.java deleted file mode 100644 index 5742d89..0000000 --- a/smallville/src/main/java/io/github/nickm980/smallville/models/memory/TemporalMemoryComparator.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.github.nickm980.smallville.models.memory; - -import java.util.Comparator; - -public class TemporalMemoryComparator implements Comparator { - - @Override - public int compare(TemporalMemory o1, TemporalMemory o2) { - return o1.getTime().compareTo(o2.getTime()); - } - -} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/prompts/AtomicPromptBuilder.java b/smallville/src/main/java/io/github/nickm980/smallville/prompts/AtomicPromptBuilder.java deleted file mode 100644 index 4010979..0000000 --- a/smallville/src/main/java/io/github/nickm980/smallville/prompts/AtomicPromptBuilder.java +++ /dev/null @@ -1,145 +0,0 @@ -package io.github.nickm980.smallville.prompts; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.github.nickm980.smallville.config.Config; -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.models.Location; -import io.github.nickm980.smallville.models.NaturalLanguageConvertible; -import io.github.nickm980.smallville.models.SimulatedLocation; -import io.github.nickm980.smallville.models.SimulatedObject; -import io.github.nickm980.smallville.models.memory.Characteristic; -import io.github.nickm980.smallville.models.memory.Memory; -import io.github.nickm980.smallville.models.memory.Plan; - -/** - * Creates the variable prompts and converts objects to natural language - * - */ -public class AtomicPromptBuilder { - private static final Logger LOG = LoggerFactory.getLogger(AtomicPromptBuilder.class); - /** - * [Current Time] - *

- * Example "It is currently 4:56 pm" - * - * @param time Current time - * @return Current time as natural language - */ - public String getTimeAsString(LocalDateTime time) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Config.getConfig().getTimeFormat()); - return "It is currently " + time.format(formatter); - } - - /** - * [World Description] - *

- * Location listing of the world - * - * @param list - * @return - */ - public String getWorldDescription(List list) { - var prompt = """ - Only use the following locations in your response. - - Locations: - """; - - for (Location location : list) { - prompt += location.asNaturalLanguage() + "; "; - } - - return prompt; - } - - /** - * [Agent's Summary Description] - *

- * This summary comprises agents’ identity information (e.g., name and - * personality), as well as a description of their main motivational drivers and - * statements that describes their current occupation and self-assessment. - *

- * To save costs it currently filters memories by instanceof - * {@link Characteristic} for the description - * - * @return - */ - public String getAgentSummaryDescription(Agent person) { - var prompt = Config.getPrompts().getAgentSummaryDescription(); - - List characteristics = person.getCharacteristics(); - String descriptions = characteristics.stream().map(Memory::getDescription).collect(Collectors.joining("; ")); - - prompt = prompt - .replace("%time%", LocalDateTime.now().toString()) - .replace("%name%", person.getFullName()) - .replace("%description%", descriptions) - .replace("%location%", person.getLocation().getName()); - - if (!person.getPlans().isEmpty()) { - prompt = prompt - .replace("%plans%", "Future Plans: " + asNaturalLanguage(person.getMemoryStream().getShortTermPlans())); - } else { - prompt = prompt.replace("%plans%", ""); - } - - return prompt; - } - - public String buildRelevantMemories(Agent agent, String observation) { - String result = ""; - - for (Memory memory : agent.getMemoryStream().getRelevantMemories(observation)) { - result += memory.getDescription(); - } - - LOG.info(agent.getFullName() + "'s relevant memories (" + observation + "): " + result); - return result; - } - - public String asNaturalLanguage(Collection convertibles) { - String result = ""; - - for (NaturalLanguageConvertible convertible : convertibles) { - result += convertible.asNaturalLanguage() + "; "; - } - - return result; - } - - public CharSequence getObjects(List objects) { - String result = ""; - - for (var obj : objects) { - result += obj.getName() + ", "; - } - - return result; - } - - public CharSequence getNextPlan(Agent agent) { - String result = ""; - - Plan plan = agent.getPlans().stream().sorted(new Comparator() { - @Override - public int compare(Plan o1, Plan o2) { - return o1.getTime().compareTo(o2.getTime()); - } - }).findFirst().orElse(null); - - if (plan == null) { - return result; - } - - return "The next plan for the day is: " + plan.asNaturalLanguage(); - } -} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/prompts/IPromptBuilder.java b/smallville/src/main/java/io/github/nickm980/smallville/prompts/IPromptBuilder.java deleted file mode 100644 index b3b6716..0000000 --- a/smallville/src/main/java/io/github/nickm980/smallville/prompts/IPromptBuilder.java +++ /dev/null @@ -1,83 +0,0 @@ -package io.github.nickm980.smallville.prompts; - -import java.util.List; - -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.models.Conversation; -import io.github.nickm980.smallville.models.SimulatedLocation; - -/** - * This interface represents a builder for creating prompts. - */ -public interface IPromptBuilder { - - /** - * Sets the agent for whom the prompt will be built. - * - * @param agent the agent for whom the prompt will be built - * @return the prompt builder instance - */ - PromptBuilder withAgent(Agent agent); - - /** - * Sets the list of locations relevant to the prompt. - * - * @param locations the list of locations relevant to the prompt - * @return the prompt builder instance - */ - PromptBuilder withLocations(List locations); - - /** - * Sets the conversation relevant to the prompt. - * - * @param conversation the conversation relevant to the prompt - * @return the prompt builder instance - */ - PromptBuilder withConversation(Conversation conversation); - - /** - * Creates a new conversation with another agent. - * - * @param other the other agent participating in the conversation - * @param topic the topic of the conversation - * @return the prompt builder instance - */ - PromptBuilder createConversationWith(Agent other); - - /** - * Creates a suggestion for how to react to a given observation. - * - * @param observation the observation to react to - * @return the prompt builder instance - */ - PromptBuilder createReactionSuggestion(String observation); - - /** - * Ranks the memories of the agent and adds them to the prompt. - * - * @return the prompt builder instance - */ - PromptBuilder createMemoryRankPrompt(); - - /** - * - * Builds and returns a Prompt object based on the previously specified - * properties. Must call a create method before building. Global parameters, as - * indicated by brackets [] are filled in - * - * @return The created Prompt object with all global placeholders formatted. - */ - Prompt build(); - - /** - * Ask an agent a question and get the result back as just the answer (not in - * JSON format) - *

- * Example: chat.send(createAskQuestionPrompt("What do you have planned for - * tomorrow?")) should return "Tomorrow I plan on..." - * - * @param question - * @return the prompt builder instance - */ - PromptBuilder createAskQuestionPrompt(String question); -} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/prompts/MiniPrompts.java b/smallville/src/main/java/io/github/nickm980/smallville/prompts/MiniPrompts.java new file mode 100644 index 0000000..37ad045 --- /dev/null +++ b/smallville/src/main/java/io/github/nickm980/smallville/prompts/MiniPrompts.java @@ -0,0 +1,63 @@ +package io.github.nickm980.smallville.prompts; + +import java.util.HashMap; +import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.github.nickm980.smallville.config.SmallvilleConfig; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.memory.Memory; +import io.github.nickm980.smallville.entities.memory.TemporalMemory; + +/** + * Creates the prompts used by other prompts and converts objects to natural + * language + * + */ +public class MiniPrompts { + private static final Logger LOG = LoggerFactory.getLogger(MiniPrompts.class); + + public String buildAgentSummary(Agent agent) { + String prompt = SmallvilleConfig.getPrompts().getAgent().getSummary(); + + Map data = new HashMap(); + data.put("agent.name", agent.getFullName()); + data.put("agent.locationName", agent.getLocation().getName()); + data.put("agent.description", agent.getCharacteristics().stream().map(c -> c.getDescription()).toList()); + + return new TemplateEngine().format(prompt, data); + } + + public Map fromAgent(Agent agent) { + Map result = new HashMap(); + result.put("name", agent.getFullName()); + result.put("memories", agent.getMemoryStream().getMemories().stream().limit(10).toList()); + result.put("activity", agent.getCurrentActivity()); + result.put("lastActivity", agent.getLastActivity()); + result.put("summary", buildAgentSummary(agent)); + result.put("locationName", agent.getLocation().getName()); + result.put("locationChildren", agent.getLocation().getObjects()); + result + .put("description", + String.join("; ", agent.getCharacteristics().stream().map(c -> c.getDescription()).toList())); + + result.put("_internal", agent); + + result + .put("plans", agent.getPlans().stream().sorted(new TemporalMemory.TemporalComparator()).limit(2).toList()); + + return result; + } + + public String buildRelevantMemories(Agent agent, String observation) { + String result = ""; + + for (Memory memory : agent.getMemoryStream().getRelevantMemories(observation)) { + result += memory.getDescription(); + } + + LOG.info(agent.getFullName() + "'s relevant memories (" + observation + "): " + result); + return result; + } +} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/prompts/PromptBuilder.java b/smallville/src/main/java/io/github/nickm980/smallville/prompts/PromptBuilder.java index 91733e4..602e5c8 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/prompts/PromptBuilder.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/prompts/PromptBuilder.java @@ -1,113 +1,101 @@ package io.github.nickm980.smallville.prompts; -import java.time.LocalDateTime; +import java.util.HashMap; import java.util.List; -import java.util.stream.Collectors; - +import java.util.Map; +import io.github.nickm980.smallville.World; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.Conversation; +import io.github.nickm980.smallville.entities.SimulatedLocation; import io.github.nickm980.smallville.exceptions.SmallvilleException; -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.models.Conversation; -import io.github.nickm980.smallville.models.SimulatedLocation; +import io.github.nickm980.smallville.prompts.dto.DateModel; +import io.github.nickm980.smallville.prompts.dto.WorldModel; -public class PromptBuilder implements IPromptBuilder { +public class PromptBuilder { - private PromptData data; - private AtomicPromptBuilder atomicBuilder; + private Map data; private String prompt; + private final MiniPrompts prompts; public PromptBuilder() { - this.atomicBuilder = new AtomicPromptBuilder(); - this.data = new PromptData(); + this.data = new HashMap<>(); + this.prompts = new MiniPrompts(); + + data.put("ping", "pong"); + data.put("date", new DateModel()); } - @Override public PromptBuilder withAgent(Agent agent) { - data.setAgent(agent); + data.put("agent", prompts.fromAgent(agent)); + + if (data.get("memories.unranked") == null) { + data.put("memories.unranked", agent.getMemoryStream().getCharacteristics()); + } + + if (data.get("memories.characteristics") == null) { + data.put("memories.characteristics", agent.getMemoryStream().getMemories()); + } + + if (data.get("observation") != null) { + data.put("memories.relevant", prompts.buildRelevantMemories(agent, (String) data.get("observation"))); + } + return this; } - @Override public PromptBuilder withLocations(List locations) { - data.setLocations(locations); + data.put("locations", locations); return this; } - @Override public PromptBuilder withConversation(Conversation conversation) { - data.setConversation(conversation); + data.put("conversation", conversation); return this; } - public PromptBuilder withPrompt(String prompt) { - this.prompt = prompt; + public PromptBuilder withOther(Agent other) { + data.put("other", prompts.fromAgent(other)); return this; } - @Override - public PromptBuilder createConversationWith(Agent other) { - prompt - .replace("%other_summary_description%", atomicBuilder.getAgentSummaryDescription(other)) - .replace("%other_name%", other.getFullName()); + public PromptBuilder withWorld(World world) { + data.put("world", WorldModel.fromWorld(world)); + + if (data.get("locations") == null) { + data.put("locations", world.getLocations()); + } + return this; } - @Override - public PromptBuilder createReactionSuggestion(String observation) { - prompt = prompt - .replace("%relevant_memories%", atomicBuilder.buildRelevantMemories(data.getAgent(), observation)) - .replace("%observation%", observation); - + public PromptBuilder withQuestion(String question) { + data.put("question", question); return this; } - @Override - public PromptBuilder createMemoryRankPrompt() { - prompt = String - .format(prompt, - data - .getAgent() - .getMemoryStream() - .getUnweightedMemories() - .stream() - .map(memory -> memory.getDescription()) - .collect(Collectors.joining(", "))); + public PromptBuilder withObservation(String observation) { + data.put("observation", observation); return this; } - @Override - public PromptBuilder createAskQuestionPrompt(String question) { - prompt = prompt - .replace("%question%", question) - .replace("%relevant_memories%", atomicBuilder.buildRelevantMemories(data.getAgent(), question)); + public PromptBuilder setPrompt(String prompt) { + this.prompt = prompt; + return this; + } + public PromptBuilder withTense(String tenses) { + data.put("tenses", tenses); return this; } - @Override public Prompt build() { if (prompt == null || prompt.isEmpty()) { throw new SmallvilleException("Must call a creation function to make a new prompt first"); } - Agent agent = data.getAgent(); - - prompt = prompt - .replace("[World Description]", atomicBuilder.getWorldDescription(data.getLocations())) - .replace("[Agent Summary Description]", atomicBuilder.getAgentSummaryDescription(agent)) - .replace("[Current Time]", atomicBuilder.getTimeAsString(LocalDateTime.now())) - .replace("[Agent Name]", agent.getFullName()) - .replace("[Current Location]", agent.getLocation().getName()) - .replace("[Current Location's Objects]", atomicBuilder.getObjects(agent.getLocation().getObjects())) - .replace("[Current Activity]", agent.getCurrentActivity()) - .replace("[Last Activity]", agent.getLastActivity()) - .replace("[Most Recent Plan]", atomicBuilder.getNextPlan(agent)) - .replace("[Future Plans]", "Plans: " + atomicBuilder.asNaturalLanguage(agent.getPlans())); + TemplateEngine engine = new TemplateEngine(); + prompt = engine.format(prompt, data); return new Prompt.User(prompt); } - - public PromptBuilder createObjectUpdates(String tenses) { - prompt = prompt.replace("%tenses%", tenses); - return this; - } } \ No newline at end of file diff --git a/smallville/src/main/java/io/github/nickm980/smallville/prompts/PromptData.java b/smallville/src/main/java/io/github/nickm980/smallville/prompts/PromptData.java deleted file mode 100644 index 9a3bdfd..0000000 --- a/smallville/src/main/java/io/github/nickm980/smallville/prompts/PromptData.java +++ /dev/null @@ -1,65 +0,0 @@ -package io.github.nickm980.smallville.prompts; - -import java.util.ArrayList; -import java.util.List; - -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.models.Conversation; -import io.github.nickm980.smallville.models.SimulatedLocation; - -public class PromptData { - - private Agent agent; - private List locations; - private Conversation conversation; - private String question; - private TimePhrase phrase; - - public PromptData() { - this.locations = new ArrayList(); - this.locations = List.of(); - this.question = ""; - this.phrase = TimePhrase.DAY; - } - - public Agent getAgent() { - return agent; - } - - public void setAgent(Agent agent) { - this.agent = agent; - } - - public List getLocations() { - return locations; - } - - public void setLocations(List locations) { - this.locations = locations; - } - - public void setConversation(Conversation conversation) { - this.conversation = conversation; - } - - public Conversation getConversation() { - return conversation; - } - - public void setQuestion(String question) { - this.question = question; - } - - public String getQuestion() { - return question; - } - - public void setTimePhrase(TimePhrase phrase) { - this.phrase = phrase; - } - - public TimePhrase getTimePhrase() { - return phrase; - } - -} \ No newline at end of file diff --git a/smallville/src/main/java/io/github/nickm980/smallville/prompts/TemplateEngine.java b/smallville/src/main/java/io/github/nickm980/smallville/prompts/TemplateEngine.java new file mode 100644 index 0000000..5741318 --- /dev/null +++ b/smallville/src/main/java/io/github/nickm980/smallville/prompts/TemplateEngine.java @@ -0,0 +1,19 @@ +package io.github.nickm980.smallville.prompts; + +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Map; +import com.github.mustachejava.DefaultMustacheFactory; +import com.github.mustachejava.Mustache; +import com.github.mustachejava.MustacheFactory; + +public class TemplateEngine { + public String format(String template, Map data) { + MustacheFactory mf = new DefaultMustacheFactory(); + + Mustache mustache = mf.compile(new StringReader(template), template); + StringWriter writer = new StringWriter(); + mustache.execute(writer, data); + return writer.toString().replaceAll(" ", "\n").trim(); + } +} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/prompts/TimePhrase.java b/smallville/src/main/java/io/github/nickm980/smallville/prompts/TimePhrase.java deleted file mode 100644 index af65488..0000000 --- a/smallville/src/main/java/io/github/nickm980/smallville/prompts/TimePhrase.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.github.nickm980.smallville.prompts; - -public enum TimePhrase { - - MINUTES("the next 15 minutes"), HOURS("the next few hours"), DAY("the rest of the day"); - - String phrase; - - TimePhrase(String time) { - this.phrase = time; - } - - public String getPhrase() { - return phrase; - } -} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/prompts/response/CurrentActivity.java b/smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/CurrentActivity.java similarity index 93% rename from smallville/src/main/java/io/github/nickm980/smallville/prompts/response/CurrentActivity.java rename to smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/CurrentActivity.java index 49be864..a7c9372 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/prompts/response/CurrentActivity.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/CurrentActivity.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.prompts.response; +package io.github.nickm980.smallville.prompts.dto; public class CurrentActivity { private String lastActivity; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/DateModel.java b/smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/DateModel.java new file mode 100644 index 0000000..c6d5447 --- /dev/null +++ b/smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/DateModel.java @@ -0,0 +1,26 @@ +package io.github.nickm980.smallville.prompts.dto; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import io.github.nickm980.smallville.config.SmallvilleConfig; + +public class DateModel { + + public String getTime() { + return format(LocalDateTime.now(), SmallvilleConfig.getConfig().getTimeFormat()); + } + + public String getFull() { + return format(LocalDateTime.now(), SmallvilleConfig.getConfig().getFullTimeFormat()); + } + + public String getYesterday() { + return format(LocalDateTime.now().minusDays(1), SmallvilleConfig.getConfig().getYesterdayFormat()); + } + + private String format(LocalDateTime time, String pattern) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); + return time.format(formatter); + } +} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/prompts/response/ObjectChangeResponse.java b/smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/ObjectChangeResponse.java similarity index 89% rename from smallville/src/main/java/io/github/nickm980/smallville/prompts/response/ObjectChangeResponse.java rename to smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/ObjectChangeResponse.java index 02b2460..eb9c763 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/prompts/response/ObjectChangeResponse.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/ObjectChangeResponse.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.prompts.response; +package io.github.nickm980.smallville.prompts.dto; public class ObjectChangeResponse { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/prompts/response/Reaction.java b/smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/Reaction.java similarity index 90% rename from smallville/src/main/java/io/github/nickm980/smallville/prompts/response/Reaction.java rename to smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/Reaction.java index 7c6b494..4ef8358 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/prompts/response/Reaction.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/Reaction.java @@ -1,4 +1,4 @@ -package io.github.nickm980.smallville.prompts.response; +package io.github.nickm980.smallville.prompts.dto; public class Reaction { private boolean react; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/WorldModel.java b/smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/WorldModel.java new file mode 100644 index 0000000..ff68b82 --- /dev/null +++ b/smallville/src/main/java/io/github/nickm980/smallville/prompts/dto/WorldModel.java @@ -0,0 +1,30 @@ +package io.github.nickm980.smallville.prompts.dto; + +import io.github.nickm980.smallville.World; +import io.github.nickm980.smallville.entities.Location; + +public class WorldModel { + + private String description; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public static WorldModel fromWorld(World world) { + WorldModel result = new WorldModel(); + String description = "Available Locations: "; + + for (Location location : world.getLocations()) { + description += location.asNaturalLanguage() + "; "; + } + + result.setDescription(description); + + return result; + } +} diff --git a/smallville/src/main/java/io/github/nickm980/smallville/update/AgentUpdate.java b/smallville/src/main/java/io/github/nickm980/smallville/update/AgentUpdate.java index 7c09ed4..32d3cb8 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/update/AgentUpdate.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/update/AgentUpdate.java @@ -4,7 +4,7 @@ import org.slf4j.LoggerFactory; import io.github.nickm980.smallville.World; -import io.github.nickm980.smallville.models.Agent; +import io.github.nickm980.smallville.entities.Agent; public abstract class AgentUpdate { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/update/ChatService.java b/smallville/src/main/java/io/github/nickm980/smallville/update/ChatService.java index 5bd7234..6066d6b 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/update/ChatService.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/update/ChatService.java @@ -15,21 +15,21 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.github.nickm980.smallville.World; -import io.github.nickm980.smallville.config.Config; +import io.github.nickm980.smallville.config.SmallvilleConfig; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.Conversation; +import io.github.nickm980.smallville.entities.Dialog; +import io.github.nickm980.smallville.entities.memory.Memory; +import io.github.nickm980.smallville.entities.memory.Observation; +import io.github.nickm980.smallville.entities.memory.Plan; import io.github.nickm980.smallville.llm.LLM; -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.models.Conversation; -import io.github.nickm980.smallville.models.Dialog; -import io.github.nickm980.smallville.models.memory.Memory; -import io.github.nickm980.smallville.models.memory.Observation; -import io.github.nickm980.smallville.models.memory.Plan; import io.github.nickm980.smallville.nlp.LocalNLP; import io.github.nickm980.smallville.nlp.NLPCoreUtils; import io.github.nickm980.smallville.prompts.Prompt; import io.github.nickm980.smallville.prompts.PromptBuilder; -import io.github.nickm980.smallville.prompts.response.CurrentActivity; -import io.github.nickm980.smallville.prompts.response.ObjectChangeResponse; -import io.github.nickm980.smallville.prompts.response.Reaction; +import io.github.nickm980.smallville.prompts.dto.CurrentActivity; +import io.github.nickm980.smallville.prompts.dto.ObjectChangeResponse; +import io.github.nickm980.smallville.prompts.dto.Reaction; public class ChatService implements IChatService { @@ -42,13 +42,12 @@ public ChatService(World world, LLM chat) { this.chat = chat; this.world = world; } - + @Override public int[] getWeights(Agent agent) { Prompt prompt = new PromptBuilder() .withAgent(agent) - .withPrompt(Config.getPrompts().getCreateMemoryRankPrompt()) - .createMemoryRankPrompt() + .setPrompt(SmallvilleConfig.getPrompts().getMisc().getRankMemories()) .build(); String response = chat.sendChat(prompt, .1); @@ -76,8 +75,7 @@ public Reaction getReaction(Agent agent, String observation) { Prompt prompt = new PromptBuilder() .withAgent(agent) .withLocations(world.getLocations()) - .withPrompt(Config.getPrompts().getCreateReactionSuggestion()) - .createReactionSuggestion(observation) + .setPrompt(SmallvilleConfig.getPrompts().getReactions().getReaction()) .build(); String response = chat.sendChat(prompt, 1); @@ -109,8 +107,7 @@ public String ask(Agent agent, String question) { Prompt prompt = new PromptBuilder() .withAgent(agent) .withLocations(world.getLocations()) - .withPrompt(Config.getPrompts().getCreateAskQuestionPrompt()) - .createAskQuestionPrompt(question) + .setPrompt(SmallvilleConfig.getPrompts().getAgent().getAskQuestion()) .build(); return chat.sendChat(prompt, .9); @@ -121,11 +118,11 @@ public List getPlans(Agent agent) { Prompt prompt = new PromptBuilder() .withLocations(world.getLocations()) .withAgent(agent) - .withPrompt(Config.getPrompts().getCreateFuturePlansPrompt()) + .setPrompt(SmallvilleConfig.getPrompts().getPlans().getLongTerm()) .build(); - String response = chat.sendChat(prompt, .4); - + String response = chat.sendChat(prompt, .2); + LOG.info(response); return parsePlans(response); } @@ -134,7 +131,7 @@ public List getShortTermPlans(Agent agent) { Prompt prompt = new PromptBuilder() .withLocations(world.getLocations()) .withAgent(agent) - .withPrompt(Config.getPrompts().getCreateShortTermPlans()) + .setPrompt(SmallvilleConfig.getPrompts().getPlans().getShortTerm()) .build(); String response = chat.sendChat(prompt, .7); @@ -148,10 +145,10 @@ public CurrentActivity getCurrentPlan(Agent agent) { Prompt prompt = new PromptBuilder() .withAgent(agent) .withLocations(world.getLocations()) - .withPrompt(Config.getPrompts().getCreateCurrentPlanPrompt()) + .setPrompt(SmallvilleConfig.getPrompts().getPlans().getCurrent()) .build(); NLPCoreUtils nlp = new LocalNLP(); - + String response = chat.sendChat(prompt, .7);// higher value provides better results for emojis response = response.substring(response.indexOf("{")); @@ -178,8 +175,7 @@ public CurrentActivity getCurrentPlan(Agent agent) { public Conversation getConversationIfExists(Agent agent, Agent other) { Prompt prompt = new PromptBuilder() .withAgent(agent) - .withPrompt(Config.getPrompts().getCreateConversationWith()) - .createConversationWith(other) + .setPrompt(SmallvilleConfig.getPrompts().getReactions().getConversation()) .build(); String response = chat.sendChat(prompt, .7); @@ -252,16 +248,16 @@ private LocalDateTime parseTime(String input, String line) throws DateTimeParseE public ObjectChangeResponse[] getObjectsChangedBy(Agent agent) { Prompt tensesPrompt = new PromptBuilder() .withAgent(agent) - .withPrompt(Config.getPrompts().getCreatePastAndPresent()) - .build(); + .setPrompt(SmallvilleConfig.getPrompts().getMisc().getCombineSentences()) + .build(); // might be able to use LocalNLP for this String tenses = chat.sendChat(tensesPrompt, .1); Prompt changedPrompt = new PromptBuilder() .withAgent(agent) + .withTense(tenses) .withLocations(world.getLocations()) - .withPrompt(Config.getPrompts().getCreateObjectUpdates()) - .createObjectUpdates(tenses) + .setPrompt(SmallvilleConfig.getPrompts().getWorld().getObjectStates()) .build(); String response = chat.sendChat(changedPrompt, .3); @@ -290,7 +286,10 @@ public ObjectChangeResponse[] getObjectsChangedBy(Agent agent) { @Override public String getExactLocation(Agent agent) { - Prompt prompt = new PromptBuilder().withAgent(agent).withPrompt(Config.getPrompts().getPickLocation()).build(); + Prompt prompt = new PromptBuilder() + .withAgent(agent) + .setPrompt(SmallvilleConfig.getPrompts().getWorld().getLocation()) + .build(); return chat.sendChat(prompt, 0); } @@ -300,12 +299,12 @@ public List convertFuturePlansToMemories(List plans) { return new ArrayList(); } LocalNLP nlp = new LocalNLP(); - + List result = new ArrayList(); for (Plan plan : plans) { String pastTense = nlp.convertToPastTense(plan.getDescription()); - + result.add(new Observation(pastTense, plan.getTime(), (int) plan.getImportance())); } diff --git a/smallville/src/main/java/io/github/nickm980/smallville/update/IChatService.java b/smallville/src/main/java/io/github/nickm980/smallville/update/IChatService.java index c1cc72d..312fb61 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/update/IChatService.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/update/IChatService.java @@ -1,18 +1,16 @@ package io.github.nickm980.smallville.update; -import java.time.LocalDateTime; -import java.time.format.DateTimeParseException; import java.util.List; -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.models.Conversation; -import io.github.nickm980.smallville.models.memory.Memory; -import io.github.nickm980.smallville.models.memory.Plan; -import io.github.nickm980.smallville.prompts.response.CurrentActivity; -import io.github.nickm980.smallville.prompts.response.ObjectChangeResponse; -import io.github.nickm980.smallville.prompts.response.Reaction; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.Conversation; +import io.github.nickm980.smallville.entities.memory.Memory; +import io.github.nickm980.smallville.entities.memory.Plan; +import io.github.nickm980.smallville.prompts.dto.CurrentActivity; +import io.github.nickm980.smallville.prompts.dto.ObjectChangeResponse; +import io.github.nickm980.smallville.prompts.dto.Reaction; -interface IChatService { +public interface IChatService { String getExactLocation(Agent agent); diff --git a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateAgentExactLocation.java b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateAgentExactLocation.java index 08e0f8e..e745ef0 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateAgentExactLocation.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateAgentExactLocation.java @@ -1,9 +1,9 @@ package io.github.nickm980.smallville.update; import io.github.nickm980.smallville.World; -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.models.AgentLocation; -import io.github.nickm980.smallville.models.SimulatedObject; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.AgentLocation; +import io.github.nickm980.smallville.entities.SimulatedObject; public class UpdateAgentExactLocation extends AgentUpdate { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateConversation.java b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateConversation.java index fa9da35..b29a1d1 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateConversation.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateConversation.java @@ -3,9 +3,9 @@ import java.util.List; import io.github.nickm980.smallville.World; -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.models.Conversation; -import io.github.nickm980.smallville.models.Dialog; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.Conversation; +import io.github.nickm980.smallville.entities.Dialog; import io.github.nickm980.smallville.nlp.LocalNLP; import io.github.nickm980.smallville.nlp.NLPCoreUtils; diff --git a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateCurrentActivity.java b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateCurrentActivity.java index b383e98..47f1f92 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateCurrentActivity.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateCurrentActivity.java @@ -1,10 +1,10 @@ package io.github.nickm980.smallville.update; import io.github.nickm980.smallville.World; -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.models.AgentLocation; -import io.github.nickm980.smallville.models.SimulatedLocation; -import io.github.nickm980.smallville.prompts.response.CurrentActivity; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.AgentLocation; +import io.github.nickm980.smallville.entities.SimulatedLocation; +import io.github.nickm980.smallville.prompts.dto.CurrentActivity; public class UpdateCurrentActivity extends AgentUpdate { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateFuturePlans.java b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateFuturePlans.java index c110476..c865297 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateFuturePlans.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateFuturePlans.java @@ -3,10 +3,9 @@ import java.util.List; import io.github.nickm980.smallville.World; -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.models.memory.Observation; -import io.github.nickm980.smallville.models.memory.Plan; -import io.github.nickm980.smallville.models.memory.PlanType; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.memory.Plan; +import io.github.nickm980.smallville.entities.memory.PlanType; public class UpdateFuturePlans extends AgentUpdate { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateLocations.java b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateLocations.java index a20c462..b6b2a64 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateLocations.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateLocations.java @@ -1,8 +1,8 @@ package io.github.nickm980.smallville.update; import io.github.nickm980.smallville.World; -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.prompts.response.ObjectChangeResponse; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.prompts.dto.ObjectChangeResponse; public class UpdateLocations extends AgentUpdate { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateMemoryWeights.java b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateMemoryWeights.java index 2bb346d..7e4ad87 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateMemoryWeights.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateMemoryWeights.java @@ -3,8 +3,8 @@ import java.util.List; import io.github.nickm980.smallville.World; -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.models.memory.Memory; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.memory.Memory; public class UpdateMemoryWeights extends AgentUpdate { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateReaction.java b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateReaction.java index 26cd892..597ded4 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateReaction.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateReaction.java @@ -1,8 +1,8 @@ package io.github.nickm980.smallville.update; import io.github.nickm980.smallville.World; -import io.github.nickm980.smallville.models.Agent; -import io.github.nickm980.smallville.prompts.response.Reaction; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.prompts.dto.Reaction; public class UpdateReaction extends AgentUpdate { diff --git a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateService.java b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateService.java index 3511edf..4bdc5a7 100644 --- a/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateService.java +++ b/smallville/src/main/java/io/github/nickm980/smallville/update/UpdateService.java @@ -4,8 +4,8 @@ import org.slf4j.LoggerFactory; import io.github.nickm980.smallville.World; +import io.github.nickm980.smallville.entities.Agent; import io.github.nickm980.smallville.llm.LLM; -import io.github.nickm980.smallville.models.Agent; /** * @@ -19,10 +19,8 @@ public class UpdateService { private final World world; private final ChatService chatService; private final Logger LOG = LoggerFactory.getLogger(UpdateService.class); - private boolean updateInProgress; public UpdateService(LLM chat, World world) { - this.updateInProgress = false; this.world = world; this.chatService = new ChatService(world, chat); } diff --git a/smallville/src/main/resources/config.yaml b/smallville/src/main/resources/config.yaml index b0030c2..8a532d5 100644 --- a/smallville/src/main/resources/config.yaml +++ b/smallville/src/main/resources/config.yaml @@ -1,2 +1,4 @@ apiPath: "https://api.openai.com/v1/chat/completions" -timeFormat: "h:mm a" \ No newline at end of file +timeFormat: "h:mm a" +fullTimeFormat: "EEEE, MMMM d, h:mm a" +yesterdayFormat: "EEEE MMMM d" diff --git a/smallville/src/main/resources/prompts.yaml b/smallville/src/main/resources/prompts.yaml index 4064051..c9560be 100644 --- a/smallville/src/main/resources/prompts.yaml +++ b/smallville/src/main/resources/prompts.yaml @@ -1,145 +1,159 @@ -agentSummaryDescription: | - Pretend you are %name% - - Name: %name% - Description: %description% - Current Location: %location% - - [Current Time] - -createConversationWith: | - [Agent Summary Description] - [Future Plans] - - %other_summary_description% - First, decide whether or not [Agent Name] is going to initiate a conversation. - - If [Agent Name] is not going to initiate a conversation respond with "No conversation" - - Otherwise, create a fake conversation between [Agent Name] and %other_name% - - For example, a conversation between people named A and B would look like this - - A: Hello, how are you today? - B: I am good, and you? - -createReactionSuggestion: | - [World Description] - [Agent Summary Description] - [Future Plans] - [Agent Name]’s status: [Current Activity] - Observation: %observation% - Summary of relevant context from [Agent Name]’s memory: %relevant_memories% - - Should [Agent Name] react to the observation, and if so, what would the reaction be? - - * Prefer to stay in a close by area - - Respond in the following JSON format: - - { - "react": "", - "action": "I am ", - "emoji": "", - } - -createCurrentPlanPrompt: | - [World Description] - [Agent Summary Description] - Most Recent Plan: [Most Recent Plan] - - Based on the time of day [Current Time] and the most recent plan, what will you be doing now? - Also choose an emoji based on the activity. - - Respond confidently in the following JSON format - - { - "activity": "I am ", - "location": "", - "emoji": "", - } - -pickLocation: | - You are currently in the [Current Location] - Current Activity: [Current Activity] - Based on the following objects [Current Location's Objects] which one will you interact with? - - Do not include punctuation. - -createMemoryRankPrompt: > - On the scale of 1 to 10, where 1 is purely mundane - (e.g., brushing teeth, making bed) and 10 is extremely poignant (e.g., a break up, college - acceptance), rate the likely poignancy of the following pieces of memory. Always answer with only a list of numbers. For example, if given the following memories Memories: John did nothing; John lin went to school; John lin saw a concert - respond with [1, 2, 6]. If just given one memory still respond in a list. Memories are separated by semi colans (;) - - Memories: %s - -createShortTermPlans: > - [World Description] - [Agent Summary Description] - - * Every plan should get its own line. - * Give a start time for every plan and format the time as "hh:mm a" - - [Future Plans] - - - [Last Activity] - What will [Agent Name] do every minute for the next 20 minutes? Start at the current time and end 20 minutes from now. - Respond with 20 plans. - [Current Time] - -createMidTermPlans: > - [World Description] - [Agent Summary Description] - - * Every plan should get its own line. - * When responding with a time, use the format " hh:mm a " - - [Future Plans] - - List what [Agent Name] has planned every 20 minutes. Start at the current time. [Current Time] - -createFuturePlansPrompt: > - [World Description] - [Agent Summary Description] - - * Every plan should be on a new line - * When responding with a time, use the format " hh:mm a " - - - Today is Wednesday, February 13. What does [Agent Name] have planned for today? - - * Start every plan on a new line with the start and ending time - * Include a plan for the current time - [Current Time] - -createAskQuestionPrompt: | - [World Description] - [Agent Summary Description] - %relevant_memories% - - Pretend you are [Agent Name] and answer the following question in the first person: %question% - -createPastAndPresent: | - [Agent Name]'s current status: [Current Activity] - [Agent Name]'s past status: [Last Activity] - - Format the current and past activity to say x is no longer {past status} and is now {current status} - -createObjectUpdates: | - [World Description] - - %tenses% - - What are the new states of the objects? - Respond in the following format: - - : - : - ... - - For example, if you are no longer cooking coffee and are now taking a shower - - Coffee Machine: Off - Shower: On \ No newline at end of file +reactions: + conversation: | + {{agent.summary}} + {{other.summary}} + + First, decide whether or not {{agent.name}} is going to initiate a conversation. + + If {{agent.name}} is not going to initiate a conversation respond with "No conversation" + + Otherwise, create a fake conversation between {{agent.name}} and {{other.name}} + + For example, a conversation between people named A and B would look like this + + A: Hello, how are you today? + B: I am good, and you? + reaction: | + {{world.description}} + {{agent.summary}} + + Observation: {{observation}} + Summary of relevant context from {{agent.name}}'s memory: {{memories.relevant}} + + Should {{agent.name}} react to the observation? If the agent is observing another agent, should they initiate a conversation? + * Prefer to stay in a close by area + + Respond in the following JSON format: + + { + "react": "", + "action": "I am ", + "emoji": "", + } + +world: + location: | + You were last in the {{agent.locationName}} + + Current Activity: {{agent.activity}} + Available Objects: {{#agent.locationChildren}}{{name}}; {{/agent.locationChildren}} + + Which one will you interact with? + + Do not include punctuation. + objectStates: | + {{world.description}} + + {{tenses}} + + What are the new states of the objects? + Respond in the following format: + + : + : + ... + + For example, if you are no longer cooking coffee and are now taking a shower + + Coffee Machine: Off + Shower: On + +plans: + shortTerm: | + {{world.description}} + {{agent.summary}} + + * Every plan should get its own line. + * Give a start time for every plan and format the time as "hh:mm a" + + Last Activity: {{agent.lastActivity}} + + Plans: {{#agent.plans}}{{description}};{{/agent.plans}} + + What will you do every minute for the next 20 minutes? Start at the current time and end 20 minutes from now. + Respond with 20 plans. + + It is currently {{date.time}} + + midTerm: | + {{world.description}} + {{agent.summary}} + + * Every plan should get its own line. + * When responding with a time, use the format " hh:mm a " + + {{#agent.plans}} + - {{description}} + {{/agent.plans}} + + List what {{agent.name}} has planned every hour. Start at {{date.time}}. + + longTerm: | + {{world.description}} + {{agent.summary}} + + * Every plan should be on a new line + * When responding with a time, use the format "hh:mm a" + + Today is {{date.full}}. What does {{agent.name}} have planned for today in broad strokes? + + * Start every plan on a new line with the start and ending time + * Include a plan for the current time + + current: | + {{world.description}} + {{agent.summary}} + + Last Activity: {{agent.lastActivity}} + Most Recent Plan: {{agent.lastPlan}} + + What are you doing now? It is currently {{date.time}} + + Respond confidently in the following JSON format and choose an emoji to represent the activity. + + { + "activity": "I am ", + "location": "", + "emoji": "", + } + +agent: + characteristics: | + How would one describe {{agent.name}}'s core characteristics + given the following statements? + {{#memories.characteristics}} + - {{description}} + {{/memories.characteristics}} + + summary: | + Pretend you are {{agent.name}} + + Name: {{agent.name}} + Description: {{agent.description}} + Current Location: {{agent.locationName}} + + {{date.full}} + askQuestion: | + {{memories.relevant}} + + Pretend you are {{agent.name}} and answer the following question in the first person: {{question}} + +misc: + combineSentences: | + {{agent.name}}'s current status: {{agent.activity}} + {{agent.name}}'s past status: {{agent.lastActivity}} + + Format the current and past activity to say x is no longer {past status} and is now {current status} + rankMemories: | + On the scale of 1 to 10, where 1 is purely mundane + (e.g., brushing teeth, making bed) and 10 is extremely poignant (e.g., a break up, college + acceptance), rate the likely poignancy of the following pieces of memory. Always answer with only a list of numbers. For example, if given the following memories Memories: John did nothing; John lin went to school; John lin saw a concert + respond with [1, 2, 6]. If just given one memory still respond in a list. Memories are separated by semi colans (;) + + Memories: {{#memories.unranked}}{{description}}; {{/memories.unranked}} + + debug: | + Ping {{ping}} + + relationship: | + What is {{agent.name}}'s relationship with the {{entity}}? diff --git a/smallville/src/test/java/io/github/nickm980/smallville/ChatServiceTest.java b/smallville/src/test/java/io/github/nickm980/smallville/ChatServiceTest.java new file mode 100644 index 0000000..478343e --- /dev/null +++ b/smallville/src/test/java/io/github/nickm980/smallville/ChatServiceTest.java @@ -0,0 +1,33 @@ +package io.github.nickm980.smallville; + +import java.util.List; + +import org.junit.jupiter.api.Test; + +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.AgentLocation; +import io.github.nickm980.smallville.entities.ObjectState; +import io.github.nickm980.smallville.entities.SimulatedLocation; +import io.github.nickm980.smallville.entities.SimulatedObject; +import io.github.nickm980.smallville.entities.memory.Characteristic; +import io.github.nickm980.smallville.llm.ChatGPT; +import io.github.nickm980.smallville.update.ChatService; + +public class ChatServiceTest { + + @Test + public void testLongTermPlans() { + SimulatedLocation location = new SimulatedLocation("Eddy's House"); + SimulatedObject obj = new SimulatedObject("Stove", new ObjectState("on", List.of()), location); + + World world = new World(); + world.save(location); + world.save(obj); + + ChatService service = new ChatService(world, new ChatGPT()); +// +// service +// .getPlans(new Agent("Eddy", List.of(new Characteristic("Eddy is a nice person")), +// "Cooking dinner in the kitchen", new AgentLocation(location))); + } +} diff --git a/smallville/src/test/java/io/github/nickm980/smallville/JacksonJsonTest.java b/smallville/src/test/java/io/github/nickm980/smallville/JacksonJsonTest.java index 882c20c..ff930ce 100644 --- a/smallville/src/test/java/io/github/nickm980/smallville/JacksonJsonTest.java +++ b/smallville/src/test/java/io/github/nickm980/smallville/JacksonJsonTest.java @@ -10,7 +10,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import io.github.nickm980.smallville.models.SimulatedLocation; +import io.github.nickm980.smallville.entities.SimulatedLocation; public class JacksonJsonTest { diff --git a/smallville/src/test/java/io/github/nickm980/smallville/LanguageProcessingTest.java b/smallville/src/test/java/io/github/nickm980/smallville/LanguageProcessingTest.java new file mode 100644 index 0000000..daad0cc --- /dev/null +++ b/smallville/src/test/java/io/github/nickm980/smallville/LanguageProcessingTest.java @@ -0,0 +1,17 @@ +package io.github.nickm980.smallville; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +import io.github.nickm980.smallville.nlp.LocalNLP; + +public class LanguageProcessingTest { + LocalNLP nlp = new LocalNLP(); + + @Test + public void testNamedEntities() { + assertEquals("I went to the mall", nlp.convertToPastTense("I will go to the mall")); + } + +} diff --git a/smallville/src/test/java/io/github/nickm980/smallville/ObjectsTest.java b/smallville/src/test/java/io/github/nickm980/smallville/ObjectsTest.java index 6dffd41..2b20e8a 100644 --- a/smallville/src/test/java/io/github/nickm980/smallville/ObjectsTest.java +++ b/smallville/src/test/java/io/github/nickm980/smallville/ObjectsTest.java @@ -6,11 +6,12 @@ import org.junit.jupiter.api.Test; -import io.github.nickm980.smallville.models.ObjectState; -import io.github.nickm980.smallville.models.SimulatedLocation; -import io.github.nickm980.smallville.models.SimulatedObject; +import io.github.nickm980.smallville.entities.ObjectState; +import io.github.nickm980.smallville.entities.SimulatedLocation; +import io.github.nickm980.smallville.entities.SimulatedObject; public class ObjectsTest { + @Test public void testObjectLoads() { World world = new World(); diff --git a/smallville/src/test/java/io/github/nickm980/smallville/PlansParsingTest.java b/smallville/src/test/java/io/github/nickm980/smallville/PlansParsingTest.java index f537f25..d989f82 100644 --- a/smallville/src/test/java/io/github/nickm980/smallville/PlansParsingTest.java +++ b/smallville/src/test/java/io/github/nickm980/smallville/PlansParsingTest.java @@ -6,9 +6,9 @@ import org.junit.Test; +import io.github.nickm980.smallville.entities.memory.MemoryStream; +import io.github.nickm980.smallville.entities.memory.Plan; import io.github.nickm980.smallville.llm.ChatGPT; -import io.github.nickm980.smallville.models.memory.MemoryStream; -import io.github.nickm980.smallville.models.memory.Plan; import io.github.nickm980.smallville.update.ChatService; public class PlansParsingTest { diff --git a/smallville/src/test/java/io/github/nickm980/smallville/PromptBuilderTest.java b/smallville/src/test/java/io/github/nickm980/smallville/PromptBuilderTest.java new file mode 100644 index 0000000..21c1ec0 --- /dev/null +++ b/smallville/src/test/java/io/github/nickm980/smallville/PromptBuilderTest.java @@ -0,0 +1,71 @@ +package io.github.nickm980.smallville; + +import static org.junit.Assert.assertEquals; + +import java.time.LocalDateTime; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import io.github.nickm980.smallville.config.SmallvilleConfig; +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.AgentLocation; +import io.github.nickm980.smallville.entities.ObjectState; +import io.github.nickm980.smallville.entities.SimulatedLocation; +import io.github.nickm980.smallville.entities.SimulatedObject; +import io.github.nickm980.smallville.entities.memory.Characteristic; +import io.github.nickm980.smallville.entities.memory.Plan; +import io.github.nickm980.smallville.prompts.Prompt; +import io.github.nickm980.smallville.prompts.PromptBuilder; + +public class PromptBuilderTest { + + @Test + public void testPromptTemplates() { + String prompt = SmallvilleConfig.getPrompts().getMisc().getDebug(); + World world = new World(); + SimulatedLocation location = new SimulatedLocation("location"); + world.save(location); + Agent ageng = new Agent("name", List.of(new Characteristic("desc")), prompt, new AgentLocation(location)); + world.save(ageng); + + Prompt builder = new PromptBuilder() + .withAgent(ageng) + .withLocations(world.getLocations()) + .setPrompt(prompt) + .build(); + + assertEquals("Ping pong", builder.build().get("content").trim()); + } + + @Test + public void testLongTermPlansPrompt() { + String prompt = SmallvilleConfig.getPrompts().getPlans().getShortTerm(); + World world = new World(); + SimulatedLocation location = new SimulatedLocation("location"); + SimulatedObject obj = new SimulatedObject("obj", new ObjectState("off", List.of()), location); + + world.save(obj); + world.save(location); + + Agent ageng = new Agent("name", List.of(new Characteristic("desc")), prompt, new AgentLocation(location)); + ageng.setGoal("Run for president"); + ageng.setCurrentActivity("Doing nothing"); + ageng.setCurrentActivity("making dinner"); + ageng.addPlans(List.of(new Plan("plan", LocalDateTime.now()))); + + world.save(ageng); + + Prompt builder = new PromptBuilder() + .withObservation("walked to the moon") + .withAgent(ageng) + .withWorld(world) + .withQuestion("hello there!") + .withLocations(world.getLocations()) + .withTense("tenses") + .setPrompt(prompt) + .build(); + + System.out.println(builder.build().get("content")); + } +} diff --git a/smallville/src/test/java/io/github/nickm980/smallville/TestUpdater.java b/smallville/src/test/java/io/github/nickm980/smallville/TestUpdater.java new file mode 100644 index 0000000..af64d40 --- /dev/null +++ b/smallville/src/test/java/io/github/nickm980/smallville/TestUpdater.java @@ -0,0 +1,11 @@ +package io.github.nickm980.smallville; + +import org.junit.jupiter.api.Test; + +public class TestUpdater { + + @Test + public void testUpdateChecker() { + Updater.checkLatestVersion(); + } +} diff --git a/smallville/src/test/java/io/github/nickm980/smallville/mocks/MockChatService.java b/smallville/src/test/java/io/github/nickm980/smallville/mocks/MockChatService.java new file mode 100644 index 0000000..e1fbc9a --- /dev/null +++ b/smallville/src/test/java/io/github/nickm980/smallville/mocks/MockChatService.java @@ -0,0 +1,73 @@ +package io.github.nickm980.smallville.mocks; + +import java.util.List; + +import io.github.nickm980.smallville.entities.Agent; +import io.github.nickm980.smallville.entities.Conversation; +import io.github.nickm980.smallville.entities.memory.Memory; +import io.github.nickm980.smallville.entities.memory.Plan; +import io.github.nickm980.smallville.prompts.dto.CurrentActivity; +import io.github.nickm980.smallville.prompts.dto.ObjectChangeResponse; +import io.github.nickm980.smallville.prompts.dto.Reaction; +import io.github.nickm980.smallville.update.IChatService; + +public class MockChatService implements IChatService { + + @Override + public String getExactLocation(Agent agent) { + return agent.getLocation().getName(); + } + + @Override + public List convertFuturePlansToMemories(List plans) { + return null; + } + + @Override + public ObjectChangeResponse[] getObjectsChangedBy(Agent agent) { + return null; + } + + @Override + public List parsePlans(String input) { + return null; + } + + @Override + public Conversation getConversationIfExists(Agent agent, Agent other) { + return null; + } + + @Override + public CurrentActivity getCurrentPlan(Agent agent) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getShortTermPlans(Agent agent) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getPlans(Agent agent) { + return null; + } + + @Override + public String ask(Agent agent, String question) { + return null; + } + + @Override + public Reaction getReaction(Agent agent, String observation) { + return null; + } + + @Override + public int[] getWeights(Agent agent) { + return null; + } + +}