kevinw66 commented on code in PR #49: URL: https://github.com/apache/bigtop-manager/pull/49#discussion_r1722774865
########## bigtop-manager-ai/bigtop-manager-ai-assistant/pom.xml: ########## @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ https://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.bigtop</groupId> + <artifactId>bigtop-manager-ai</artifactId> + <version>0.0.1-SNAPSHOT</version> + </parent> + + <groupId>org.apacje.bigtop</groupId> Review Comment: groupId is wrong, but we can safely remove this property here ########## bigtop-manager-ai/bigtop-manager-ai-assistant/pom.xml: ########## @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ https://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.bigtop</groupId> + <artifactId>bigtop-manager-ai</artifactId> + <version>0.0.1-SNAPSHOT</version> + </parent> + + <groupId>org.apacje.bigtop</groupId> + <artifactId>bigtop-manager-ai-assistant</artifactId> + Review Comment: please add <name> <description> tags, you can refers to other pom.xml files ########## bigtop-manager-ai/bigtop-manager-ai-assistant/pom.xml: ########## @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ https://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.bigtop</groupId> + <artifactId>bigtop-manager-ai</artifactId> + <version>0.0.1-SNAPSHOT</version> + </parent> + + <groupId>org.apacje.bigtop</groupId> + <artifactId>bigtop-manager-ai-assistant</artifactId> + + + <dependencies> + <dependency> + <groupId>org.apache.bigtop</groupId> + <artifactId>bigtop-manager-ai-openai</artifactId> + </dependency> + <dependency> + <groupId>org.apache.bigtop</groupId> + <artifactId>bigtop-manager-ai-core</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> Review Comment: Junit can be removed here as it's already added as global dependency ########## bigtop-manager-ai/bigtop-manager-ai-assistant/src/test/java/org/apache/bigtop/manager/ai/assistant/AIAssistantFactoryTests.java: ########## @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bigtop.manager.ai.assistant; + +import dev.langchain4j.data.message.ChatMessage; +import dev.langchain4j.memory.ChatMemory; +import dev.langchain4j.model.openai.OpenAiChatModelName; +import org.apache.bigtop.manager.ai.assistant.provider.LocSystemPromptProvider; +import org.apache.bigtop.manager.ai.core.enums.PlatformType; +import org.apache.bigtop.manager.ai.core.factory.AIAssistant; +import org.apache.bigtop.manager.ai.assistant.provider.AIAssistantConfig; +import org.apache.bigtop.manager.ai.core.provider.AIAssistantConfigProvider; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import reactor.core.publisher.Flux; + +import java.util.List; + + +public class AIAssistantFactoryTests { + + private AIAssistantFactory aiAssistantFactory = new AIAssistantFactory(); + private PlatformType platformType = PlatformType.OPENAI; + + private AIAssistantConfigProvider configProvider = AIAssistantConfig.builder() Review Comment: We should use mock call on ut, please do not interact with real online api ########## bigtop-manager-ai/bigtop-manager-ai-core/src/main/java/org/apache/bigtop/manager/ai/core/factory/AIAssistantAbstractFactory.java: ########## @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bigtop.manager.ai.core.factory; + +import org.apache.bigtop.manager.ai.core.enums.PlatformType; +import org.apache.bigtop.manager.ai.core.exception.PlatformNotFoundException; +import org.apache.bigtop.manager.ai.core.provider.AIAssistantConfigProvider; + +import java.util.Objects; +import java.util.UUID; + + +public interface AIAssistantAbstractFactory { Review Comment: How about we use `AIAssistantFactory` for interface, and create an abstract class `AbsctractAIAssistantFactory`? ########## bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/tez/TezClientScript.java: ########## @@ -40,4 +40,9 @@ public ShellResult install(Params params) { public ShellResult configure(Params params) { return TezSetup.config(params); } + + @Test Review Comment: Why add test here? ########## bigtop-manager-ai/bigtop-manager-ai-assistant/src/main/java/org/apache/bigtop/manager/ai/assistant/AIAssistantFactory.java: ########## @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bigtop.manager.ai.assistant; + +import dev.langchain4j.data.message.SystemMessage; +import dev.langchain4j.store.memory.chat.ChatMemoryStore; +import dev.langchain4j.store.memory.chat.InMemoryChatMemoryStore; +import org.apache.bigtop.manager.ai.assistant.provider.LocSystemPromptProvider; +import org.apache.bigtop.manager.ai.core.enums.PlatformType; +import org.apache.bigtop.manager.ai.core.factory.AIAssistant; +import org.apache.bigtop.manager.ai.core.factory.AIAssistantAbstractFactory; +import org.apache.bigtop.manager.ai.core.factory.ToolBox; +import org.apache.bigtop.manager.ai.core.provider.AIAssistantConfigProvider; +import org.apache.bigtop.manager.ai.core.provider.SystemPromptProvider; +import org.apache.bigtop.manager.ai.openai.OpenAIAssistant; + +import java.util.Objects; + +public class AIAssistantFactory implements AIAssistantAbstractFactory { + + private SystemPromptProvider systemPromptProvider = new LocSystemPromptProvider(); + private ChatMemoryStore chatMemoryStore = new InMemoryChatMemoryStore(); + + public AIAssistantFactory(){ + + } + + public AIAssistantFactory(SystemPromptProvider systemPromptProvider){ + this.systemPromptProvider = systemPromptProvider; + } + + public AIAssistantFactory(SystemPromptProvider systemPromptProvider, ChatMemoryStore chatMemoryStore){ + this.systemPromptProvider = systemPromptProvider; + this.chatMemoryStore = chatMemoryStore; + + } + + + @Override + public AIAssistant createWithPrompt(PlatformType platformType, AIAssistantConfigProvider assistantConfig, Object id, Object promptId) { + AIAssistant aiAssistant = create(platformType, assistantConfig, id); + SystemMessage systemPrompt = systemPromptProvider.getSystemPrompt(promptId); + aiAssistant.setSystemPrompt(systemPrompt); + return aiAssistant; + } + + @Override + public AIAssistant create(PlatformType platformType, AIAssistantConfigProvider assistantConfig, Object id) { + if (Objects.requireNonNull(platformType) == PlatformType.OPENAI) { + AIAssistant aiAssistant = OpenAIAssistant.builder() + .id(id) + .memoryStore(chatMemoryStore) + .withConfigProvider(assistantConfig) + .build(); + aiAssistant.setSystemPrompt(systemPromptProvider.getSystemPrompt()); + return aiAssistant; + } + return null; + } + + + Review Comment: One empty line is enough ########## bigtop-manager-ai/bigtop-manager-ai-assistant/src/main/java/org/apache/bigtop/manager/ai/assistant/provider/LocSystemPromptProvider.java: ########## @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bigtop.manager.ai.assistant.provider; + +import dev.langchain4j.data.message.SystemMessage; +import org.apache.bigtop.manager.ai.core.provider.SystemPromptProvider; +import org.springframework.util.ResourceUtils; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.Objects; + +public class LocSystemPromptProvider implements SystemPromptProvider { + + public final static String DEFAULT = "default"; + @Override + public SystemMessage getSystemPrompt(Object id) { + if(Objects.equals(id.toString(), DEFAULT)){ + return getSystemPrompt(); + } + return null; + } + + @Override + public SystemMessage getSystemPrompt() { + try { + File file = ResourceUtils.getFile("src/main/resources/big-data-professor.st"); Review Comment: we should add `paths-ignore` for st files on `.licenserc.yaml`, or we can extract the content as a constant variable? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
