picoLLM Inference Engine
.NET API
API Reference for the picoLLM .NET SDK (NuGet).
namespace: Pv
PicoLLM.Create()
Factory method for picoLLM Inference Engine.
Parameters
accessKeystring : AccessKey obtained from Picovoice Console.modelPathstring : Absolute path to the file containing LLM parameters.devicestring : String representation of the device (e.g., CPU or GPU) to use for inference. If set tobest, picoLLM picks the most suitable device. If set togpu, the engine uses the first available GPU device. To select a specific GPU device, set this argument togpu:${GPU_INDEX}, where${GPU_INDEX}is the index of the target GPU. If set tocpu, the engine will run on the CPU with the default number of threads. To specify the number of threads, set this argument tocpu:${NUM_THREADS}, where${NUM_THREADS}is the desired number of threads. If set tonull,bestdevice will be used.
Returns
PicoLLM: An instance of picoLLM Inference Engine.
Throws
PicoLLM.GetAvailableDevices()
Lists all available devices that picoLLM can use for inference. Each entry in the list can be used as the device
argument of the .create() factory method or the PicoLLM constructor.
Returns
string[]: List of all available devices that picoLLM can use for inference.
Throws
PicoLLM
Class for the picoLLM Inference Engine.
PicoLLM can be initialized either using the static constructor create().
Resources should be cleaned when you are done using the dispose() method.
PicoLLM.Model
Getter for model's name.
Returns
string: Model name.
PicoLLM.ContextLength
Getter for model's context length.
Returns
int: Context length.
PicoLLM.Version
Getter for version.
Returns
string: Version string.
PicoLLM.MaxTopChoices
Getter for maximum number of top choices.
Returns
int: Maximum number of top choices.
PicoLLM.Dispose()
Releases resources acquired by picoLLM.
PicoLLM.Generate()
Given a text prompt and a set of generation parameters, creates a completion text and relevant metadata.
Parameters
promptstring : Prompt.completionTokenLimitint? : Maximum number of tokens in the completion. If the generation process stops due to reaching this limit, the.endpointparameter inPicoLLMCompletionoutput will bePicoLLMEndpoints.COMPLETION_TOKEN_LIMIT_REACHED. Set tonullto impose no limit.stopPhrasesstring[] : The generation process stops when it encounters any of these phrases in the completion. The already generated completion, including the encountered stop phrase, will be returned. Theendpointparameter inPicoLLMCompletionoutput will bePicoLLMEndpoints.STOP_PHRASE_ENCOUNTERED. Set tonullto turn off this feature.seedint? : The internal random number generator uses it as its seed if set to a positive integer value. Seeding enforces deterministic outputs. Set tonullfor randomized outputs for a given prompt.presencePenaltyfloat : It penalizes logits already appearing in the partial completion if set to a positive value. If set to0.0, it has no effect.frequencyPenaltyfloat : If set to a positive floating-point value, it penalizes logits proportional to the frequency of their appearance in the partial completion. If set to0.0, it has no effect.temperaturefloat : Sampling temperature. Temperature is a non-negative floating-point value that controls the randomness of the sampler. A higher temperature smoothens the samplers' output, increasing the randomness. In contrast, a lower temperature creates a narrower distribution and reduces variability. Setting it to0selects the maximum logit during sampling.topPfloat : A positive floating-point number within 0 and 1. It restricts the sampler's choices to high-probability logits that form thetop_pportion of the probability mass. Hence, it avoids randomly selecting unlikely logits. A value of1.enables the sampler to pick any token with non-zero probability, turning off the feature.numTopChoicesint : If set to a positive value, picoLLM returns the list of the highest probability tokens for any generated token. Set to0to turn off the feature. The maximum number of top choices is.max_top_choices.streamCallbackAction<string> : If not set tonull, picoLLM executes this callback every time a new piece of completion string becomes available.
Returns
PicoLLMCompletion: Completion result.
Throws
PicoLLM.Interrupt()
Interrupts .Generate() if generation is in progress. Otherwise, it has no effect.
Throws
PicoLLM.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
textstring : Text.bosbool : If set totrue, the tokenizer prepends the beginning of the sentence token to the result.eosbool : If set totrue, the tokenizer appends the end of the sentence token to the result.
Returns
int[]: Tokens representing the input text.
Throws
PicoLLM.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
tokenint : The input token for the forward pass.
Returns
float[]: The logits resulting from the forward pass.
Throws
PicoLLM.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
PicoLLM.GetDialog()
Return the PicoLLMDialog object corresponding to the loaded model. The model needs to be instruction-tuned and have a specific chat template.
Parameters
modestring : Some models (e.g.,phi-2) define multiple chat template modes. For example,phi-2allows bothqaandchattemplates.historyint? : History refers to the number of latest back-and-forths to include in the prompt. Setting history tonullwill embed the entire dialog in the prompt.systemstring : System instruction to embed in the prompt for configuring the model's responses.
Returns
PicoLLMDialog: Constructed dialog object.
Throws
PicoLLMException
Error thrown if an error occurs within picoLLM Inference Engine.
Exceptions
PicoLLMUsage
Usage information.
PromptTokensint : Number of tokens in the prompt.CompletionTokensint : Number of tokens in the completion.
PicoLLMEndpoint
Reasons for ending the generation process.
END_OF_SENTENCE: 0COMPLETION_TOKEN_LIMIT_REACHED: 1STOP_PHRASE_ENCOUNTERED: 2INTERRUPTED: 3
PicoLLMToken
Generated token and its log probability.
Tokenstring : Token.LogProbfloat : Log probability.
PicoLLMCompletionToken
Generated token within completion and top alternative tokens.
TokenPicoLLMToken : Token.TopChoicesPicoLLMToken[] : Top choices.
PicoLLMCompletion
LLM completion result.
UsagePicoLLMUsage : Usage information.EndpointPicoLLMEndpoint : Reason for ending the generation process.CompletionTokensPicoLLMCompletionToken[] : Generated tokens within completion and top alternative tokens.Completionstring : Completion string.
PicoLLMDialog
Dialog is a helper class that stores a chat dialog and formats it according to an instruction-tuned LLM's chat template. Dialog is the base class. Each supported instruction-tuned LLM has an accompanying concrete subclass.
PicoLLMDialog.PicoLLMDialog()
Constructor.
Parameters
historyint? : History refers to the number of latest back-and-forths to include in the prompt. Setting history tonullwill embed the entire dialog in the prompt.systemstring : System instruction to embed in the prompt for configuring the model's responses.
Throws
PicoLLMDialog.AddHumanRequest()
Adds a human's request to the dialog.
Parameters
contentstring : Human's request.
Throws
PicoLLMDialog.AddLLMResponse()
Adds LLM's response to the dialog.
Parameters
contentstring : LLM's response.
Throws
GemmaChatDialog
Dialog helper for gemma-2b-it and gemma-7b-it.
GemmaChatDialog.Prompt()
Creates a prompt string for gemma-2b-it and gemma-7b-it models.
Returns
string: Formatted prompt.
Throws
Llama2ChatDialog
Dialog helper for llama-2-7b-chat, llama-2-13b-chat, and llama-2-70b-chat.
Llama2ChatDialog.Prompt()
Creates a prompt string for llama-2-7b-chat, llama-2-13b-chat, and llama-2-70b-chat models.
Returns
string: Formatted prompt.
Throws
Llama3ChatDialog
Dialog helper for llama-3-8b-instruct and llama-3-70b-instruct.
Llama3ChatDialog.Prompt()
Creates a prompt string for llama-3-8b-instruct and llama-3-70b-instruct models.
Returns
string: Formatted prompt.
Throws
Llama32ChatDialog
Dialog helper for llama-3.2-1b-instruct and llama-3.2-3b-instruct.
Llama32ChatDialog.Prompt()
Creates a prompt string for llama-3.2-1b-instruct and llama-3.2-3b-instruct models.
Returns
string: Formatted prompt.
Throws
MistralChatDialog
Dialog helper for mistral-7b-instruct-v0.1 and mistral-7b-instruct-v0.2.
MistralChatDialog.Prompt()
Creates a prompt string for mistral-7b-instruct-v0.1 and mistral-7b-instruct-v0.2 models.
Returns
string: Formatted prompt.
Throws
MixtralChatDialog
Dialog helper for mixtral-8x7b-instruct-v0.1. This class inherits methods from MistralChatDialog.
Phi2Dialog
Dialog helper for phi-2. This is a base class, use one of the mode-specific subclasses.
Phi2Dialog.Phi2Dialog()
Constructor for the Phi2Dialog class.
Parameters
humanRequestsTagstring : Tag for human input.llmResponsesTagstring : Tag for LLM input.historyint? : History refers to the number of latest back-and-forths to include in the prompt. Setting history tonullwill embed the entire dialog in the prompt.systemstring : System instruction to embed in the prompt for configuring the model's responses.
Phi2Dialog.Prompt()
Creates a prompt string for phi-2 model.
Returns
string: Formatted prompt.
Throws
Phi2QADialog
Dialog helper for phi-2 in qa mode. This class inherits methods from Phi2Dialog.
Phi2ChatDialog
Dialog helper for phi-2 in chat mode. This class inherits methods from Phi2Dialog.
Phi3Dialog
Dialog helper for phi3.
Phi35Dialog
Dialog helper for phi3.5.