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 Details

  • Constructor Details

    • AbstractPuppyChatter

      public AbstractPuppyChatter(CacheService cacheService, String replyRole)
    • AbstractPuppyChatter

      public AbstractPuppyChatter()
  • Method Details

    • createSession

      public String createSession()
      Description copied from interface: PuppyChatter
      initialize a chat session with a default model and return a session id to be used in further chats
      Specified by:
      createSession in interface PuppyChatter<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 the bark method 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 returns VerificationResult.GOOD if the response is not an error, otherwise it returns VerificationResult.GIVE_UP.
      Specified by:
      bark in interface PuppyChatter<T extends PromptParameters,S extends Response>
      Parameters:
      sessionId - the session identifier
      prompt - the input prompt to process
      parameters - additional parameters for the bark operation
      barkCallback -
      Throws:
      BarkException - if an error occurs during the bark operation
    • bark

      public S bark(String sessionId, String prompt, T parameters) throws BarkException
      Description copied from interface: PuppyChatter
      bark with the given PromptParameters
      Specified by:
      bark in interface PuppyChatter<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: PuppyChatter
      bark with default PromptParameters and use a streaming-if-possible way
      Specified by:
      bark in interface PuppyChatter<T extends PromptParameters,S extends Response>
      Parameters:
      sessionId -
      prompt -
      barkCallback -
      Throws:
      BarkException
    • bark

      public S bark(String sessionId, String prompt) throws BarkException
      Description copied from interface: PuppyChatter
      bark with default PromptParameters using a block way
      Specified by:
      bark in interface PuppyChatter<T extends PromptParameters,S extends Response>
      Parameters:
      sessionId -
      prompt -
      Returns:
      Throws:
      BarkException
    • closeSession

      public void closeSession(String sessionId)
      Description copied from interface: PuppyChatter
      close the session with the given sessionId
      Specified by:
      closeSession in interface PuppyChatter<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

      protected abstract T createDefaultPromptParameter()
    • createResponseFromConversation

      protected abstract S createResponseFromConversation(List<Conversation> lastPrompt, Conversation lastResponse)
    • createConversationFromPrompt

      protected Conversation createConversationFromPrompt(String prompt, T parameters)
      create a conversation from a prompt by default, this function create an instance of Conversation
      Parameters:
      prompt -
      parameters -
      Returns:
    • isCacheable

      protected boolean isCacheable(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
      Parameters:
      sessionId -
      messages -
      parameters -
      Returns: