Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
singhk97 committed Jan 26, 2024
1 parent 913423b commit bb2da9f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ public async void Test_RenderAsTextAsync_ShouldRenderWithFunction()
Assert.Equal(9, rendered.Length);
}

[Fact]
public async void Test_RenderAsTextAsync_ShouldRenderWithFunction_WithWhiteSpace()
{
TemplateSection section = new("this is a test message: {{ getMessage }}", ChatRole.User);
Mock<ITurnContext> context = new();
MemoryFork memory = new();
GPTTokenizer tokenizer = new();
PromptManager manager = new();

manager.AddFunction("getMessage", async (context, memory, functions, tokenizer, args) =>
{
return await Task.FromResult("Hello World!");
});

RenderedPromptSection<string> rendered = await section.RenderAsTextAsync(context.Object, memory, manager, tokenizer, 10);

Assert.Equal("this is a test message: Hello World!", rendered.Output);
Assert.Equal(9, rendered.Length);
}

[Fact]
public async void Test_RenderAsTextAsync_ShouldRenderWithFunctionArgs()
{
Expand Down Expand Up @@ -66,5 +86,22 @@ public async void Test_RenderAsTextAsync_ShouldRenderWithVariable()
Assert.Equal("this is a test message: \"Hello World!\"", rendered.Output);
Assert.Equal(10, rendered.Length);
}

[Fact]
public async void Test_RenderAsTextAsync_ShouldRenderWithVariable_WithWhitespace()
{
TemplateSection section = new("this is a test message: {{ $message }}", ChatRole.User);
Mock<ITurnContext> context = new();
MemoryFork memory = new();
GPTTokenizer tokenizer = new();
PromptManager manager = new();

memory.SetValue("message", "Hello World!");

RenderedPromptSection<string> rendered = await section.RenderAsTextAsync(context.Object, memory, manager, tokenizer, 15);

Assert.Equal("this is a test message: \"Hello World!\"", rendered.Output);
Assert.Equal(10, rendered.Length);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ private List<RenderFunction> Parse(string template)
{
if (chunk.Length > 0)
{
chunk = chunk.Trim();
if (chunk[0] == '$')
{
renderers.Add(this.CreateVariableRenderer(chunk.Substring(1)));
Expand Down

0 comments on commit bb2da9f

Please sign in to comment.