mirror of
https://gitee.com/agents-flex/agents-flex.git
synced 2024-12-01 19:37:50 +08:00
feat: add SystemMessage to TextPrompt and FunctionPrompt
This commit is contained in:
parent
76ddf203f8
commit
c7b8dbb15e
@ -24,5 +24,7 @@ public class SystemMessage extends AbstractTextMessage {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
|
||||
public static SystemMessage of(String content) {
|
||||
return new SystemMessage(content);
|
||||
}
|
||||
}
|
||||
|
@ -22,12 +22,15 @@ import com.agentsflex.core.memory.ChatMemory;
|
||||
import com.agentsflex.core.memory.DefaultChatMemory;
|
||||
import com.agentsflex.core.message.HumanMessage;
|
||||
import com.agentsflex.core.message.Message;
|
||||
import com.agentsflex.core.message.SystemMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class FunctionPrompt extends Prompt<FunctionMessageResponse> {
|
||||
|
||||
private SystemMessage systemMessage;
|
||||
private final ChatMemory memory = new DefaultChatMemory();
|
||||
private final List<Function> functions = new ArrayList<>();
|
||||
|
||||
@ -61,9 +64,25 @@ public class FunctionPrompt extends Prompt<FunctionMessageResponse> {
|
||||
functions.addAll(Functions.from(funcObject, methodNames));
|
||||
}
|
||||
|
||||
public SystemMessage getSystemMessage() {
|
||||
return systemMessage;
|
||||
}
|
||||
|
||||
public void setSystemMessage(SystemMessage systemMessage) {
|
||||
this.systemMessage = systemMessage;
|
||||
}
|
||||
|
||||
public ChatMemory getMemory() {
|
||||
return memory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Message> toMessages() {
|
||||
return memory.getMessages();
|
||||
List<Message> messages = memory.getMessages();
|
||||
if (systemMessage != null){
|
||||
messages.add(0, systemMessage);
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
public List<Function> getFunctions() {
|
||||
|
@ -18,12 +18,15 @@ package com.agentsflex.core.prompt;
|
||||
import com.agentsflex.core.llm.response.AiMessageResponse;
|
||||
import com.agentsflex.core.message.HumanMessage;
|
||||
import com.agentsflex.core.message.Message;
|
||||
import com.agentsflex.core.message.SystemMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class TextPrompt extends Prompt<AiMessageResponse> {
|
||||
|
||||
private SystemMessage systemMessage;
|
||||
protected String content;
|
||||
|
||||
public TextPrompt() {
|
||||
@ -41,8 +44,22 @@ public class TextPrompt extends Prompt<AiMessageResponse> {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public SystemMessage getSystemMessage() {
|
||||
return systemMessage;
|
||||
}
|
||||
|
||||
public void setSystemMessage(SystemMessage systemMessage) {
|
||||
this.systemMessage = systemMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Message> toMessages() {
|
||||
if (systemMessage != null) {
|
||||
ArrayList<Message> messages = new ArrayList<>();
|
||||
messages.add(systemMessage);
|
||||
messages.add(new HumanMessage(content));
|
||||
return messages;
|
||||
}
|
||||
return Collections.singletonList(new HumanMessage(content));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user