Package ai.picovoice.picollm
Class PicoLLM
java.lang.Object
ai.picovoice.picollm.PicoLLM
Android binding for picoLLM.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for creating a `PicoLLM` instance.classBuilder class for creating a `PicoLLMDialog` instance. -
Method Summary
Modifier and TypeMethodDescriptionvoiddelete()Deletes the resources acquired by picoLLM.float[]forward(int token) Performs a single forward pass given a token and returns the logits.generate(String prompt, PicoLLMGenerateParams generateParams) Generates completion text and relevant metadata given a text prompt and a set of generation parameters.static String[]Lists all available devices that picoLLM can use for inference.intGetter for model's context length.Retrieves a new instance of DialogBuilder for constructing dialog objects from the currently loaded picoLLM model.static intRetrieves the maximum number of top choices allowed during generation.getModel()Getter for model's name.static StringRetrieves the version of the picoLLM library.voidInterrupts `.generate()` if generation is in progress.voidreset()Resets the internal state of LLM.static voidint[]Tokenizes a given text using the model's tokenizer.
-
Method Details
-
setSdk
-
getVersion
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
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
Interrupts `.generate()` if generation is in progress. Otherwise, it has no effect.- Throws:
PicoLLMException- if interrupt fails.
-
tokenize
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
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
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
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
Retrieves a new instance of DialogBuilder for constructing dialog objects from the currently loaded picoLLM model.- Returns:
- A new instance of DialogBuilder.
-