using System; using System.Runtime.InteropServices; namespace LLama.Native; /// /// Passed to beam_search_callback function. /// Whenever 0 < common_prefix_length, this number of tokens should be copied from any of the beams /// (e.g. beams[0]) as they will be removed (shifted) from all beams in all subsequent callbacks. /// [StructLayout(LayoutKind.Sequential)] public struct LLamaBeamsState { /// /// The state of each individual beam /// private unsafe LLamaBeamView* beam_views; /// /// Number of elements in beam_views /// private nint n_beams; /// /// Current max length of prefix tokens shared by all beams. /// public ulong CommonPrefixLength; /// /// True iff this is the last callback invocation. /// public bool LastCall; /// /// The current state of each beam /// public Span Beams { get { unsafe { if (n_beams > int.MaxValue) throw new InvalidOperationException("More than 2147483647 beams is not supported"); return new Span(beam_views, (int)n_beams); } } } }