Skip to content

Commit 6b171e4

Browse files
committed
Re-Instantiate Grammar upon every Prompt
1 parent 4e9473d commit 6b171e4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

LLama.Examples/Examples/GrammarJsonResponse.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,23 @@ public static async Task Run()
2525
Console.WriteLine("The executor has been enabled. In this example, the LLM will follow your instructions and always respond in a JSON format. For example, you can input \"Tell me the attributes of a good dish\"");
2626
Console.ForegroundColor = ConsoleColor.White;
2727

28-
using var grammarInstance = grammar.CreateInstance();
28+
var samplingPipeline = new DefaultSamplingPipeline
29+
{
30+
Temperature = 0.6f
31+
};
32+
2933
var inferenceParams = new InferenceParams()
3034
{
31-
SamplingPipeline = new DefaultSamplingPipeline
32-
{
33-
Temperature = 0.6f,
34-
Grammar = grammarInstance
35-
},
35+
SamplingPipeline = samplingPipeline,
3636
AntiPrompts = new List<string> { "Question:", "#", "Question: ", ".\n" },
3737
MaxTokens = 50,
3838
};
3939

4040
while (true)
4141
{
42+
using var grammarInstance = grammar.CreateInstance();
43+
samplingPipeline.Grammar = grammarInstance;
44+
4245
Console.Write("\nQuestion: ");
4346
Console.ForegroundColor = ConsoleColor.Green;
4447
var prompt = Console.ReadLine();

0 commit comments

Comments
 (0)