-
Notifications
You must be signed in to change notification settings - Fork 46
BIGTOP-4191: Add AI assistant module, integrating with a large language model for basic conversational functionality. #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1f4375d
add bigtop-manager-ai-assistant model and implement openai assistant.
NingNing0111 d0838da
delete custom OpenAI model name enum class.
NingNing0111 e3eae56
add OpenAI Model
NingNing0111 099a491
some code update
NingNing0111 69e9a21
Merge branch 'main' of https://github.com/apache/bigtop-manager
NingNing0111 31b205f
Add AI assistant module, integrating with a large language model for …
NingNing0111 7d295db
add GeneralAssistantFactory to implement AIAssistantFactory, and some…
NingNing0111 8182c12
Changed some code formatting
NingNing0111 eb750e0
Changed some code formatting
NingNing0111 9c2194d
Changed some code formatting
NingNing0111 57d9e3c
Changed AIAssistantAbstractFactory to AbstractAIAssistantFactory, add…
NingNing0111 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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> | ||
|
|
||
kevinw66 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <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> | ||
kevinw66 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| </dependencies> | ||
|
|
||
| </project> | ||
84 changes: 84 additions & 0 deletions
84
...ai-assistant/src/main/java/org/apache/bigtop/manager/ai/assistant/AIAssistantFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
|
|
||
|
|
||
|
|
||
kevinw66 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @Override | ||
| public ToolBox createToolBox(PlatformType platformType) { | ||
| return null; | ||
| } | ||
|
|
||
| } | ||
64 changes: 64 additions & 0 deletions
64
...tant/src/main/java/org/apache/bigtop/manager/ai/assistant/provider/AIAssistantConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * 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 org.apache.bigtop.manager.ai.core.provider.AIAssistantConfigProvider; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| public class AIAssistantConfig implements AIAssistantConfigProvider { | ||
| private final Map<String, String> configMap; | ||
|
|
||
| private AIAssistantConfig(Map<String, String> configMap){ | ||
| this.configMap = configMap; | ||
| } | ||
|
|
||
| public static Builder builder(){ | ||
| return new Builder(); | ||
| } | ||
|
|
||
| public static Builder withDefault(String baseUrl, String apiKey){ | ||
| Builder builder = new Builder(); | ||
| return builder.set("baseUrl", baseUrl).set("apiKey", apiKey); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, String> configs() { | ||
|
|
||
| return configMap; | ||
| } | ||
|
|
||
| public static class Builder{ | ||
| private final Map<String,String> configs; | ||
| public Builder(){ | ||
| configs = new HashMap<>(); | ||
| configs.put("memoryLen", "30"); | ||
| } | ||
|
|
||
| public Builder set(String key, String value){ | ||
| configs.put(key,value); | ||
| return this; | ||
| } | ||
|
|
||
| public AIAssistantConfig build(){ | ||
| return new AIAssistantConfig(configs); | ||
| } | ||
| } | ||
|
|
||
| } |
52 changes: 52 additions & 0 deletions
52
...rc/main/java/org/apache/bigtop/manager/ai/assistant/provider/LocSystemPromptProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); | ||
kevinw66 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| String systemStr = Files.readString(file.toPath(), StandardCharsets.UTF_8); | ||
| return SystemMessage.from(systemStr); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } | ||
1 change: 1 addition & 0 deletions
1
bigtop-manager-ai/bigtop-manager-ai-assistant/src/main/resources/big-data-professor.st
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| You are a qualified big data expert who knows the world's leading open source big data component engineering projects. Now please focus on the content in the direction of big data. I will ask you some questions and hope to get your answers. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.