Skip to content

Commit

Permalink
Merge pull request #14 from tghamm/feature/2.0.0
Browse files Browse the repository at this point in the history
v2.0.0
  • Loading branch information
tghamm authored Dec 2, 2024
2 parents 8371bcb + 6f3c7e6 commit 6027c33
Show file tree
Hide file tree
Showing 28 changed files with 2,474 additions and 182 deletions.
56 changes: 56 additions & 0 deletions Mistral.SDK.Tests/ChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,61 @@ public async Task TestMistralCompletionSafeWithOptions()

Assert.IsTrue(!string.IsNullOrEmpty(response.Message.Text));
}

[TestMethod]
public async Task TestNonStreamingFunctionCalls()
{
IChatClient client = new MistralClient().Completions
.AsBuilder()
.UseFunctionInvocation()
.Build();

ChatOptions options = new()
{
ModelId = ModelDefinitions.MistralSmall,
MaxOutputTokens = 512,
ToolMode = ChatToolMode.Auto,
Tools = [AIFunctionFactory.Create((string personName) => personName switch {
"Alice" => "25",
_ => "40"
}, "GetPersonAge", "Gets the age of the person whose name is specified.")]
};

var res = await client.CompleteAsync("How old is Alice?", options);

Assert.IsTrue(
res.Message.Text?.Contains("25") is true,
res.Message.Text);
}

[TestMethod]
public async Task TestStreamingFunctionCalls()
{
IChatClient client = new MistralClient().Completions
.AsBuilder()
.UseFunctionInvocation()
.Build();

ChatOptions options = new()
{
ModelId = ModelDefinitions.MistralSmall,
MaxOutputTokens = 512,
ToolMode = ChatToolMode.Auto,
Tools = [AIFunctionFactory.Create((string personName) => personName switch {
"Alice" => "25",
_ => "40"
}, "GetPersonAge", "Gets the age of the person whose name is specified.")]
};

StringBuilder sb = new();
await foreach (var update in client.CompleteStreamingAsync("How old is Alice?", options))
{
sb.Append(update);
}

Assert.IsTrue(
sb.ToString().Contains("25") is true,
sb.ToString());
}
}
}
Loading

0 comments on commit 6027c33

Please sign in to comment.