picoLLM Inference Engine
Android API
API Reference for the picoLLM Android SDK (Maven Central)
PicoLLM
Class for the picoLLM Inference Engine.
PicoLLM
must be initialized using the Builder()
Class. Resources should be cleaned when you are done using the delete()
function.
PicoLLM.getVersion()
Retrieves the version of the picoLLM library.
Returns
String
: Version of the picoLLM library.
Throws
PicoLLMException
: If getting the version fails.
PicoLLM.getMaxTopChoices()
Retrieves the maximum number of top choices allowed during generation.
Returns
int
: Maximum number of top choices allowed during generation.
PicoLLM.getAvailableDevices()
Lists all available devices that picoLLM can use for inference.
Returns
String[]
: Array of all available devices that picoLLM can be used for inference.
Throws
PicoLLMException
: If getting available devices fails.
PicoLLM.delete()
Deletes the resources acquired by picoLLM.
PicoLLM.generate()
Generates completion text and relevant metadata given a text prompt and a set of generation parameters.
Parameters
prompt
String : Text prompt.generateParams
PicoLLMGenerateParams: Generation parameters.
Returns
PicoLLMCompletion
: Completion result.
Throws
PicoLLMException
: If generation fails.
PicoLLM.interrupt()
Interrupts .generate()
if generation is in progress. Otherwise, it has no effect.
Throws
PicoLLMException
: If interrupt fails.
PicoLLM.tokenize()
Tokenizes a given text using the model's tokenizer.
Parameters
text
String : Text.bos
boolean : If set totrue
, the tokenizer prepends the beginning of the sentence token to the result.eos
boolean : If set totrue
, the tokenizer appends the end of the sentence token to the result.
Returns
int[]
: Tokens representing the input text.
Throws
PicoLLMException
: If tokenization fails.
PicoLLM.forward()
Performs a single forward pass given a token and returns the logits.
Parameters
token
int : Input token.
Returns
float[]
: Logits.
Throws
PicoLLMException
: If the forward pass fails.
PicoLLM.reset()
Resets the internal state of LLM.
Throws
PicoLLMException
: If resetting fails.
PicoLLM.getModel()
Getter for model's name.
Returns
String
: Model's name.
PicoLLM.getContextLength()
Getter for model's context length.
Returns
int
: Model's context length.
PicoLLM.getDialogBuilder()
Retrieves a new instance of DialogBuilder for constructing dialog objects from the currently loaded picoLLM model.
Returns
DialogBuilder
: A new instance of DialogBuilder.
PicoLLM.Builder
Builder for creating an instance of PicoLLM
with a mixture of default arguments.
PicoLLM.Builder.setAccessKey()
Sets the AccessKey.
Parameters
accessKey
String : AccessKey obtained from Picovoice Console.
Returns
Builder
: Builder instance.
PicoLLM.Builder.setModelPath()
Sets the model path.
Parameters
modelPath
String : Absolute path to the file containing LLM parameters.
Returns
Builder
: Builder instance.
PicoLLM.Builder.setDevice()
Sets the device to use for inference.
Parameters
device
String : String representation of the device (e.g., CPU or GPU) to use for inference.
Returns
Builder
: Builder instance.
PicoLLM.Builder.build()
Creates an instance of PicoLLM
Inference Engine.
Returns
PicoLLM
: An instance of picoLLM Inference Engine.
Throws
PicoLLMException
: If an error occurs while creating an instance of picoLLM Inference Engine.
PicoLLM.DialogBuilder
Builder for creating an instance of PicoLLMDialog
with a mixture of default arguments.
PicoLLM.DialogBuilder.setMode()
Sets the mode for the dialog builder.
Parameters
mode
String : The mode to set.
Returns
DialogBuilder
: DialogBuilder instance.\
PicoLLM.DialogBuilder.setHistory()
Sets the history length for the dialog builder.
Parameters
history
int : The history length to set.
Returns
DialogBuilder
: DialogBuilder instance.
PicoLLM.DialogBuilder.setSystem()
Sets the system instruction for the dialog builder.
Parameters
system
String : The system instruction to set.
Returns
DialogBuilder
: DialogBuilder instance.
PicoLLM.DialogBuilder.build()
Constructs a PicoLLMDialog instance based on the configured settings.
Returns
PicoLLMDialog
: A new instance of PicoLLMDialog.
Throws
PicoLLMException
: If there's an issue constructing the dialog.
PicoLLMException
Exception thrown if an error occurs within picoLLM
Inference Engine.
Exceptions:
PicoLLMGenerateParams
Class for configuring generation parameters when calling PicoLLM.generate()
.
PicoLLMGenerateParams.getCompletionTokenLimit()
Getter for the maximum number of tokens allowed in the completion.
Returns
Integer
: The completion token limit.
PicoLLMGenerateParams.setCompletionTokenLimit()
Setter for the maximum number of tokens allowed in the completion.
Parameters
completionTokenLimit
Integer : The completion token limit to set.
PicoLLMGenerateParams.getStopPhrases()
Getter for phrases that trigger early completion termination.
Returns
String[]
: Phrases that trigger early completion termination.
PicoLLMGenerateParams.setStopPhrases()
Setter for phrases that trigger early completion termination.
Parameters
stopPhrases
String[] : Phrases that trigger early completion termination.
PicoLLMGenerateParams.getSeed()
Getter for the seed value for the internal random number generator.
Returns
Integer
: The seed value for the internal random number generator.
PicoLLMGenerateParams.setSeed()
Setter for the seed value for the internal random number generator.
Parameters
seed
Integer : The seed value for the internal random number generator.
PicoLLMGenerateParams.getPresencePenalty()
Getter for the presence penalty.
Returns
float
: The presence penalty.
PicoLLMGenerateParams.setPresencePenalty()
Setter for the presence penalty.
Parameters
presencePenalty
float : The presence penalty.
PicoLLMGenerateParams.getFrequencyPenalty()
Getter for the frequency penalty.
Returns
float
: The frequency penalty.
PicoLLMGenerateParams.setFrequencyPenalty()
Setter for the frequency penalty.
Parameters
frequencyPenalty
float : The frequency penalty.
PicoLLMGenerateParams.getTemperature()
Getter for the temperature parameter.
Returns
float
: The temperature parameter.
PicoLLMGenerateParams.setTemperature()
Setter for the temperature parameter.
Parameters
temperature
float : The temperature parameter.
PicoLLMGenerateParams.getTopP()
Getter for the top-p parameter.
Returns
float
: The top-p parameter.
PicoLLMGenerateParams.setTopP()
Setter for the top-p parameter.
Parameters
topP
float : The top-p parameter.
PicoLLMGenerateParams.getNumTopChoices()
Getter for the number of top choices.
Returns
int
: The number of top choices.
PicoLLMGenerateParams.setNumTopChoices()
Setter for the number of top choices.
Parameters
numTopChoices
int : The number of top choices.
PicoLLMGenerateParams.getStreamCallback()
Getter for the completion stream callback.
Returns
PicoLLMStreamCallback
: The stream callback.
PicoLLMGenerateParams.setStreamCallback()
Setter for the completion stream callback.
Parameters
streamCallback
PicoLLMStreamCallback
: The stream callback.
PicoLLMGenerateParams.Builder
Builder class for creating a PicoLLMGenerateParams
instance.
PicoLLMGenerateParams.Builder.setCompletionTokenLimit()
Sets the maximum number of tokens allowed in the completion.
Parameters
completionTokenLimit
Integer : The maximum number of tokens allowed in the completion. If not set, there will be no limit imposed.
Returns
Builder
: The Builder instance.
PicoLLMGenerateParams.Builder.setStopPhrases()
Sets the phrases that trigger early completion termination.
Parameters
stopPhrases
String[] : Phrases that trigger early completion termination. Set tonull
to turn off this feature.
Returns
Builder
: The Builder instance.
PicoLLMGenerateParams.Builder.setSeed()
Sets the seed value for the internal random number generator.
Parameters
seed
Integer : The seed value for the internal random number generator. If not set, randomized outputs will be generated for a given prompt.
Returns
Builder
: The Builder instance.
PicoLLMGenerateParams.Builder.setPresencePenalty()
Sets the presence penalty.
Parameters
presencePenalty
float : The presence penalty.
Returns
Builder
: The Builder instance.
PicoLLMGenerateParams.Builder.setFrequencyPenalty()
Sets the frequency penalty.
Parameters
frequencyPenalty
float : The frequency penalty.
Returns
Builder
: The Builder instance.
PicoLLMGenerateParams.Builder.setTemperature()
Sets the temperature parameter.
Parameters
temperature
float : The temperature parameter.
Returns
Builder
: The Builder instance.
PicoLLMGenerateParams.Builder.setTopP()
Sets the top-p parameter.
Parameters
topP
float : The top-p parameter.
Returns
Builder
: The Builder instance.
PicoLLMGenerateParams.Builder.setNumTopChoices()
Sets the number of top choices.
Parameters
numTopChoices
int : The number of top choices.
Returns
Builder
: The Builder instance.
PicoLLMGenerateParams.Builder.setStreamCallback()
Sets the completion stream callback.
Parameters
streamCallback
PicoLLMStreamCallback : The stream callback.
Returns
Builder
: The Builder instance.
PicoLLMGenerateParams.Builder.build()
Constructs a new PicoLLMGenerateParams
object.
Returns
PicoLLMGenerateParams
: A newPicoLLMGenerateParams
object with the parameters set in the builder.
PicoLLMStreamCallback
Interface for receiving streaming result callbacks from picoLLM's .generate()
method.
PicoLLMCompletion
Represents a picoLLM completion result.
PicoLLMCompletion.getUsage()
Getter for usage information.
Returns
Usage
: The usage information.
PicoLLMCompletion.getEndpoint()
Getter for the reason for ending the generation process.
Returns
Endpoint
: The reason for ending the generation process.
PicoLLMCompletion.getCompletionTokens()
Getter for the generated tokens within completion and top alternative tokens.
Returns
CompletionToken[]
: The generated tokens within completion and top alternative tokens.
PicoLLMCompletion.getCompletion()
Getter for the completion string.
Returns
String
: The completion string.
PicoLLMCompletion.Usage
Represents usage information.
PicoLLMCompletion.Usage.getPromptTokens()
Getter for the number of tokens in the prompt.
Returns
int
: The number of tokens in the prompt.
PicoLLMCompletion.Usage.getCompletionTokens()
Getter for the number of tokens in the completion.
Returns
int
: The number of tokens in the completion.
PicoLLMCompletion.Endpoint
Reasons for ending the generation process.
PicoLLMCompletion.Token
Represents a generated token.
PicoLLMCompletion.Token.getToken
Getter for the token.
Returns
String
: The token.
PicoLLMCompletion.Token.getLogProb
Getter for the log probability.
Returns
float
: The log probability.
PicoLLMCompletion.CompletionToken
Represents a generated token within completion and top alternative tokens.
PicoLLMCompletion.CompletionToken.getToken
Getter for the token.
Returns
Token
: The token.
PicoLLMCompletion.CompletionToken.getTopChoices
Getter for the top alternative tokens.
Returns
Token
[] : The top alternative tokens.
PicoLLMDialog
PicoLLMDialog
is a helper class that stores a chat dialog and formats it according to an instruction-tuned LLM's chat template. PicoLLMDialog
is the base class. Each supported instruction-tuned LLM has an accompanying concrete subclass.
PicoLLMDialog.addHumanRequest()
Adds a human request to the dialog.
Parameters
content
String : The human request to add.
Throws
PicoLLMInvalidStateException
: if adding a human request without a corresponding LLM response.
PicoLLMDialog.addLLMResponse()
Adds an LLM response to the dialog.
Parameters
content
String : The LLM response to add.
Throws
PicoLLMInvalidStateException
: if adding an LLM response without a corresponding human request.
PicoLLMDialog.getPrompt()
Creates a prompt string given parameters passed the constructor and dialog's content.
Returns
- String : Formatted prompt.
Throws
PicoLLMException
: if called from the basePicoLLMDialog
class.
PicoLLMDialog.Builder
Builder class for constructing instances of PicoLLMDialog
.
PicoLLMDialog.Builder.setHistory()
Sets the history length for the builder.
Parameters
history
Integer : The history length to set. History refers to the number of latest back-and-forths to include in the prompt. Setting history tonull
will embed the entire dialog in the prompt.
Returns
Builder
: Builder instance.
PicoLLMDialog.Builder.setSystem()
Sets the system instruction for the builder.
Parameters
system
String : The system instruction to set. System instruction to embed in the prompt for configuring the model's responses.
Returns
Builder
: Builder instance.
PicoLLMDialog.Builder.build()
Builds a new instance of PicoLLMDialog
based on the configured settings.
Returns
PicoLLMDialog
: A new instance ofPicoLLMDialog
.
GemmaChatDialog
Represents a dialog helper specific for gemma-2b-it
and gemma-7b-it
models.
Llama2ChatDialog
Represents a dialog helper specific for llama-2-7b-chat
, llama-2-13b-chat
, and llama-2-70b-chat
models.
Llama3ChatDialog
Represents a dialog helper specific for llama-3-8b-instruct
and llama-3-70b-instruct
models.
MistralChatDialog
Represents a dialog helper specific for mistral-7b-instruct-v0.1
and mistral-7b-instruct-v0.2
models.
MixtralChatDialog
Represents a dialog helper specific for the mixtral-8x7b-instruct-v0.1
model.
Phi2ChatDialog
Represents a dialog helper specific for phi-2
models in chat
mode.
Phi2Dialog
Represents a dialog helper for the phi-2
model within PicoLLM. This is a base class that provides functionalities common to both chat
and qa
modes
Phi2QADialog
Represents a dialog helper specific for phi-2
models in qa
mode.