|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- # Grammar
-
- Namespace: LLama.Grammars
-
- A grammar is a set of [GrammarRule](./llama.grammars.grammarrule.md)s for deciding which characters are valid next. Can be used to constrain
- output to certain formats - e.g. force the model to output JSON
-
- ```csharp
- public sealed class Grammar
- ```
-
- Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [Grammar](./llama.grammars.grammar.md)
-
- ## Properties
-
- ### **StartRuleIndex**
-
- Index of the initial rule to start from
-
- ```csharp
- public ulong StartRuleIndex { get; set; }
- ```
-
- #### Property Value
-
- [UInt64](https://docs.microsoft.com/en-us/dotnet/api/system.uint64)<br>
-
- ### **Rules**
-
- The rules which make up this grammar
-
- ```csharp
- public IReadOnlyList<GrammarRule> Rules { get; }
- ```
-
- #### Property Value
-
- [IReadOnlyList<GrammarRule>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ireadonlylist-1)<br>
-
- ## Constructors
-
- ### **Grammar(IReadOnlyList<GrammarRule>, UInt64)**
-
- Create a new grammar from a set of rules
-
- ```csharp
- public Grammar(IReadOnlyList<GrammarRule> rules, ulong startRuleIndex)
- ```
-
- #### Parameters
-
- `rules` [IReadOnlyList<GrammarRule>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ireadonlylist-1)<br>
- The rules which make up this grammar
-
- `startRuleIndex` [UInt64](https://docs.microsoft.com/en-us/dotnet/api/system.uint64)<br>
- Index of the initial rule to start from
-
- #### Exceptions
-
- [ArgumentOutOfRangeException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentoutofrangeexception)<br>
-
- ## Methods
-
- ### **CreateInstance()**
-
- Create a `SafeLLamaGrammarHandle` instance to use for parsing
-
- ```csharp
- public SafeLLamaGrammarHandle CreateInstance()
- ```
-
- #### Returns
-
- [SafeLLamaGrammarHandle](./llama.native.safellamagrammarhandle.md)<br>
-
- ### **Parse(String, String)**
-
- Parse a string of GGML BNF into a Grammar
-
- ```csharp
- public static Grammar Parse(string gbnf, string startRule)
- ```
-
- #### Parameters
-
- `gbnf` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
- The string to parse
-
- `startRule` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
- Name of the start rule of this grammar
-
- #### Returns
-
- [Grammar](./llama.grammars.grammar.md)<br>
- A Grammar which can be converted into a SafeLLamaGrammarHandle for sampling
-
- #### Exceptions
-
- [GrammarFormatException](./llama.exceptions.grammarformatexception.md)<br>
- Thrown if input is malformed
-
- ### **ToString()**
-
- ```csharp
- public string ToString()
- ```
-
- #### Returns
-
- [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
|