Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions bigtop-manager-ai/bigtop-manager-ai-assistant/pom.xml
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>


<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>

</dependencies>

</project>
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;
}



@Override
public ToolBox createToolBox(PlatformType platformType) {
return null;
}

}
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);
}
}

}
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");
String systemStr = Files.readString(file.toPath(), StandardCharsets.UTF_8);
return SystemMessage.from(systemStr);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
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.
Loading