openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.2.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/Chat/OpenAIChatModelFactoryTests.cs

943lines · modeblame

79014abcShivangiReja1 years ago1using System;
2using System.Collections.Generic;
3using System.Linq;
4using NUnit.Framework;
5using OpenAI.Chat;
6
7namespace OpenAI.Tests.Chat;
8
9[Parallelizable(ParallelScope.All)]
2ab1a942Jose Arriaga Maldonado1 years ago10[Category("Chat")]
79014abcShivangiReja1 years ago11[Category("Smoke")]
12public partial class OpenAIChatModelFactoryTests
13{
14[Test]
15public void ChatCompletionWithNoPropertiesWorks()
16{
17ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion();
18
19Assert.That(chatCompletion.Id, Is.Null);
20Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
21Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
22Assert.That(chatCompletion.Refusal, Is.Null);
23Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
24Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
2ab1a942Jose Arriaga Maldonado1 years ago25#pragma warning disable CS0618
79014abcShivangiReja1 years ago26Assert.That(chatCompletion.FunctionCall, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago27#pragma warning restore CS0618
79014abcShivangiReja1 years ago28Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
29Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
30Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
31Assert.That(chatCompletion.Model, Is.Null);
32Assert.That(chatCompletion.SystemFingerprint, Is.Null);
33Assert.That(chatCompletion.Usage, Is.Null);
34}
35
36[Test]
37public void ChatCompletionWithIdWorks()
38{
39string id = "chat_completion_id";
40ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(id: id);
41
42Assert.That(chatCompletion.Id, Is.EqualTo(id));
43Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
44Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
45Assert.That(chatCompletion.Refusal, Is.Null);
46Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
47Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
2ab1a942Jose Arriaga Maldonado1 years ago48#pragma warning disable CS0618
79014abcShivangiReja1 years ago49Assert.That(chatCompletion.FunctionCall, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago50#pragma warning restore CS0618
79014abcShivangiReja1 years ago51Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
52Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
53Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
54Assert.That(chatCompletion.Model, Is.Null);
55Assert.That(chatCompletion.SystemFingerprint, Is.Null);
56Assert.That(chatCompletion.Usage, Is.Null);
57}
58
59[Test]
60public void ChatCompletionWithFinishReasonWorks()
61{
62ChatFinishReason finishReason = ChatFinishReason.ToolCalls;
63ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(finishReason: finishReason);
64
65Assert.That(chatCompletion.Id, Is.Null);
66Assert.That(chatCompletion.FinishReason, Is.EqualTo(finishReason));
67Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
68Assert.That(chatCompletion.Refusal, Is.Null);
69Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
70Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
2ab1a942Jose Arriaga Maldonado1 years ago71#pragma warning disable CS0618
79014abcShivangiReja1 years ago72Assert.That(chatCompletion.FunctionCall, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago73#pragma warning restore CS0618
79014abcShivangiReja1 years ago74Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
75Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
76Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
77Assert.That(chatCompletion.Model, Is.Null);
78Assert.That(chatCompletion.SystemFingerprint, Is.Null);
79Assert.That(chatCompletion.Usage, Is.Null);
80}
81
82[Test]
83public void ChatCompletionWithContentWorks()
84{
31c2ba63Jose Arriaga Maldonado1 years ago85ChatMessageContent content = [
2ab1a942Jose Arriaga Maldonado1 years ago86ChatMessageContentPart.CreateTextPart("first part"),
87ChatMessageContentPart.CreateTextPart("second part")
79014abcShivangiReja1 years ago88];
89ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(content: content);
90
91Assert.That(chatCompletion.Id, Is.Null);
92Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
93Assert.That(chatCompletion.Content.SequenceEqual(content), Is.True);
94Assert.That(chatCompletion.Refusal, Is.Null);
95Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
96Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
2ab1a942Jose Arriaga Maldonado1 years ago97#pragma warning disable CS0618
79014abcShivangiReja1 years ago98Assert.That(chatCompletion.FunctionCall, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago99#pragma warning restore CS0618
79014abcShivangiReja1 years ago100Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
101Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
102Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
103Assert.That(chatCompletion.Model, Is.Null);
104Assert.That(chatCompletion.SystemFingerprint, Is.Null);
105Assert.That(chatCompletion.Usage, Is.Null);
106}
107
108[Test]
109public void ChatCompletionWithRefusalWorks()
110{
111string refusal = "This is a refusal.";
112ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(refusal: refusal);
113
114Assert.That(chatCompletion.Id, Is.Null);
115Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
116Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
117Assert.That(chatCompletion.Refusal, Is.EqualTo(refusal));
118Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
119Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
2ab1a942Jose Arriaga Maldonado1 years ago120#pragma warning disable CS0618
79014abcShivangiReja1 years ago121Assert.That(chatCompletion.FunctionCall, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago122#pragma warning restore CS0618
79014abcShivangiReja1 years ago123Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
124Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
125Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
126Assert.That(chatCompletion.Model, Is.Null);
127Assert.That(chatCompletion.SystemFingerprint, Is.Null);
128Assert.That(chatCompletion.Usage, Is.Null);
129}
130
131[Test]
132public void ChatCompletionWithToolCallsWorks()
133{
134IEnumerable<ChatToolCall> toolCalls = [
31c2ba63Jose Arriaga Maldonado1 years ago135ChatToolCall.CreateFunctionToolCall("id1", "get_recipe", BinaryData.FromBytes("{}"u8.ToArray())),
136ChatToolCall.CreateFunctionToolCall("id2", "get_location", BinaryData.FromBytes("{}"u8.ToArray()))
79014abcShivangiReja1 years ago137];
138ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(toolCalls: toolCalls);
139
140Assert.That(chatCompletion.Id, Is.Null);
141Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
142Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
143Assert.That(chatCompletion.Refusal, Is.Null);
144Assert.That(chatCompletion.ToolCalls.SequenceEqual(toolCalls), Is.True);
145Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
2ab1a942Jose Arriaga Maldonado1 years ago146#pragma warning disable CS0618
79014abcShivangiReja1 years ago147Assert.That(chatCompletion.FunctionCall, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago148#pragma warning restore CS0618
79014abcShivangiReja1 years ago149Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
150Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
151Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
152Assert.That(chatCompletion.Model, Is.Null);
153Assert.That(chatCompletion.SystemFingerprint, Is.Null);
154Assert.That(chatCompletion.Usage, Is.Null);
155}
156
157[Test]
158public void ChatCompletionWithRoleWorks()
159{
160ChatMessageRole role = ChatMessageRole.Tool;
161ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(role: role);
162
163Assert.That(chatCompletion.Id, Is.Null);
164Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
165Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
166Assert.That(chatCompletion.Refusal, Is.Null);
167Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
168Assert.That(chatCompletion.Role, Is.EqualTo(role));
2ab1a942Jose Arriaga Maldonado1 years ago169#pragma warning disable CS0618
79014abcShivangiReja1 years ago170Assert.That(chatCompletion.FunctionCall, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago171#pragma warning restore CS0618
79014abcShivangiReja1 years ago172Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
173Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
174Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
175Assert.That(chatCompletion.Model, Is.Null);
176Assert.That(chatCompletion.SystemFingerprint, Is.Null);
177Assert.That(chatCompletion.Usage, Is.Null);
178}
179
180[Test]
181public void ChatCompletionWithFunctionCallWorks()
182{
2ab1a942Jose Arriaga Maldonado1 years ago183#pragma warning disable CS0618
31c2ba63Jose Arriaga Maldonado1 years ago184ChatFunctionCall functionCall = new ChatFunctionCall("get_recipe", BinaryData.FromBytes("{}"u8.ToArray()));
2ab1a942Jose Arriaga Maldonado1 years ago185#pragma warning restore CS0618
79014abcShivangiReja1 years ago186ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(functionCall: functionCall);
187
188Assert.That(chatCompletion.Id, Is.Null);
189Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
190Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
191Assert.That(chatCompletion.Refusal, Is.Null);
192Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
193Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
2ab1a942Jose Arriaga Maldonado1 years ago194#pragma warning disable CS0618
79014abcShivangiReja1 years ago195Assert.That(chatCompletion.FunctionCall, Is.EqualTo(functionCall));
2ab1a942Jose Arriaga Maldonado1 years ago196#pragma warning restore CS0618
79014abcShivangiReja1 years ago197Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
198Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
199Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
200Assert.That(chatCompletion.Model, Is.Null);
201Assert.That(chatCompletion.SystemFingerprint, Is.Null);
202Assert.That(chatCompletion.Usage, Is.Null);
203}
204
205[Test]
206public void ChatCompletionWithContentTokenLogProbabilitiesWorks()
207{
2ab1a942Jose Arriaga Maldonado1 years ago208IEnumerable<ChatTokenLogProbabilityDetails> contentTokenLogProbabilities = [
209OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 1f),
210OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 2f)
79014abcShivangiReja1 years ago211];
212ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(contentTokenLogProbabilities: contentTokenLogProbabilities);
213
214Assert.That(chatCompletion.Id, Is.Null);
215Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
216Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
217Assert.That(chatCompletion.Refusal, Is.Null);
218Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
219Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
2ab1a942Jose Arriaga Maldonado1 years ago220#pragma warning disable CS0618
79014abcShivangiReja1 years ago221Assert.That(chatCompletion.FunctionCall, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago222#pragma warning restore CS0618
79014abcShivangiReja1 years ago223Assert.That(chatCompletion.ContentTokenLogProbabilities.SequenceEqual(contentTokenLogProbabilities), Is.True);
224Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
225Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
226Assert.That(chatCompletion.Model, Is.Null);
227Assert.That(chatCompletion.SystemFingerprint, Is.Null);
228Assert.That(chatCompletion.Usage, Is.Null);
229}
230
231[Test]
232public void ChatCompletionWithRefusalTokenLogProbabilitiesWorks()
233{
2ab1a942Jose Arriaga Maldonado1 years ago234IEnumerable<ChatTokenLogProbabilityDetails> refusalTokenLogProbabilities = [
235OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 1f),
236OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 2f)
79014abcShivangiReja1 years ago237];
238ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(refusalTokenLogProbabilities: refusalTokenLogProbabilities);
239
240Assert.That(chatCompletion.Id, Is.Null);
241Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
242Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
243Assert.That(chatCompletion.Refusal, Is.Null);
244Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
245Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
2ab1a942Jose Arriaga Maldonado1 years ago246#pragma warning disable CS0618
79014abcShivangiReja1 years ago247Assert.That(chatCompletion.FunctionCall, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago248#pragma warning restore CS0618
79014abcShivangiReja1 years ago249Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
250Assert.That(chatCompletion.RefusalTokenLogProbabilities.SequenceEqual(refusalTokenLogProbabilities), Is.True);
251Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
252Assert.That(chatCompletion.Model, Is.Null);
253Assert.That(chatCompletion.SystemFingerprint, Is.Null);
254Assert.That(chatCompletion.Usage, Is.Null);
255}
256
257[Test]
258public void ChatCompletionWithCreatedAtWorks()
259{
260DateTimeOffset createdAt = DateTimeOffset.UtcNow;
261ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(createdAt: createdAt);
262
263Assert.That(chatCompletion.Id, Is.Null);
264Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
265Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
266Assert.That(chatCompletion.Refusal, Is.Null);
267Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
268Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
2ab1a942Jose Arriaga Maldonado1 years ago269#pragma warning disable CS0618
79014abcShivangiReja1 years ago270Assert.That(chatCompletion.FunctionCall, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago271#pragma warning restore CS0618
79014abcShivangiReja1 years ago272Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
273Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
274Assert.That(chatCompletion.CreatedAt, Is.EqualTo(createdAt));
275Assert.That(chatCompletion.Model, Is.Null);
276Assert.That(chatCompletion.SystemFingerprint, Is.Null);
277Assert.That(chatCompletion.Usage, Is.Null);
278}
279
280[Test]
281public void ChatCompletionWithModelWorks()
282{
283string model = "topmodel";
284ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(model: model);
285
286Assert.That(chatCompletion.Id, Is.Null);
287Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
288Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
289Assert.That(chatCompletion.Refusal, Is.Null);
290Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
291Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
2ab1a942Jose Arriaga Maldonado1 years ago292#pragma warning disable CS0618
79014abcShivangiReja1 years ago293Assert.That(chatCompletion.FunctionCall, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago294#pragma warning restore CS0618
79014abcShivangiReja1 years ago295Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
296Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
297Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
298Assert.That(chatCompletion.Model, Is.EqualTo(model));
299Assert.That(chatCompletion.SystemFingerprint, Is.Null);
300Assert.That(chatCompletion.Usage, Is.Null);
301}
302
303[Test]
304public void ChatCompletionWithSystemFingerprintWorks()
305{
306string systemFingerprint = "footprint";
307ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(systemFingerprint: systemFingerprint);
308
309Assert.That(chatCompletion.Id, Is.Null);
310Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
311Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
312Assert.That(chatCompletion.Refusal, Is.Null);
313Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
314Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
2ab1a942Jose Arriaga Maldonado1 years ago315#pragma warning disable CS0618
79014abcShivangiReja1 years ago316Assert.That(chatCompletion.FunctionCall, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago317#pragma warning restore CS0618
79014abcShivangiReja1 years ago318Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
319Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
320Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
321Assert.That(chatCompletion.Model, Is.Null);
322Assert.That(chatCompletion.SystemFingerprint, Is.EqualTo(systemFingerprint));
323Assert.That(chatCompletion.Usage, Is.Null);
324}
325
326[Test]
327public void ChatCompletionWithUsageWorks()
328{
75eded51ShivangiReja1 years ago329ChatTokenUsage usage = OpenAIChatModelFactory.ChatTokenUsage(outputTokenCount: 20);
79014abcShivangiReja1 years ago330ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(usage: usage);
331
332Assert.That(chatCompletion.Id, Is.Null);
333Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
334Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
335Assert.That(chatCompletion.Refusal, Is.Null);
336Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
337Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
2ab1a942Jose Arriaga Maldonado1 years ago338#pragma warning disable CS0618
79014abcShivangiReja1 years ago339Assert.That(chatCompletion.FunctionCall, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago340#pragma warning restore CS0618
79014abcShivangiReja1 years ago341Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
342Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
343Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
344Assert.That(chatCompletion.Model, Is.Null);
345Assert.That(chatCompletion.SystemFingerprint, Is.Null);
346Assert.That(chatCompletion.Usage, Is.EqualTo(usage));
347}
348
349[Test]
2ab1a942Jose Arriaga Maldonado1 years ago350public void ChatTokenLogProbabilityDetailsWithNoPropertiesWorks()
79014abcShivangiReja1 years ago351{
b0f9e5c3Jose Arriaga Maldonado1 years ago352ChatTokenLogProbabilityDetails chatTokenLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenLogProbabilityDetails();
79014abcShivangiReja1 years ago353
2ab1a942Jose Arriaga Maldonado1 years ago354Assert.That(chatTokenLogProbabilityDetails.Token, Is.Null);
355Assert.That(chatTokenLogProbabilityDetails.LogProbability, Is.EqualTo(0f));
356Assert.That(chatTokenLogProbabilityDetails.Utf8Bytes, Is.Null);
357Assert.That(chatTokenLogProbabilityDetails.TopLogProbabilities, Is.Not.Null.And.Empty);
79014abcShivangiReja1 years ago358}
359
360[Test]
2ab1a942Jose Arriaga Maldonado1 years ago361public void ChatTokenLogProbabilityDetailsWithTokenWorks()
79014abcShivangiReja1 years ago362{
363string token = "a_token_of_appreciation";
2ab1a942Jose Arriaga Maldonado1 years ago364ChatTokenLogProbabilityDetails chatTokenLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(token: token);
79014abcShivangiReja1 years ago365
2ab1a942Jose Arriaga Maldonado1 years ago366Assert.That(chatTokenLogProbabilityDetails.Token, Is.EqualTo(token));
367Assert.That(chatTokenLogProbabilityDetails.LogProbability, Is.EqualTo(0f));
368Assert.That(chatTokenLogProbabilityDetails.Utf8Bytes, Is.Null);
369Assert.That(chatTokenLogProbabilityDetails.TopLogProbabilities, Is.Not.Null.And.Empty);
79014abcShivangiReja1 years ago370}
371
372[Test]
2ab1a942Jose Arriaga Maldonado1 years ago373public void ChatTokenLogProbabilityDetailsWithLogProbabilityWorks()
79014abcShivangiReja1 years ago374{
375float logProbability = 3.14f;
2ab1a942Jose Arriaga Maldonado1 years ago376ChatTokenLogProbabilityDetails chatTokenLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: logProbability);
79014abcShivangiReja1 years ago377
2ab1a942Jose Arriaga Maldonado1 years ago378Assert.That(chatTokenLogProbabilityDetails.Token, Is.Null);
379Assert.That(chatTokenLogProbabilityDetails.LogProbability, Is.EqualTo(logProbability));
380Assert.That(chatTokenLogProbabilityDetails.Utf8Bytes, Is.Null);
381Assert.That(chatTokenLogProbabilityDetails.TopLogProbabilities, Is.Not.Null.And.Empty);
79014abcShivangiReja1 years ago382}
383
384[Test]
2ab1a942Jose Arriaga Maldonado1 years ago385public void ChatTokenLogProbabilityDetailsWithUtf8ByteValuesWorks()
79014abcShivangiReja1 years ago386{
2ab1a942Jose Arriaga Maldonado1 years ago387ReadOnlyMemory<byte> utf8Bytes = "hello"u8.ToArray();
388ChatTokenLogProbabilityDetails chatTokenLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(utf8Bytes: utf8Bytes);
79014abcShivangiReja1 years ago389
2ab1a942Jose Arriaga Maldonado1 years ago390Assert.That(chatTokenLogProbabilityDetails.Token, Is.Null);
391Assert.That(chatTokenLogProbabilityDetails.LogProbability, Is.EqualTo(0f));
392Assert.That(chatTokenLogProbabilityDetails.Utf8Bytes.Value.ToArray().SequenceEqual(utf8Bytes.ToArray()), Is.True);
393Assert.That(chatTokenLogProbabilityDetails.TopLogProbabilities, Is.Not.Null.And.Empty);
79014abcShivangiReja1 years ago394}
395
396[Test]
2ab1a942Jose Arriaga Maldonado1 years ago397public void ChatTokenLogProbabilityDetailsWithTopLogProbabilitiesWorks()
79014abcShivangiReja1 years ago398{
2ab1a942Jose Arriaga Maldonado1 years ago399IEnumerable<ChatTokenTopLogProbabilityDetails> topLogProbabilities = [
400OpenAIChatModelFactory.ChatTokenTopLogProbabilityDetails(token: "firstToken"),
401OpenAIChatModelFactory.ChatTokenTopLogProbabilityDetails(token: "secondToken")
79014abcShivangiReja1 years ago402];
2ab1a942Jose Arriaga Maldonado1 years ago403ChatTokenLogProbabilityDetails chatTokenLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(topLogProbabilities: topLogProbabilities);
79014abcShivangiReja1 years ago404
2ab1a942Jose Arriaga Maldonado1 years ago405Assert.That(chatTokenLogProbabilityDetails.Token, Is.Null);
406Assert.That(chatTokenLogProbabilityDetails.LogProbability, Is.EqualTo(0f));
407Assert.That(chatTokenLogProbabilityDetails.Utf8Bytes, Is.Null);
408Assert.That(chatTokenLogProbabilityDetails.TopLogProbabilities.SequenceEqual(topLogProbabilities), Is.True);
79014abcShivangiReja1 years ago409}
410
411[Test]
2ab1a942Jose Arriaga Maldonado1 years ago412public void ChatTokenTopLogProbabilityDetailsWithNoPropertiesWorks()
79014abcShivangiReja1 years ago413{
2ab1a942Jose Arriaga Maldonado1 years ago414ChatTokenTopLogProbabilityDetails chatTokenTopLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenTopLogProbabilityDetails();
79014abcShivangiReja1 years ago415
2ab1a942Jose Arriaga Maldonado1 years ago416Assert.That(chatTokenTopLogProbabilityDetails.Token, Is.Null);
417Assert.That(chatTokenTopLogProbabilityDetails.LogProbability, Is.EqualTo(0f));
418Assert.That(chatTokenTopLogProbabilityDetails.Utf8Bytes, Is.Null);
79014abcShivangiReja1 years ago419}
420
421[Test]
2ab1a942Jose Arriaga Maldonado1 years ago422public void ChatTokenTopLogProbabilityDetailsWithTokenWorks()
79014abcShivangiReja1 years ago423{
424string token = "a_token_of_appreciation";
2ab1a942Jose Arriaga Maldonado1 years ago425ChatTokenTopLogProbabilityDetails chatTokenTopLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenTopLogProbabilityDetails(token: token);
79014abcShivangiReja1 years ago426
2ab1a942Jose Arriaga Maldonado1 years ago427Assert.That(chatTokenTopLogProbabilityDetails.Token, Is.EqualTo(token));
428Assert.That(chatTokenTopLogProbabilityDetails.LogProbability, Is.EqualTo(0f));
429Assert.That(chatTokenTopLogProbabilityDetails.Utf8Bytes, Is.Null);
79014abcShivangiReja1 years ago430}
431
432[Test]
2ab1a942Jose Arriaga Maldonado1 years ago433public void ChatTokenTopLogProbabilityDetailsWithLogProbabilityWorks()
79014abcShivangiReja1 years ago434{
435float logProbability = 3.14f;
2ab1a942Jose Arriaga Maldonado1 years ago436ChatTokenTopLogProbabilityDetails chatTokenTopLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenTopLogProbabilityDetails(logProbability: logProbability);
79014abcShivangiReja1 years ago437
2ab1a942Jose Arriaga Maldonado1 years ago438Assert.That(chatTokenTopLogProbabilityDetails.Token, Is.Null);
439Assert.That(chatTokenTopLogProbabilityDetails.LogProbability, Is.EqualTo(logProbability));
440Assert.That(chatTokenTopLogProbabilityDetails.Utf8Bytes, Is.Null);
79014abcShivangiReja1 years ago441}
442
443[Test]
2ab1a942Jose Arriaga Maldonado1 years ago444public void ChatTokenTopLogProbabilityDetailsWithUtf8ByteValuesWorks()
79014abcShivangiReja1 years ago445{
2ab1a942Jose Arriaga Maldonado1 years ago446ReadOnlyMemory<byte> utf8Bytes = "hello"u8.ToArray();
447ChatTokenTopLogProbabilityDetails chatTokenTopLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenTopLogProbabilityDetails(utf8Bytes: utf8Bytes);
79014abcShivangiReja1 years ago448
2ab1a942Jose Arriaga Maldonado1 years ago449Assert.That(chatTokenTopLogProbabilityDetails.Token, Is.Null);
450Assert.That(chatTokenTopLogProbabilityDetails.LogProbability, Is.EqualTo(0f));
451Assert.That(chatTokenTopLogProbabilityDetails.Utf8Bytes.Value.ToArray().SequenceEqual(utf8Bytes.ToArray()), Is.True);
79014abcShivangiReja1 years ago452}
453
454[Test]
455public void ChatTokenUsageWithNoPropertiesWorks()
456{
457ChatTokenUsage chatTokenUsage = OpenAIChatModelFactory.ChatTokenUsage();
458
2ab1a942Jose Arriaga Maldonado1 years ago459Assert.That(chatTokenUsage.OutputTokenCount, Is.EqualTo(0));
460Assert.That(chatTokenUsage.InputTokenCount, Is.EqualTo(0));
461Assert.That(chatTokenUsage.TotalTokenCount, Is.EqualTo(0));
79014abcShivangiReja1 years ago462}
463
464[Test]
465public void ChatTokenUsageWithOutputTokensWorks()
466{
467int outputTokens = 271828;
75eded51ShivangiReja1 years ago468ChatTokenUsage chatTokenUsage = OpenAIChatModelFactory.ChatTokenUsage(outputTokenCount: outputTokens);
79014abcShivangiReja1 years ago469
2ab1a942Jose Arriaga Maldonado1 years ago470Assert.That(chatTokenUsage.OutputTokenCount, Is.EqualTo(outputTokens));
471Assert.That(chatTokenUsage.InputTokenCount, Is.EqualTo(0));
472Assert.That(chatTokenUsage.TotalTokenCount, Is.EqualTo(0));
79014abcShivangiReja1 years ago473}
474
475[Test]
476public void ChatTokenUsageWithInputTokensWorks()
477{
478int inputTokens = 271828;
75eded51ShivangiReja1 years ago479ChatTokenUsage chatTokenUsage = OpenAIChatModelFactory.ChatTokenUsage(inputTokenCount: inputTokens);
79014abcShivangiReja1 years ago480
2ab1a942Jose Arriaga Maldonado1 years ago481Assert.That(chatTokenUsage.OutputTokenCount, Is.EqualTo(0));
482Assert.That(chatTokenUsage.InputTokenCount, Is.EqualTo(inputTokens));
483Assert.That(chatTokenUsage.TotalTokenCount, Is.EqualTo(0));
79014abcShivangiReja1 years ago484}
485
486[Test]
487public void ChatTokenUsageWithTotalTokensWorks()
488{
489int totalTokens = 271828;
75eded51ShivangiReja1 years ago490ChatTokenUsage chatTokenUsage = OpenAIChatModelFactory.ChatTokenUsage(totalTokenCount: totalTokens);
79014abcShivangiReja1 years ago491
2ab1a942Jose Arriaga Maldonado1 years ago492Assert.That(chatTokenUsage.OutputTokenCount, Is.EqualTo(0));
493Assert.That(chatTokenUsage.InputTokenCount, Is.EqualTo(0));
494Assert.That(chatTokenUsage.TotalTokenCount, Is.EqualTo(totalTokens));
79014abcShivangiReja1 years ago495}
496
497[Test]
498public void StreamingChatCompletionUpdateWithNoPropertiesWorks()
499{
500StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate();
501
31c2ba63Jose Arriaga Maldonado1 years ago502Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
79014abcShivangiReja1 years ago503Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
2ab1a942Jose Arriaga Maldonado1 years ago504#pragma warning disable CS0618
79014abcShivangiReja1 years ago505Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago506#pragma warning restore CS0618
79014abcShivangiReja1 years ago507Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
508Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
509Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
510Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
511Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
512Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
513Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
514Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
515Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
516Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
517}
518
519[Test]
520public void StreamingChatCompletionUpdateWithIdWorks()
521{
522string id = "chat_completion_id";
31c2ba63Jose Arriaga Maldonado1 years ago523StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(completionId: id);
79014abcShivangiReja1 years ago524
31c2ba63Jose Arriaga Maldonado1 years ago525Assert.That(streamingChatCompletionUpdate.CompletionId, Is.EqualTo(id));
79014abcShivangiReja1 years ago526Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
2ab1a942Jose Arriaga Maldonado1 years ago527#pragma warning disable CS0618
79014abcShivangiReja1 years ago528Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago529#pragma warning restore CS0618
79014abcShivangiReja1 years ago530Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
531Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
532Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
533Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
534Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
535Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
536Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
537Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
538Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
539Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
540}
541
542[Test]
543public void StreamingChatCompletionUpdateWithContentUpdateWorks()
544{
31c2ba63Jose Arriaga Maldonado1 years ago545ChatMessageContent contentUpdate = [
2ab1a942Jose Arriaga Maldonado1 years ago546ChatMessageContentPart.CreateTextPart("first part"),
547ChatMessageContentPart.CreateTextPart("second part")
79014abcShivangiReja1 years ago548];
549StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(contentUpdate: contentUpdate);
550
31c2ba63Jose Arriaga Maldonado1 years ago551Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
79014abcShivangiReja1 years ago552Assert.That(streamingChatCompletionUpdate.ContentUpdate.SequenceEqual(contentUpdate), Is.True);
2ab1a942Jose Arriaga Maldonado1 years ago553#pragma warning disable CS0618
79014abcShivangiReja1 years ago554Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago555#pragma warning restore CS0618
79014abcShivangiReja1 years ago556Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
557Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
558Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
559Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
560Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
561Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
562Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
563Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
564Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
565Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
566}
567
568[Test]
569public void StreamingChatCompletionUpdateWithFunctionCallUpdateWorks()
570{
2ab1a942Jose Arriaga Maldonado1 years ago571#pragma warning disable CS0618
79014abcShivangiReja1 years ago572StreamingChatFunctionCallUpdate functionCallUpdate = OpenAIChatModelFactory.StreamingChatFunctionCallUpdate(functionName: "get_recipte");
2ab1a942Jose Arriaga Maldonado1 years ago573#pragma warning restore CS0618
79014abcShivangiReja1 years ago574StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(functionCallUpdate: functionCallUpdate);
575
31c2ba63Jose Arriaga Maldonado1 years ago576Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
79014abcShivangiReja1 years ago577Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
2ab1a942Jose Arriaga Maldonado1 years ago578#pragma warning disable CS0618
79014abcShivangiReja1 years ago579Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.EqualTo(functionCallUpdate));
2ab1a942Jose Arriaga Maldonado1 years ago580#pragma warning restore CS0618
79014abcShivangiReja1 years ago581Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
582Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
583Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
584Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
585Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
586Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
587Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
588Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
589Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
590Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
591}
592
593[Test]
594public void StreamingChatCompletionUpdateWithToolCallUpdatesWorks()
595{
596IEnumerable<StreamingChatToolCallUpdate> toolCallUpdates = [
31c2ba63Jose Arriaga Maldonado1 years ago597OpenAIChatModelFactory.StreamingChatToolCallUpdate(toolCallId: "id1"),
598OpenAIChatModelFactory.StreamingChatToolCallUpdate(toolCallId: "id2")
79014abcShivangiReja1 years ago599];
600StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(toolCallUpdates: toolCallUpdates);
601
31c2ba63Jose Arriaga Maldonado1 years ago602Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
79014abcShivangiReja1 years ago603Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
2ab1a942Jose Arriaga Maldonado1 years ago604#pragma warning disable CS0618
79014abcShivangiReja1 years ago605Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago606#pragma warning restore CS0618
79014abcShivangiReja1 years ago607Assert.That(streamingChatCompletionUpdate.ToolCallUpdates.SequenceEqual(toolCallUpdates), Is.True);
608Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
609Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
610Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
611Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
612Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
613Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
614Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
615Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
616Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
617}
618
619[Test]
620public void StreamingChatCompletionUpdateWithRoleWorks()
621{
622ChatMessageRole role = ChatMessageRole.Tool;
623StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(role: role);
624
31c2ba63Jose Arriaga Maldonado1 years ago625Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
79014abcShivangiReja1 years ago626Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
2ab1a942Jose Arriaga Maldonado1 years ago627#pragma warning disable CS0618
79014abcShivangiReja1 years ago628Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago629#pragma warning restore CS0618
79014abcShivangiReja1 years ago630Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
631Assert.That(streamingChatCompletionUpdate.Role, Is.EqualTo(role));
632Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
633Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
634Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
635Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
636Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
637Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
638Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
639Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
640}
641
642[Test]
643public void StreamingChatCompletionUpdateWithRefusalUpdateWorks()
644{
645string refusalUpdate = "This is a refusal update.";
646StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(refusalUpdate: refusalUpdate);
647
31c2ba63Jose Arriaga Maldonado1 years ago648Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
79014abcShivangiReja1 years ago649Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
2ab1a942Jose Arriaga Maldonado1 years ago650#pragma warning disable CS0618
79014abcShivangiReja1 years ago651Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago652#pragma warning restore CS0618
79014abcShivangiReja1 years ago653Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
654Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
655Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.EqualTo(refusalUpdate));
656Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
657Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
658Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
659Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
660Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
661Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
662Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
663}
664
665[Test]
666public void StreamingChatCompletionUpdateWithContentTokenLogProbabilitiesWorks()
667{
2ab1a942Jose Arriaga Maldonado1 years ago668IEnumerable<ChatTokenLogProbabilityDetails> contentTokenLogProbabilities = [
669OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 1f),
670OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 2f)
79014abcShivangiReja1 years ago671];
672StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(contentTokenLogProbabilities: contentTokenLogProbabilities);
673
31c2ba63Jose Arriaga Maldonado1 years ago674Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
79014abcShivangiReja1 years ago675Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
2ab1a942Jose Arriaga Maldonado1 years ago676#pragma warning disable CS0618
79014abcShivangiReja1 years ago677Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago678#pragma warning restore CS0618
79014abcShivangiReja1 years ago679Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
680Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
681Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
682Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities.SequenceEqual(contentTokenLogProbabilities), Is.True);
683Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
684Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
685Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
686Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
687Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
688Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
689}
690
691[Test]
692public void StreamingChatCompletionUpdateWithRefusalTokenLogProbabilitiesWorks()
693{
2ab1a942Jose Arriaga Maldonado1 years ago694IEnumerable<ChatTokenLogProbabilityDetails> refusalTokenLogProbabilities = [
695OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 1f),
696OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 2f)
79014abcShivangiReja1 years ago697];
698StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(refusalTokenLogProbabilities: refusalTokenLogProbabilities);
699
31c2ba63Jose Arriaga Maldonado1 years ago700Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
79014abcShivangiReja1 years ago701Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
2ab1a942Jose Arriaga Maldonado1 years ago702#pragma warning disable CS0618
79014abcShivangiReja1 years ago703Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago704#pragma warning restore CS0618
79014abcShivangiReja1 years ago705Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
706Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
707Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
708Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
709Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities.SequenceEqual(refusalTokenLogProbabilities), Is.True);
710Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
711Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
712Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
713Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
714Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
715}
716
717[Test]
718public void StreamingChatCompletionUpdateWithFinishReasonWorks()
719{
720ChatFinishReason finishReason = ChatFinishReason.ToolCalls;
721StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(finishReason: finishReason);
722
31c2ba63Jose Arriaga Maldonado1 years ago723Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
79014abcShivangiReja1 years ago724Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
2ab1a942Jose Arriaga Maldonado1 years ago725#pragma warning disable CS0618
79014abcShivangiReja1 years ago726Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago727#pragma warning restore CS0618
79014abcShivangiReja1 years ago728Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
729Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
730Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
731Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
732Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
733Assert.That(streamingChatCompletionUpdate.FinishReason, Is.EqualTo(finishReason));
734Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
735Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
736Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
737Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
738}
739
740[Test]
741public void StreamingChatCompletionUpdateWithCreatedAtWorks()
742{
743DateTimeOffset createdAt = DateTimeOffset.UtcNow;
744StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(createdAt: createdAt);
745
31c2ba63Jose Arriaga Maldonado1 years ago746Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
79014abcShivangiReja1 years ago747Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
2ab1a942Jose Arriaga Maldonado1 years ago748#pragma warning disable CS0618
79014abcShivangiReja1 years ago749Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago750#pragma warning restore CS0618
79014abcShivangiReja1 years ago751Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
752Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
753Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
754Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
755Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
756Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
757Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(createdAt));
758Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
759Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
760Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
761}
762
763[Test]
764public void StreamingChatCompletionUpdateWithModelWorks()
765{
766string model = "topmodel";
767StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(model: model);
768
31c2ba63Jose Arriaga Maldonado1 years ago769Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
79014abcShivangiReja1 years ago770Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
2ab1a942Jose Arriaga Maldonado1 years ago771#pragma warning disable CS0618
79014abcShivangiReja1 years ago772Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago773#pragma warning restore CS0618
79014abcShivangiReja1 years ago774Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
775Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
776Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
777Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
778Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
779Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
780Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
781Assert.That(streamingChatCompletionUpdate.Model, Is.EqualTo(model));
782Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
783Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
784}
785
786[Test]
787public void StreamingChatCompletionUpdateWithSystemFingerprintWorks()
788{
789string systemFingerprint = "footprint";
790StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(systemFingerprint: systemFingerprint);
791
31c2ba63Jose Arriaga Maldonado1 years ago792Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
79014abcShivangiReja1 years ago793Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
2ab1a942Jose Arriaga Maldonado1 years ago794#pragma warning disable CS0618
79014abcShivangiReja1 years ago795Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago796#pragma warning restore CS0618
79014abcShivangiReja1 years ago797Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
798Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
799Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
800Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
801Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
802Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
803Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
804Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
805Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.EqualTo(systemFingerprint));
806Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
807}
808
809[Test]
810public void StreamingChatCompletionUpdateWithUsageWorks()
811{
75eded51ShivangiReja1 years ago812ChatTokenUsage usage = OpenAIChatModelFactory.ChatTokenUsage(outputTokenCount: 20);
79014abcShivangiReja1 years ago813StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(usage: usage);
814
31c2ba63Jose Arriaga Maldonado1 years ago815Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
79014abcShivangiReja1 years ago816Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
2ab1a942Jose Arriaga Maldonado1 years ago817#pragma warning disable CS0618
79014abcShivangiReja1 years ago818Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
2ab1a942Jose Arriaga Maldonado1 years ago819#pragma warning restore CS0618
79014abcShivangiReja1 years ago820Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
821Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
822Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
823Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
824Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
825Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
826Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
827Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
828Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
829Assert.That(streamingChatCompletionUpdate.Usage, Is.EqualTo(usage));
830}
831
832[Test]
833public void StreamingChatFunctionCallUpdateWithNoPropertiesWorks()
834{
2ab1a942Jose Arriaga Maldonado1 years ago835#pragma warning disable CS0618
79014abcShivangiReja1 years ago836StreamingChatFunctionCallUpdate streamingChatFunctionCallUpdate = OpenAIChatModelFactory.StreamingChatFunctionCallUpdate();
2ab1a942Jose Arriaga Maldonado1 years ago837#pragma warning restore CS0618
79014abcShivangiReja1 years ago838
839Assert.That(streamingChatFunctionCallUpdate.FunctionName, Is.Null);
840Assert.That(streamingChatFunctionCallUpdate.FunctionArgumentsUpdate, Is.Null);
841}
842
843[Test]
844public void StreamingChatFunctionCallUpdateWithFunctionNameWorks()
845{
846string functionName = "Margaret";
2ab1a942Jose Arriaga Maldonado1 years ago847#pragma warning disable CS0618
79014abcShivangiReja1 years ago848StreamingChatFunctionCallUpdate streamingChatFunctionCallUpdate = OpenAIChatModelFactory.StreamingChatFunctionCallUpdate(functionName: functionName);
2ab1a942Jose Arriaga Maldonado1 years ago849#pragma warning restore CS0618
79014abcShivangiReja1 years ago850
851Assert.That(streamingChatFunctionCallUpdate.FunctionName, Is.EqualTo(functionName));
852Assert.That(streamingChatFunctionCallUpdate.FunctionArgumentsUpdate, Is.Null);
853}
854
855[Test]
856public void StreamingChatFunctionCallUpdateWithFunctionArgumentsUpdateWorks()
857{
31c2ba63Jose Arriaga Maldonado1 years ago858BinaryData functionArgumentsUpdate = BinaryData.FromBytes("arguments_update"u8.ToArray());
2ab1a942Jose Arriaga Maldonado1 years ago859#pragma warning disable CS0618
79014abcShivangiReja1 years ago860StreamingChatFunctionCallUpdate streamingChatFunctionCallUpdate = OpenAIChatModelFactory.StreamingChatFunctionCallUpdate(functionArgumentsUpdate: functionArgumentsUpdate);
2ab1a942Jose Arriaga Maldonado1 years ago861#pragma warning restore CS0618
79014abcShivangiReja1 years ago862
863Assert.That(streamingChatFunctionCallUpdate.FunctionName, Is.Null);
864Assert.That(streamingChatFunctionCallUpdate.FunctionArgumentsUpdate, Is.EqualTo(functionArgumentsUpdate));
865}
866
867[Test]
868public void StreamingChatToolCallUpdateWithNoPropertiesWorks()
869{
870StreamingChatToolCallUpdate streamingChatToolCallUpdate = OpenAIChatModelFactory.StreamingChatToolCallUpdate();
871
872Assert.That(streamingChatToolCallUpdate.Index, Is.EqualTo(0));
31c2ba63Jose Arriaga Maldonado1 years ago873Assert.That(streamingChatToolCallUpdate.ToolCallId, Is.Null);
79014abcShivangiReja1 years ago874Assert.That(streamingChatToolCallUpdate.Kind, Is.EqualTo(default(ChatToolCallKind)));
875Assert.That(streamingChatToolCallUpdate.FunctionName, Is.Null);
876Assert.That(streamingChatToolCallUpdate.FunctionArgumentsUpdate, Is.Null);
877}
878
879[Test]
880public void StreamingChatToolCallUpdateWithIndexWorks()
881{
882int index = 31415;
883StreamingChatToolCallUpdate streamingChatToolCallUpdate = OpenAIChatModelFactory.StreamingChatToolCallUpdate(index: index);
884
885Assert.That(streamingChatToolCallUpdate.Index, Is.EqualTo(index));
31c2ba63Jose Arriaga Maldonado1 years ago886Assert.That(streamingChatToolCallUpdate.ToolCallId, Is.Null);
79014abcShivangiReja1 years ago887Assert.That(streamingChatToolCallUpdate.Kind, Is.EqualTo(default(ChatToolCallKind)));
888Assert.That(streamingChatToolCallUpdate.FunctionName, Is.Null);
889Assert.That(streamingChatToolCallUpdate.FunctionArgumentsUpdate, Is.Null);
890}
891
892[Test]
893public void StreamingChatToolCallUpdateWithIdWorks()
894{
895string id = "tool_call_id";
31c2ba63Jose Arriaga Maldonado1 years ago896StreamingChatToolCallUpdate streamingChatToolCallUpdate = OpenAIChatModelFactory.StreamingChatToolCallUpdate(toolCallId: id);
79014abcShivangiReja1 years ago897
898Assert.That(streamingChatToolCallUpdate.Index, Is.EqualTo(0));
31c2ba63Jose Arriaga Maldonado1 years ago899Assert.That(streamingChatToolCallUpdate.ToolCallId, Is.EqualTo(id));
79014abcShivangiReja1 years ago900Assert.That(streamingChatToolCallUpdate.Kind, Is.EqualTo(default(ChatToolCallKind)));
901Assert.That(streamingChatToolCallUpdate.FunctionName, Is.Null);
902Assert.That(streamingChatToolCallUpdate.FunctionArgumentsUpdate, Is.Null);
903}
904
905[Test]
906public void StreamingChatToolCallUpdateWithKindWorks()
907{
908ChatToolCallKind kind = ChatToolCallKind.Function;
909StreamingChatToolCallUpdate streamingChatToolCallUpdate = OpenAIChatModelFactory.StreamingChatToolCallUpdate(kind: kind);
910
911Assert.That(streamingChatToolCallUpdate.Index, Is.EqualTo(0));
31c2ba63Jose Arriaga Maldonado1 years ago912Assert.That(streamingChatToolCallUpdate.ToolCallId, Is.Null);
79014abcShivangiReja1 years ago913Assert.That(streamingChatToolCallUpdate.Kind, Is.EqualTo(kind));
914Assert.That(streamingChatToolCallUpdate.FunctionName, Is.Null);
915Assert.That(streamingChatToolCallUpdate.FunctionArgumentsUpdate, Is.Null);
916}
917
918[Test]
919public void StreamingChatToolCallUpdateWithFunctionNameWorks()
920{
921string functionName = "Margaret";
922StreamingChatToolCallUpdate streamingChatToolCallUpdate = OpenAIChatModelFactory.StreamingChatToolCallUpdate(functionName: functionName);
923
924Assert.That(streamingChatToolCallUpdate.Index, Is.EqualTo(0));
31c2ba63Jose Arriaga Maldonado1 years ago925Assert.That(streamingChatToolCallUpdate.ToolCallId, Is.Null);
79014abcShivangiReja1 years ago926Assert.That(streamingChatToolCallUpdate.Kind, Is.EqualTo(default(ChatToolCallKind)));
927Assert.That(streamingChatToolCallUpdate.FunctionName, Is.EqualTo(functionName));
928Assert.That(streamingChatToolCallUpdate.FunctionArgumentsUpdate, Is.Null);
929}
930
931[Test]
932public void StreamingChatToolCallUpdateWithFunctionArgumentsUpdateWorks()
933{
31c2ba63Jose Arriaga Maldonado1 years ago934BinaryData functionArgumentsUpdate = BinaryData.FromBytes("arguments_update"u8.ToArray());
79014abcShivangiReja1 years ago935StreamingChatToolCallUpdate streamingChatToolCallUpdate = OpenAIChatModelFactory.StreamingChatToolCallUpdate(functionArgumentsUpdate: functionArgumentsUpdate);
936
937Assert.That(streamingChatToolCallUpdate.Index, Is.EqualTo(0));
31c2ba63Jose Arriaga Maldonado1 years ago938Assert.That(streamingChatToolCallUpdate.ToolCallId, Is.Null);
79014abcShivangiReja1 years ago939Assert.That(streamingChatToolCallUpdate.Kind, Is.EqualTo(default(ChatToolCallKind)));
940Assert.That(streamingChatToolCallUpdate.FunctionName, Is.Null);
941Assert.That(streamingChatToolCallUpdate.FunctionArgumentsUpdate, Is.EqualTo(functionArgumentsUpdate));
942}
943}