Class PicoLLM

java.lang.Object
ai.picovoice.picollm.PicoLLM

public class PicoLLM extends Object
Android binding for picoLLM.
  • Method Details

    • setSdk

      public static void setSdk(String sdk)
    • getVersion

      public static String getVersion() throws PicoLLMException
      Retrieves the version of the picoLLM library.
      Returns:
      Version of the picoLLM library.
      Throws:
      PicoLLMException - if getting the version fails.
    • getMaxTopChoices

      public static int getMaxTopChoices()
      Retrieves the maximum number of top choices allowed during generation.
      Returns:
      Maximum number of top choices allowed during generation.
    • getAvailableDevices

      public static String[] getAvailableDevices() throws PicoLLMException
      Lists all available devices that picoLLM can use for inference. Each entry in the list can be the `device` when initializing picoLLM.
      Returns:
      Array of all available devices that picoLLM can be used for inference.
      Throws:
      PicoLLMException - if getting available devices fails.
    • delete

      public void delete()
      Deletes the resources acquired by picoLLM.
    • generate

      public PicoLLMCompletion generate(String prompt, PicoLLMGenerateParams generateParams) throws PicoLLMException
      Generates completion text and relevant metadata given a text prompt and a set of generation parameters.
      Parameters:
      prompt - Text prompt.
      generateParams - Generation parameters.
      Returns:
      Completion result.
      Throws:
      PicoLLMException - if generation fails.
    • interrupt

      public void interrupt() throws PicoLLMException
      Interrupts `.generate()` if generation is in progress. Otherwise, it has no effect.
      Throws:
      PicoLLMException - if interrupt fails.
    • tokenize

      public int[] tokenize(String text, boolean bos, boolean eos) throws PicoLLMException
      Tokenizes a given text using the model's tokenizer. This is a low-level function meant for benchmarking and advanced usage. `.generate()` should be used when possible.
      Parameters:
      text - Text.
      bos - If set to `true`, the tokenizer prepends the beginning of the sentence token to the result.
      eos - If set to `true`, the tokenizer appends the end of the sentence token to the result.
      Returns:
      Tokens representing the input text.
      Throws:
      PicoLLMException - if tokenization fails.
    • forward

      public float[] forward(int token) throws PicoLLMException
      Performs a single forward pass given a token and returns the logits. This is a low-level function for benchmarking and advanced usage. `.generate()` should be used when possible.
      Parameters:
      token - Input token.
      Returns:
      Logits.
      Throws:
      PicoLLMException - if the forward pass fails.
    • reset

      public void reset() throws PicoLLMException
      Resets the internal state of LLM. It should be called in conjunction with `.forward()` when processing a new sequence of tokens. This is a low-level function for benchmarking and advanced usage. `.generate()` should be used when possible.
      Throws:
      PicoLLMException - if resetting fails.
    • getModel

      public String getModel()
      Getter for model's name.
      Returns:
      Model's name.
    • getContextLength

      public int getContextLength()
      Getter for model's context length.
      Returns:
      Model's context length.
    • getDialogBuilder

      public PicoLLM.DialogBuilder getDialogBuilder()
      Retrieves a new instance of DialogBuilder for constructing dialog objects from the currently loaded picoLLM model.
      Returns:
      A new instance of DialogBuilder.