Package rocks.imsofa.ai.puppychatter
Class AbstractPuppyChatter<T extends PromptParameters,S extends Response>
java.lang.Object
rocks.imsofa.ai.puppychatter.AbstractPuppyChatter<T,S>
- All Implemented Interfaces:
PuppyChatter<T,S>
- Direct Known Subclasses:
GeminiAqaPuppyChatter,OpenAICompatiblePuppyChatter
public abstract class AbstractPuppyChatter<T extends PromptParameters,S extends Response>
extends Object
implements PuppyChatter<T,S>
- Author:
- USER
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CacheServiceprotected Stringprotected Map<String, List<Conversation>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract S_bark(String sessionId, List<Conversation> messages, T parameters) protected abstract void_bark(String sessionId, List<Conversation> messages, T parameters, BarkCallback<S> callback) bark with default PromptParameters using a block wayvoidbark(String sessionId, String prompt, BarkCallback<S> barkCallback) bark with default PromptParameters and use a streaming-if-possible waybark with the given PromptParametersvoidGenerates a response by invoking thebarkmethod with a default verification function.voidcloseSession(String sessionId) close the session with the given sessionIdprotected ConversationcreateConversationFromPrompt(String prompt, T parameters) create a conversation from a prompt by default, this function create an instance ofConversationprotected abstract Tprotected abstract ScreateResponseFromConversation(List<Conversation> lastPrompt, Conversation lastResponse) initialize a chat session with a default model and return a session id to be used in further chatsprotected booleanisCacheable(String sessionId, List<Conversation> messages, T parameters) check if the current conversation is cacheable by default, this function returns true child classes can override this function to customize the behavior
-
Field Details
-
sessionHistory
-
cacheService
-
replyRole
-
-
Constructor Details
-
AbstractPuppyChatter
-
AbstractPuppyChatter
public AbstractPuppyChatter()
-
-
Method Details
-
createSession
Description copied from interface:PuppyChatterinitialize a chat session with a default model and return a session id to be used in further chats- Specified by:
createSessionin interfacePuppyChatter<T extends PromptParameters,S extends Response> - Returns:
-
bark
public void bark(String sessionId, String prompt, T parameters, BarkCallback<S> barkCallback) throws BarkException Generates a response by invoking thebarkmethod with a default verification function. If it is possible, the call to the underlying llm will be in a streaming way but not guaranteed. The default verification function returnsVerificationResult.GOODif the response is not an error, otherwise it returnsVerificationResult.GIVE_UP.- Specified by:
barkin interfacePuppyChatter<T extends PromptParameters,S extends Response> - Parameters:
sessionId- the session identifierprompt- the input prompt to processparameters- additional parameters for the bark operationbarkCallback-- Throws:
BarkException- if an error occurs during the bark operation
-
bark
Description copied from interface:PuppyChatterbark with the given PromptParameters- Specified by:
barkin interfacePuppyChatter<T extends PromptParameters,S extends Response> - Parameters:
sessionId-prompt-parameters-- Returns:
- Throws:
BarkException
-
bark
public void bark(String sessionId, String prompt, BarkCallback<S> barkCallback) throws BarkException Description copied from interface:PuppyChatterbark with default PromptParameters and use a streaming-if-possible way- Specified by:
barkin interfacePuppyChatter<T extends PromptParameters,S extends Response> - Parameters:
sessionId-prompt-barkCallback-- Throws:
BarkException
-
bark
Description copied from interface:PuppyChatterbark with default PromptParameters using a block way- Specified by:
barkin interfacePuppyChatter<T extends PromptParameters,S extends Response> - Parameters:
sessionId-prompt-- Returns:
- Throws:
BarkException
-
closeSession
Description copied from interface:PuppyChatterclose the session with the given sessionId- Specified by:
closeSessionin interfacePuppyChatter<T extends PromptParameters,S extends Response> - Parameters:
sessionId-
-
_bark
protected abstract S _bark(String sessionId, List<Conversation> messages, T parameters) throws Exception - Throws:
Exception
-
_bark
protected abstract void _bark(String sessionId, List<Conversation> messages, T parameters, BarkCallback<S> callback) throws Exception - Throws:
Exception
-
createDefaultPromptParameter
-
createResponseFromConversation
protected abstract S createResponseFromConversation(List<Conversation> lastPrompt, Conversation lastResponse) -
createConversationFromPrompt
create a conversation from a prompt by default, this function create an instance ofConversation- Parameters:
prompt-parameters-- Returns:
-
isCacheable
check if the current conversation is cacheable by default, this function returns true child classes can override this function to customize the behavior- Parameters:
sessionId-messages-parameters-- Returns:
-