Namespace: LLama.Batched
A single conversation thread that can be prompted (adding tokens from the user) or inferred (extracting a token from the LLM)
public sealed class Conversation : System.IDisposable
Inheritance Object → Conversation
Implements IDisposable
The executor which this conversation belongs to
public BatchedExecutor Executor { get; }
Unique ID for this conversation
public LLamaSeqId ConversationId { get; }
Total number of tokens in this conversation, cannot exceed the context length.
public int TokenCount { get; }
Indicates if this conversation has been disposed, nothing can be done with a disposed conversation
public bool IsDisposed { get; }
Indicates if this conversation is waiting for inference to be run on the executor. "Prompt" and "Sample" cannot be called when this is true.
public bool RequiresInference { get; }
Indicates that this conversation should be sampled.
public bool RequiresSampling { get; }
Finalizer for Conversation
protected void Finalize()
End this conversation, freeing all resources used by it
public void Dispose()
Create a copy of the current conversation
public Conversation Fork()
Remarks:
The copy shares internal state, so consumes very little extra memory.
Get the logits from this conversation, ready for sampling
public Span<float> Sample()
CannotSampleRequiresPromptException
Thrown if this conversation was not prompted before the previous call to infer
CannotSampleRequiresInferenceException
Thrown if Infer() must be called on the executor
Add tokens to this conversation
public void Prompt(string input)
input String
Add tokens to this conversation
public void Prompt(List<LLamaToken> tokens)
tokens List<LLamaToken>
AlreadyPromptedConversationException
Add tokens to this conversation
public void Prompt(ReadOnlySpan<LLamaToken> tokens)
tokens ReadOnlySpan<LLamaToken>
AlreadyPromptedConversationException
Add a single token to this conversation
public void Prompt(LLamaToken token)
token LLamaToken
AlreadyPromptedConversationException
Directly modify the KV cache of this conversation
public void Modify(ModifyKvCache modifier)
modifier ModifyKvCache
CannotModifyWhileRequiresInferenceException
Thrown if this method is called while Conversation.RequiresInference == true