I'll never understand beans

This commit is contained in:
Mahesh Kommareddi 2024-07-16 23:45:35 -04:00
parent 9983a530a5
commit 44cced45e3
8 changed files with 55 additions and 47 deletions

View File

@ -10,10 +10,13 @@ import com.ioa.tool.ToolRegistry;
import com.ioa.model.BedrockLanguageModel;
import com.ioa.service.WebSocketService;
import com.ioa.tool.Tool;
import com.ioa.util.TreeOfThought;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import java.lang.reflect.Method;
import java.util.Arrays;
@ -46,8 +49,13 @@ public class IoASystem {
}
@Bean
public TeamFormation teamFormation(AgentRegistry agentRegistry, BedrockLanguageModel model) {
return new TeamFormation(agentRegistry, model);
public TreeOfThought treeOfThought(BedrockLanguageModel model, WebSocketService webSocketService) {
return new TreeOfThought(model, webSocketService);
}
@Bean
public TeamFormation teamFormation(AgentRegistry agentRegistry, TreeOfThought treeOfThought, WebSocketService webSocketService) {
return new TeamFormation(agentRegistry, treeOfThought, webSocketService);
}
@Bean
@ -56,17 +64,17 @@ public class IoASystem {
}
@Bean
public WebSocketService webSocketService() {
return new WebSocketService();
public WebSocketService webSocketService(SimpMessagingTemplate messagingTemplate) {
return new WebSocketService(messagingTemplate);
}
public static void main(String[] args) {
var context = SpringApplication.run(IoASystem.class, args);
ConfigurableApplicationContext context = SpringApplication.run(IoASystem.class, args);
AgentRegistry agentRegistry = context.getBean(AgentRegistry.class);
TeamFormation teamFormation = context.getBean(TeamFormation.class);
TaskManager taskManager = context.getBean(TaskManager.class);
// Register all agents
agentRegistry.registerAgent("agent1", new AgentInfo("agent1", "General Assistant",
Arrays.asList("general", "search"),
@ -92,32 +100,32 @@ public class IoASystem {
// Create all tasks
List<Task> tasks = Arrays.asList(
// new Task("task1", "Plan a weekend trip to Paris",
// Arrays.asList("travel", "booking"),
// Arrays.asList("bookTravel", "findRestaurants", "getWeather")),
// new Task("task2", "Organize a corporate team-building event in New York",
// Arrays.asList("event planning", "team management"),
// Arrays.asList("findRestaurants", "bookTravel", "scheduleAppointment")),
// new Task("task3", "Develop a personalized fitness and nutrition plan",
// Arrays.asList("health", "nutrition"),
// Arrays.asList("getWeather", "findFitnessClasses", "getRecipe")),
// new Task("task4", "Research and summarize recent advancements in renewable energy",
// Arrays.asList("research", "writing"),
// Arrays.asList("webSearch", "getNewsUpdates", "translate")),
// new Task("task5", "Plan and execute a social media marketing campaign for a new product launch",
// Arrays.asList("marketing", "social media"),
// Arrays.asList("webSearch", "getNewsUpdates", "scheduleAppointment")),
// new Task("task6", "Assist in planning a multi-city European vacation for a family of four",
// Arrays.asList("travel", "family planning"),
// Arrays.asList("bookTravel", "calculateDistance", "getWeather", "findRestaurants")),
new Task("task1", "Plan a weekend trip to Paris",
Arrays.asList("travel", "booking"),
Arrays.asList("bookTravel", "findRestaurants", "getWeather")),
new Task("task2", "Organize a corporate team-building event in New York",
Arrays.asList("event planning", "team management"),
Arrays.asList("findRestaurants", "bookTravel", "scheduleAppointment")),
new Task("task3", "Develop a personalized fitness and nutrition plan",
Arrays.asList("health", "nutrition"),
Arrays.asList("getWeather", "findFitnessClasses", "getRecipe")),
new Task("task4", "Research and summarize recent advancements in renewable energy",
Arrays.asList("research", "writing"),
Arrays.asList("webSearch", "getNewsUpdates", "translate")),
new Task("task5", "Plan and execute a social media marketing campaign for a new product launch",
Arrays.asList("marketing", "social media"),
Arrays.asList("webSearch", "getNewsUpdates", "scheduleAppointment")),
new Task("task6", "Assist in planning a multi-city European vacation for a family of four",
Arrays.asList("travel", "family planning"),
Arrays.asList("bookTravel", "calculateDistance", "getWeather", "findRestaurants")),
// new Task("task7", "Organize an international tech conference with virtual and in-person components",
// Arrays.asList("event planning", "tech expertise", "marketing", "travel coordination", "content creation"),
// Arrays.asList("scheduleAppointment", "webSearch", "bookTravel", "getWeather", "findRestaurants", "getNewsUpdates")),
new Task("task7", "Organize an international tech conference with virtual and in-person components",
Arrays.asList("event planning", "tech expertise", "marketing", "travel coordination", "content creation"),
Arrays.asList("scheduleAppointment", "webSearch", "bookTravel", "getWeather", "findRestaurants", "getNewsUpdates")),
// new Task("task8", "Develop and launch a multi-lingual mobile app for sustainable tourism",
// Arrays.asList("software development", "travel", "language expertise", "environmental science", "user experience design"),
// Arrays.asList("webSearch", "translate", "getWeather", "findRestaurants", "getNewsUpdates", "compareProductPrices")),
new Task("task8", "Develop and launch a multi-lingual mobile app for sustainable tourism",
Arrays.asList("software development", "travel", "language expertise", "environmental science", "user experience design"),
Arrays.asList("webSearch", "translate", "getWeather", "findRestaurants", "getNewsUpdates", "compareProductPrices")),
new Task("task9", "Create a comprehensive health and wellness program for a large corporation, including mental health support",
Arrays.asList("health", "nutrition", "psychology", "corporate wellness", "data analysis"),

View File

@ -1,14 +1,16 @@
package com.ioa.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;
@Service
public class WebSocketService {
@Autowired
private SimpMessagingTemplate messagingTemplate;
private final SimpMessagingTemplate messagingTemplate;
public WebSocketService(SimpMessagingTemplate messagingTemplate) {
this.messagingTemplate = messagingTemplate;
}
public void sendUpdate(String topic, Object payload) {
messagingTemplate.convertAndSend("/topic/" + topic, payload);

View File

@ -5,8 +5,9 @@ import com.ioa.agent.AgentRegistry;
import com.ioa.model.BedrockLanguageModel;
import com.ioa.task.Task;
import com.ioa.util.TreeOfThought;
import com.ioa.service.WebSocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
@ -14,15 +15,14 @@ import java.util.stream.Collectors;
@Component
public class TeamFormation {
private AgentRegistry agentRegistry;
private TreeOfThought treeOfThought;
@Autowired
private WebSocketService webSocketService;
private final AgentRegistry agentRegistry;
private final TreeOfThought treeOfThought;
private final WebSocketService webSocketService;
public TeamFormation(AgentRegistry agentRegistry, BedrockLanguageModel model) {
public TeamFormation(AgentRegistry agentRegistry, TreeOfThought treeOfThought, WebSocketService webSocketService) {
this.agentRegistry = agentRegistry;
this.treeOfThought = new TreeOfThought(model);
this.treeOfThought = treeOfThought;
this.webSocketService = webSocketService;
}
public List<AgentInfo> formTeam(Task task) {

View File

@ -2,7 +2,6 @@ package com.ioa.util;
import com.ioa.model.BedrockLanguageModel;
import com.ioa.service.WebSocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
@ -13,12 +12,11 @@ import java.util.Map;
@Component
public class TreeOfThought {
private final BedrockLanguageModel model;
@Autowired
private WebSocketService webSocketService;
private final WebSocketService webSocketService;
public TreeOfThought(BedrockLanguageModel model) {
public TreeOfThought(BedrockLanguageModel model, WebSocketService webSocketService) {
this.model = model;
this.webSocketService = webSocketService;
}
public String reason(String task, int depth, int branches) {