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 · modecode

1using System;
2using System.Collections.Generic;
3using System.Linq;
4using NUnit.Framework;
5using OpenAI.Chat;
6
7namespace OpenAI.Tests.Chat;
8
9[Parallelizable(ParallelScope.All)]
10[Category("Chat")]
11[Category("Smoke")]
12public partial class OpenAIChatModelFactoryTests
13{
14 [Test]
15 public void ChatCompletionWithNoPropertiesWorks()
16 {
17 ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion();
18
19 Assert.That(chatCompletion.Id, Is.Null);
20 Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
21 Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
22 Assert.That(chatCompletion.Refusal, Is.Null);
23 Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
24 Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
25#pragma warning disable CS0618
26 Assert.That(chatCompletion.FunctionCall, Is.Null);
27#pragma warning restore CS0618
28 Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
29 Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
30 Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
31 Assert.That(chatCompletion.Model, Is.Null);
32 Assert.That(chatCompletion.SystemFingerprint, Is.Null);
33 Assert.That(chatCompletion.Usage, Is.Null);
34 }
35
36 [Test]
37 public void ChatCompletionWithIdWorks()
38 {
39 string id = "chat_completion_id";
40 ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(id: id);
41
42 Assert.That(chatCompletion.Id, Is.EqualTo(id));
43 Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
44 Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
45 Assert.That(chatCompletion.Refusal, Is.Null);
46 Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
47 Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
48#pragma warning disable CS0618
49 Assert.That(chatCompletion.FunctionCall, Is.Null);
50#pragma warning restore CS0618
51 Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
52 Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
53 Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
54 Assert.That(chatCompletion.Model, Is.Null);
55 Assert.That(chatCompletion.SystemFingerprint, Is.Null);
56 Assert.That(chatCompletion.Usage, Is.Null);
57 }
58
59 [Test]
60 public void ChatCompletionWithFinishReasonWorks()
61 {
62 ChatFinishReason finishReason = ChatFinishReason.ToolCalls;
63 ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(finishReason: finishReason);
64
65 Assert.That(chatCompletion.Id, Is.Null);
66 Assert.That(chatCompletion.FinishReason, Is.EqualTo(finishReason));
67 Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
68 Assert.That(chatCompletion.Refusal, Is.Null);
69 Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
70 Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
71#pragma warning disable CS0618
72 Assert.That(chatCompletion.FunctionCall, Is.Null);
73#pragma warning restore CS0618
74 Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
75 Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
76 Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
77 Assert.That(chatCompletion.Model, Is.Null);
78 Assert.That(chatCompletion.SystemFingerprint, Is.Null);
79 Assert.That(chatCompletion.Usage, Is.Null);
80 }
81
82 [Test]
83 public void ChatCompletionWithContentWorks()
84 {
85 ChatMessageContent content = [
86 ChatMessageContentPart.CreateTextPart("first part"),
87 ChatMessageContentPart.CreateTextPart("second part")
88 ];
89 ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(content: content);
90
91 Assert.That(chatCompletion.Id, Is.Null);
92 Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
93 Assert.That(chatCompletion.Content.SequenceEqual(content), Is.True);
94 Assert.That(chatCompletion.Refusal, Is.Null);
95 Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
96 Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
97#pragma warning disable CS0618
98 Assert.That(chatCompletion.FunctionCall, Is.Null);
99#pragma warning restore CS0618
100 Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
101 Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
102 Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
103 Assert.That(chatCompletion.Model, Is.Null);
104 Assert.That(chatCompletion.SystemFingerprint, Is.Null);
105 Assert.That(chatCompletion.Usage, Is.Null);
106 }
107
108 [Test]
109 public void ChatCompletionWithRefusalWorks()
110 {
111 string refusal = "This is a refusal.";
112 ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(refusal: refusal);
113
114 Assert.That(chatCompletion.Id, Is.Null);
115 Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
116 Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
117 Assert.That(chatCompletion.Refusal, Is.EqualTo(refusal));
118 Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
119 Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
120#pragma warning disable CS0618
121 Assert.That(chatCompletion.FunctionCall, Is.Null);
122#pragma warning restore CS0618
123 Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
124 Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
125 Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
126 Assert.That(chatCompletion.Model, Is.Null);
127 Assert.That(chatCompletion.SystemFingerprint, Is.Null);
128 Assert.That(chatCompletion.Usage, Is.Null);
129 }
130
131 [Test]
132 public void ChatCompletionWithToolCallsWorks()
133 {
134 IEnumerable<ChatToolCall> toolCalls = [
135 ChatToolCall.CreateFunctionToolCall("id1", "get_recipe", BinaryData.FromBytes("{}"u8.ToArray())),
136 ChatToolCall.CreateFunctionToolCall("id2", "get_location", BinaryData.FromBytes("{}"u8.ToArray()))
137 ];
138 ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(toolCalls: toolCalls);
139
140 Assert.That(chatCompletion.Id, Is.Null);
141 Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
142 Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
143 Assert.That(chatCompletion.Refusal, Is.Null);
144 Assert.That(chatCompletion.ToolCalls.SequenceEqual(toolCalls), Is.True);
145 Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
146#pragma warning disable CS0618
147 Assert.That(chatCompletion.FunctionCall, Is.Null);
148#pragma warning restore CS0618
149 Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
150 Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
151 Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
152 Assert.That(chatCompletion.Model, Is.Null);
153 Assert.That(chatCompletion.SystemFingerprint, Is.Null);
154 Assert.That(chatCompletion.Usage, Is.Null);
155 }
156
157 [Test]
158 public void ChatCompletionWithRoleWorks()
159 {
160 ChatMessageRole role = ChatMessageRole.Tool;
161 ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(role: role);
162
163 Assert.That(chatCompletion.Id, Is.Null);
164 Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
165 Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
166 Assert.That(chatCompletion.Refusal, Is.Null);
167 Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
168 Assert.That(chatCompletion.Role, Is.EqualTo(role));
169#pragma warning disable CS0618
170 Assert.That(chatCompletion.FunctionCall, Is.Null);
171#pragma warning restore CS0618
172 Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
173 Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
174 Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
175 Assert.That(chatCompletion.Model, Is.Null);
176 Assert.That(chatCompletion.SystemFingerprint, Is.Null);
177 Assert.That(chatCompletion.Usage, Is.Null);
178 }
179
180 [Test]
181 public void ChatCompletionWithFunctionCallWorks()
182 {
183#pragma warning disable CS0618
184 ChatFunctionCall functionCall = new ChatFunctionCall("get_recipe", BinaryData.FromBytes("{}"u8.ToArray()));
185#pragma warning restore CS0618
186 ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(functionCall: functionCall);
187
188 Assert.That(chatCompletion.Id, Is.Null);
189 Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
190 Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
191 Assert.That(chatCompletion.Refusal, Is.Null);
192 Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
193 Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
194#pragma warning disable CS0618
195 Assert.That(chatCompletion.FunctionCall, Is.EqualTo(functionCall));
196#pragma warning restore CS0618
197 Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
198 Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
199 Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
200 Assert.That(chatCompletion.Model, Is.Null);
201 Assert.That(chatCompletion.SystemFingerprint, Is.Null);
202 Assert.That(chatCompletion.Usage, Is.Null);
203 }
204
205 [Test]
206 public void ChatCompletionWithContentTokenLogProbabilitiesWorks()
207 {
208 IEnumerable<ChatTokenLogProbabilityDetails> contentTokenLogProbabilities = [
209 OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 1f),
210 OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 2f)
211 ];
212 ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(contentTokenLogProbabilities: contentTokenLogProbabilities);
213
214 Assert.That(chatCompletion.Id, Is.Null);
215 Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
216 Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
217 Assert.That(chatCompletion.Refusal, Is.Null);
218 Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
219 Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
220#pragma warning disable CS0618
221 Assert.That(chatCompletion.FunctionCall, Is.Null);
222#pragma warning restore CS0618
223 Assert.That(chatCompletion.ContentTokenLogProbabilities.SequenceEqual(contentTokenLogProbabilities), Is.True);
224 Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
225 Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
226 Assert.That(chatCompletion.Model, Is.Null);
227 Assert.That(chatCompletion.SystemFingerprint, Is.Null);
228 Assert.That(chatCompletion.Usage, Is.Null);
229 }
230
231 [Test]
232 public void ChatCompletionWithRefusalTokenLogProbabilitiesWorks()
233 {
234 IEnumerable<ChatTokenLogProbabilityDetails> refusalTokenLogProbabilities = [
235 OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 1f),
236 OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 2f)
237 ];
238 ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(refusalTokenLogProbabilities: refusalTokenLogProbabilities);
239
240 Assert.That(chatCompletion.Id, Is.Null);
241 Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
242 Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
243 Assert.That(chatCompletion.Refusal, Is.Null);
244 Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
245 Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
246#pragma warning disable CS0618
247 Assert.That(chatCompletion.FunctionCall, Is.Null);
248#pragma warning restore CS0618
249 Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
250 Assert.That(chatCompletion.RefusalTokenLogProbabilities.SequenceEqual(refusalTokenLogProbabilities), Is.True);
251 Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
252 Assert.That(chatCompletion.Model, Is.Null);
253 Assert.That(chatCompletion.SystemFingerprint, Is.Null);
254 Assert.That(chatCompletion.Usage, Is.Null);
255 }
256
257 [Test]
258 public void ChatCompletionWithCreatedAtWorks()
259 {
260 DateTimeOffset createdAt = DateTimeOffset.UtcNow;
261 ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(createdAt: createdAt);
262
263 Assert.That(chatCompletion.Id, Is.Null);
264 Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
265 Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
266 Assert.That(chatCompletion.Refusal, Is.Null);
267 Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
268 Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
269#pragma warning disable CS0618
270 Assert.That(chatCompletion.FunctionCall, Is.Null);
271#pragma warning restore CS0618
272 Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
273 Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
274 Assert.That(chatCompletion.CreatedAt, Is.EqualTo(createdAt));
275 Assert.That(chatCompletion.Model, Is.Null);
276 Assert.That(chatCompletion.SystemFingerprint, Is.Null);
277 Assert.That(chatCompletion.Usage, Is.Null);
278 }
279
280 [Test]
281 public void ChatCompletionWithModelWorks()
282 {
283 string model = "topmodel";
284 ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(model: model);
285
286 Assert.That(chatCompletion.Id, Is.Null);
287 Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
288 Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
289 Assert.That(chatCompletion.Refusal, Is.Null);
290 Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
291 Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
292#pragma warning disable CS0618
293 Assert.That(chatCompletion.FunctionCall, Is.Null);
294#pragma warning restore CS0618
295 Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
296 Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
297 Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
298 Assert.That(chatCompletion.Model, Is.EqualTo(model));
299 Assert.That(chatCompletion.SystemFingerprint, Is.Null);
300 Assert.That(chatCompletion.Usage, Is.Null);
301 }
302
303 [Test]
304 public void ChatCompletionWithSystemFingerprintWorks()
305 {
306 string systemFingerprint = "footprint";
307 ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(systemFingerprint: systemFingerprint);
308
309 Assert.That(chatCompletion.Id, Is.Null);
310 Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
311 Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
312 Assert.That(chatCompletion.Refusal, Is.Null);
313 Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
314 Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
315#pragma warning disable CS0618
316 Assert.That(chatCompletion.FunctionCall, Is.Null);
317#pragma warning restore CS0618
318 Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
319 Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
320 Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
321 Assert.That(chatCompletion.Model, Is.Null);
322 Assert.That(chatCompletion.SystemFingerprint, Is.EqualTo(systemFingerprint));
323 Assert.That(chatCompletion.Usage, Is.Null);
324 }
325
326 [Test]
327 public void ChatCompletionWithUsageWorks()
328 {
329 ChatTokenUsage usage = OpenAIChatModelFactory.ChatTokenUsage(outputTokenCount: 20);
330 ChatCompletion chatCompletion = OpenAIChatModelFactory.ChatCompletion(usage: usage);
331
332 Assert.That(chatCompletion.Id, Is.Null);
333 Assert.That(chatCompletion.FinishReason, Is.EqualTo(default(ChatFinishReason)));
334 Assert.That(chatCompletion.Content, Is.Not.Null.And.Empty);
335 Assert.That(chatCompletion.Refusal, Is.Null);
336 Assert.That(chatCompletion.ToolCalls, Is.Not.Null.And.Empty);
337 Assert.That(chatCompletion.Role, Is.EqualTo(default(ChatMessageRole)));
338#pragma warning disable CS0618
339 Assert.That(chatCompletion.FunctionCall, Is.Null);
340#pragma warning restore CS0618
341 Assert.That(chatCompletion.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
342 Assert.That(chatCompletion.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
343 Assert.That(chatCompletion.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
344 Assert.That(chatCompletion.Model, Is.Null);
345 Assert.That(chatCompletion.SystemFingerprint, Is.Null);
346 Assert.That(chatCompletion.Usage, Is.EqualTo(usage));
347 }
348
349 [Test]
350 public void ChatTokenLogProbabilityDetailsWithNoPropertiesWorks()
351 {
352 ChatTokenLogProbabilityDetails chatTokenLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenLogProbabilityDetails();
353
354 Assert.That(chatTokenLogProbabilityDetails.Token, Is.Null);
355 Assert.That(chatTokenLogProbabilityDetails.LogProbability, Is.EqualTo(0f));
356 Assert.That(chatTokenLogProbabilityDetails.Utf8Bytes, Is.Null);
357 Assert.That(chatTokenLogProbabilityDetails.TopLogProbabilities, Is.Not.Null.And.Empty);
358 }
359
360 [Test]
361 public void ChatTokenLogProbabilityDetailsWithTokenWorks()
362 {
363 string token = "a_token_of_appreciation";
364 ChatTokenLogProbabilityDetails chatTokenLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(token: token);
365
366 Assert.That(chatTokenLogProbabilityDetails.Token, Is.EqualTo(token));
367 Assert.That(chatTokenLogProbabilityDetails.LogProbability, Is.EqualTo(0f));
368 Assert.That(chatTokenLogProbabilityDetails.Utf8Bytes, Is.Null);
369 Assert.That(chatTokenLogProbabilityDetails.TopLogProbabilities, Is.Not.Null.And.Empty);
370 }
371
372 [Test]
373 public void ChatTokenLogProbabilityDetailsWithLogProbabilityWorks()
374 {
375 float logProbability = 3.14f;
376 ChatTokenLogProbabilityDetails chatTokenLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: logProbability);
377
378 Assert.That(chatTokenLogProbabilityDetails.Token, Is.Null);
379 Assert.That(chatTokenLogProbabilityDetails.LogProbability, Is.EqualTo(logProbability));
380 Assert.That(chatTokenLogProbabilityDetails.Utf8Bytes, Is.Null);
381 Assert.That(chatTokenLogProbabilityDetails.TopLogProbabilities, Is.Not.Null.And.Empty);
382 }
383
384 [Test]
385 public void ChatTokenLogProbabilityDetailsWithUtf8ByteValuesWorks()
386 {
387 ReadOnlyMemory<byte> utf8Bytes = "hello"u8.ToArray();
388 ChatTokenLogProbabilityDetails chatTokenLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(utf8Bytes: utf8Bytes);
389
390 Assert.That(chatTokenLogProbabilityDetails.Token, Is.Null);
391 Assert.That(chatTokenLogProbabilityDetails.LogProbability, Is.EqualTo(0f));
392 Assert.That(chatTokenLogProbabilityDetails.Utf8Bytes.Value.ToArray().SequenceEqual(utf8Bytes.ToArray()), Is.True);
393 Assert.That(chatTokenLogProbabilityDetails.TopLogProbabilities, Is.Not.Null.And.Empty);
394 }
395
396 [Test]
397 public void ChatTokenLogProbabilityDetailsWithTopLogProbabilitiesWorks()
398 {
399 IEnumerable<ChatTokenTopLogProbabilityDetails> topLogProbabilities = [
400 OpenAIChatModelFactory.ChatTokenTopLogProbabilityDetails(token: "firstToken"),
401 OpenAIChatModelFactory.ChatTokenTopLogProbabilityDetails(token: "secondToken")
402 ];
403 ChatTokenLogProbabilityDetails chatTokenLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(topLogProbabilities: topLogProbabilities);
404
405 Assert.That(chatTokenLogProbabilityDetails.Token, Is.Null);
406 Assert.That(chatTokenLogProbabilityDetails.LogProbability, Is.EqualTo(0f));
407 Assert.That(chatTokenLogProbabilityDetails.Utf8Bytes, Is.Null);
408 Assert.That(chatTokenLogProbabilityDetails.TopLogProbabilities.SequenceEqual(topLogProbabilities), Is.True);
409 }
410
411 [Test]
412 public void ChatTokenTopLogProbabilityDetailsWithNoPropertiesWorks()
413 {
414 ChatTokenTopLogProbabilityDetails chatTokenTopLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenTopLogProbabilityDetails();
415
416 Assert.That(chatTokenTopLogProbabilityDetails.Token, Is.Null);
417 Assert.That(chatTokenTopLogProbabilityDetails.LogProbability, Is.EqualTo(0f));
418 Assert.That(chatTokenTopLogProbabilityDetails.Utf8Bytes, Is.Null);
419 }
420
421 [Test]
422 public void ChatTokenTopLogProbabilityDetailsWithTokenWorks()
423 {
424 string token = "a_token_of_appreciation";
425 ChatTokenTopLogProbabilityDetails chatTokenTopLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenTopLogProbabilityDetails(token: token);
426
427 Assert.That(chatTokenTopLogProbabilityDetails.Token, Is.EqualTo(token));
428 Assert.That(chatTokenTopLogProbabilityDetails.LogProbability, Is.EqualTo(0f));
429 Assert.That(chatTokenTopLogProbabilityDetails.Utf8Bytes, Is.Null);
430 }
431
432 [Test]
433 public void ChatTokenTopLogProbabilityDetailsWithLogProbabilityWorks()
434 {
435 float logProbability = 3.14f;
436 ChatTokenTopLogProbabilityDetails chatTokenTopLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenTopLogProbabilityDetails(logProbability: logProbability);
437
438 Assert.That(chatTokenTopLogProbabilityDetails.Token, Is.Null);
439 Assert.That(chatTokenTopLogProbabilityDetails.LogProbability, Is.EqualTo(logProbability));
440 Assert.That(chatTokenTopLogProbabilityDetails.Utf8Bytes, Is.Null);
441 }
442
443 [Test]
444 public void ChatTokenTopLogProbabilityDetailsWithUtf8ByteValuesWorks()
445 {
446 ReadOnlyMemory<byte> utf8Bytes = "hello"u8.ToArray();
447 ChatTokenTopLogProbabilityDetails chatTokenTopLogProbabilityDetails = OpenAIChatModelFactory.ChatTokenTopLogProbabilityDetails(utf8Bytes: utf8Bytes);
448
449 Assert.That(chatTokenTopLogProbabilityDetails.Token, Is.Null);
450 Assert.That(chatTokenTopLogProbabilityDetails.LogProbability, Is.EqualTo(0f));
451 Assert.That(chatTokenTopLogProbabilityDetails.Utf8Bytes.Value.ToArray().SequenceEqual(utf8Bytes.ToArray()), Is.True);
452 }
453
454 [Test]
455 public void ChatTokenUsageWithNoPropertiesWorks()
456 {
457 ChatTokenUsage chatTokenUsage = OpenAIChatModelFactory.ChatTokenUsage();
458
459 Assert.That(chatTokenUsage.OutputTokenCount, Is.EqualTo(0));
460 Assert.That(chatTokenUsage.InputTokenCount, Is.EqualTo(0));
461 Assert.That(chatTokenUsage.TotalTokenCount, Is.EqualTo(0));
462 }
463
464 [Test]
465 public void ChatTokenUsageWithOutputTokensWorks()
466 {
467 int outputTokens = 271828;
468 ChatTokenUsage chatTokenUsage = OpenAIChatModelFactory.ChatTokenUsage(outputTokenCount: outputTokens);
469
470 Assert.That(chatTokenUsage.OutputTokenCount, Is.EqualTo(outputTokens));
471 Assert.That(chatTokenUsage.InputTokenCount, Is.EqualTo(0));
472 Assert.That(chatTokenUsage.TotalTokenCount, Is.EqualTo(0));
473 }
474
475 [Test]
476 public void ChatTokenUsageWithInputTokensWorks()
477 {
478 int inputTokens = 271828;
479 ChatTokenUsage chatTokenUsage = OpenAIChatModelFactory.ChatTokenUsage(inputTokenCount: inputTokens);
480
481 Assert.That(chatTokenUsage.OutputTokenCount, Is.EqualTo(0));
482 Assert.That(chatTokenUsage.InputTokenCount, Is.EqualTo(inputTokens));
483 Assert.That(chatTokenUsage.TotalTokenCount, Is.EqualTo(0));
484 }
485
486 [Test]
487 public void ChatTokenUsageWithTotalTokensWorks()
488 {
489 int totalTokens = 271828;
490 ChatTokenUsage chatTokenUsage = OpenAIChatModelFactory.ChatTokenUsage(totalTokenCount: totalTokens);
491
492 Assert.That(chatTokenUsage.OutputTokenCount, Is.EqualTo(0));
493 Assert.That(chatTokenUsage.InputTokenCount, Is.EqualTo(0));
494 Assert.That(chatTokenUsage.TotalTokenCount, Is.EqualTo(totalTokens));
495 }
496
497 [Test]
498 public void StreamingChatCompletionUpdateWithNoPropertiesWorks()
499 {
500 StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate();
501
502 Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
503 Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
504#pragma warning disable CS0618
505 Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
506#pragma warning restore CS0618
507 Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
508 Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
509 Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
510 Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
511 Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
512 Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
513 Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
514 Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
515 Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
516 Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
517 }
518
519 [Test]
520 public void StreamingChatCompletionUpdateWithIdWorks()
521 {
522 string id = "chat_completion_id";
523 StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(completionId: id);
524
525 Assert.That(streamingChatCompletionUpdate.CompletionId, Is.EqualTo(id));
526 Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
527#pragma warning disable CS0618
528 Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
529#pragma warning restore CS0618
530 Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
531 Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
532 Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
533 Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
534 Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
535 Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
536 Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
537 Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
538 Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
539 Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
540 }
541
542 [Test]
543 public void StreamingChatCompletionUpdateWithContentUpdateWorks()
544 {
545 ChatMessageContent contentUpdate = [
546 ChatMessageContentPart.CreateTextPart("first part"),
547 ChatMessageContentPart.CreateTextPart("second part")
548 ];
549 StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(contentUpdate: contentUpdate);
550
551 Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
552 Assert.That(streamingChatCompletionUpdate.ContentUpdate.SequenceEqual(contentUpdate), Is.True);
553#pragma warning disable CS0618
554 Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
555#pragma warning restore CS0618
556 Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
557 Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
558 Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
559 Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
560 Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
561 Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
562 Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
563 Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
564 Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
565 Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
566 }
567
568 [Test]
569 public void StreamingChatCompletionUpdateWithFunctionCallUpdateWorks()
570 {
571#pragma warning disable CS0618
572 StreamingChatFunctionCallUpdate functionCallUpdate = OpenAIChatModelFactory.StreamingChatFunctionCallUpdate(functionName: "get_recipte");
573#pragma warning restore CS0618
574 StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(functionCallUpdate: functionCallUpdate);
575
576 Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
577 Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
578#pragma warning disable CS0618
579 Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.EqualTo(functionCallUpdate));
580#pragma warning restore CS0618
581 Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
582 Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
583 Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
584 Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
585 Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
586 Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
587 Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
588 Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
589 Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
590 Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
591 }
592
593 [Test]
594 public void StreamingChatCompletionUpdateWithToolCallUpdatesWorks()
595 {
596 IEnumerable<StreamingChatToolCallUpdate> toolCallUpdates = [
597 OpenAIChatModelFactory.StreamingChatToolCallUpdate(toolCallId: "id1"),
598 OpenAIChatModelFactory.StreamingChatToolCallUpdate(toolCallId: "id2")
599 ];
600 StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(toolCallUpdates: toolCallUpdates);
601
602 Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
603 Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
604#pragma warning disable CS0618
605 Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
606#pragma warning restore CS0618
607 Assert.That(streamingChatCompletionUpdate.ToolCallUpdates.SequenceEqual(toolCallUpdates), Is.True);
608 Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
609 Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
610 Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
611 Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
612 Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
613 Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
614 Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
615 Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
616 Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
617 }
618
619 [Test]
620 public void StreamingChatCompletionUpdateWithRoleWorks()
621 {
622 ChatMessageRole role = ChatMessageRole.Tool;
623 StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(role: role);
624
625 Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
626 Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
627#pragma warning disable CS0618
628 Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
629#pragma warning restore CS0618
630 Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
631 Assert.That(streamingChatCompletionUpdate.Role, Is.EqualTo(role));
632 Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
633 Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
634 Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
635 Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
636 Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
637 Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
638 Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
639 Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
640 }
641
642 [Test]
643 public void StreamingChatCompletionUpdateWithRefusalUpdateWorks()
644 {
645 string refusalUpdate = "This is a refusal update.";
646 StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(refusalUpdate: refusalUpdate);
647
648 Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
649 Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
650#pragma warning disable CS0618
651 Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
652#pragma warning restore CS0618
653 Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
654 Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
655 Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.EqualTo(refusalUpdate));
656 Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
657 Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
658 Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
659 Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
660 Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
661 Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
662 Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
663 }
664
665 [Test]
666 public void StreamingChatCompletionUpdateWithContentTokenLogProbabilitiesWorks()
667 {
668 IEnumerable<ChatTokenLogProbabilityDetails> contentTokenLogProbabilities = [
669 OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 1f),
670 OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 2f)
671 ];
672 StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(contentTokenLogProbabilities: contentTokenLogProbabilities);
673
674 Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
675 Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
676#pragma warning disable CS0618
677 Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
678#pragma warning restore CS0618
679 Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
680 Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
681 Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
682 Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities.SequenceEqual(contentTokenLogProbabilities), Is.True);
683 Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
684 Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
685 Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
686 Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
687 Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
688 Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
689 }
690
691 [Test]
692 public void StreamingChatCompletionUpdateWithRefusalTokenLogProbabilitiesWorks()
693 {
694 IEnumerable<ChatTokenLogProbabilityDetails> refusalTokenLogProbabilities = [
695 OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 1f),
696 OpenAIChatModelFactory.ChatTokenLogProbabilityDetails(logProbability: 2f)
697 ];
698 StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(refusalTokenLogProbabilities: refusalTokenLogProbabilities);
699
700 Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
701 Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
702#pragma warning disable CS0618
703 Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
704#pragma warning restore CS0618
705 Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
706 Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
707 Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
708 Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
709 Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities.SequenceEqual(refusalTokenLogProbabilities), Is.True);
710 Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
711 Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
712 Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
713 Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
714 Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
715 }
716
717 [Test]
718 public void StreamingChatCompletionUpdateWithFinishReasonWorks()
719 {
720 ChatFinishReason finishReason = ChatFinishReason.ToolCalls;
721 StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(finishReason: finishReason);
722
723 Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
724 Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
725#pragma warning disable CS0618
726 Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
727#pragma warning restore CS0618
728 Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
729 Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
730 Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
731 Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
732 Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
733 Assert.That(streamingChatCompletionUpdate.FinishReason, Is.EqualTo(finishReason));
734 Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
735 Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
736 Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
737 Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
738 }
739
740 [Test]
741 public void StreamingChatCompletionUpdateWithCreatedAtWorks()
742 {
743 DateTimeOffset createdAt = DateTimeOffset.UtcNow;
744 StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(createdAt: createdAt);
745
746 Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
747 Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
748#pragma warning disable CS0618
749 Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
750#pragma warning restore CS0618
751 Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
752 Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
753 Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
754 Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
755 Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
756 Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
757 Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(createdAt));
758 Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
759 Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
760 Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
761 }
762
763 [Test]
764 public void StreamingChatCompletionUpdateWithModelWorks()
765 {
766 string model = "topmodel";
767 StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(model: model);
768
769 Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
770 Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
771#pragma warning disable CS0618
772 Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
773#pragma warning restore CS0618
774 Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
775 Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
776 Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
777 Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
778 Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
779 Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
780 Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
781 Assert.That(streamingChatCompletionUpdate.Model, Is.EqualTo(model));
782 Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
783 Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
784 }
785
786 [Test]
787 public void StreamingChatCompletionUpdateWithSystemFingerprintWorks()
788 {
789 string systemFingerprint = "footprint";
790 StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(systemFingerprint: systemFingerprint);
791
792 Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
793 Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
794#pragma warning disable CS0618
795 Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
796#pragma warning restore CS0618
797 Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
798 Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
799 Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
800 Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
801 Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
802 Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
803 Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
804 Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
805 Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.EqualTo(systemFingerprint));
806 Assert.That(streamingChatCompletionUpdate.Usage, Is.Null);
807 }
808
809 [Test]
810 public void StreamingChatCompletionUpdateWithUsageWorks()
811 {
812 ChatTokenUsage usage = OpenAIChatModelFactory.ChatTokenUsage(outputTokenCount: 20);
813 StreamingChatCompletionUpdate streamingChatCompletionUpdate = OpenAIChatModelFactory.StreamingChatCompletionUpdate(usage: usage);
814
815 Assert.That(streamingChatCompletionUpdate.CompletionId, Is.Null);
816 Assert.That(streamingChatCompletionUpdate.ContentUpdate, Is.Not.Null.And.Empty);
817#pragma warning disable CS0618
818 Assert.That(streamingChatCompletionUpdate.FunctionCallUpdate, Is.Null);
819#pragma warning restore CS0618
820 Assert.That(streamingChatCompletionUpdate.ToolCallUpdates, Is.Not.Null.And.Empty);
821 Assert.That(streamingChatCompletionUpdate.Role, Is.Null);
822 Assert.That(streamingChatCompletionUpdate.RefusalUpdate, Is.Null);
823 Assert.That(streamingChatCompletionUpdate.ContentTokenLogProbabilities, Is.Not.Null.And.Empty);
824 Assert.That(streamingChatCompletionUpdate.RefusalTokenLogProbabilities, Is.Not.Null.And.Empty);
825 Assert.That(streamingChatCompletionUpdate.FinishReason, Is.Null);
826 Assert.That(streamingChatCompletionUpdate.CreatedAt, Is.EqualTo(default(DateTimeOffset)));
827 Assert.That(streamingChatCompletionUpdate.Model, Is.Null);
828 Assert.That(streamingChatCompletionUpdate.SystemFingerprint, Is.Null);
829 Assert.That(streamingChatCompletionUpdate.Usage, Is.EqualTo(usage));
830 }
831
832 [Test]
833 public void StreamingChatFunctionCallUpdateWithNoPropertiesWorks()
834 {
835#pragma warning disable CS0618
836 StreamingChatFunctionCallUpdate streamingChatFunctionCallUpdate = OpenAIChatModelFactory.StreamingChatFunctionCallUpdate();
837#pragma warning restore CS0618
838
839 Assert.That(streamingChatFunctionCallUpdate.FunctionName, Is.Null);
840 Assert.That(streamingChatFunctionCallUpdate.FunctionArgumentsUpdate, Is.Null);
841 }
842
843 [Test]
844 public void StreamingChatFunctionCallUpdateWithFunctionNameWorks()
845 {
846 string functionName = "Margaret";
847#pragma warning disable CS0618
848 StreamingChatFunctionCallUpdate streamingChatFunctionCallUpdate = OpenAIChatModelFactory.StreamingChatFunctionCallUpdate(functionName: functionName);
849#pragma warning restore CS0618
850
851 Assert.That(streamingChatFunctionCallUpdate.FunctionName, Is.EqualTo(functionName));
852 Assert.That(streamingChatFunctionCallUpdate.FunctionArgumentsUpdate, Is.Null);
853 }
854
855 [Test]
856 public void StreamingChatFunctionCallUpdateWithFunctionArgumentsUpdateWorks()
857 {
858 BinaryData functionArgumentsUpdate = BinaryData.FromBytes("arguments_update"u8.ToArray());
859#pragma warning disable CS0618
860 StreamingChatFunctionCallUpdate streamingChatFunctionCallUpdate = OpenAIChatModelFactory.StreamingChatFunctionCallUpdate(functionArgumentsUpdate: functionArgumentsUpdate);
861#pragma warning restore CS0618
862
863 Assert.That(streamingChatFunctionCallUpdate.FunctionName, Is.Null);
864 Assert.That(streamingChatFunctionCallUpdate.FunctionArgumentsUpdate, Is.EqualTo(functionArgumentsUpdate));
865 }
866
867 [Test]
868 public void StreamingChatToolCallUpdateWithNoPropertiesWorks()
869 {
870 StreamingChatToolCallUpdate streamingChatToolCallUpdate = OpenAIChatModelFactory.StreamingChatToolCallUpdate();
871
872 Assert.That(streamingChatToolCallUpdate.Index, Is.EqualTo(0));
873 Assert.That(streamingChatToolCallUpdate.ToolCallId, Is.Null);
874 Assert.That(streamingChatToolCallUpdate.Kind, Is.EqualTo(default(ChatToolCallKind)));
875 Assert.That(streamingChatToolCallUpdate.FunctionName, Is.Null);
876 Assert.That(streamingChatToolCallUpdate.FunctionArgumentsUpdate, Is.Null);
877 }
878
879 [Test]
880 public void StreamingChatToolCallUpdateWithIndexWorks()
881 {
882 int index = 31415;
883 StreamingChatToolCallUpdate streamingChatToolCallUpdate = OpenAIChatModelFactory.StreamingChatToolCallUpdate(index: index);
884
885 Assert.That(streamingChatToolCallUpdate.Index, Is.EqualTo(index));
886 Assert.That(streamingChatToolCallUpdate.ToolCallId, Is.Null);
887 Assert.That(streamingChatToolCallUpdate.Kind, Is.EqualTo(default(ChatToolCallKind)));
888 Assert.That(streamingChatToolCallUpdate.FunctionName, Is.Null);
889 Assert.That(streamingChatToolCallUpdate.FunctionArgumentsUpdate, Is.Null);
890 }
891
892 [Test]
893 public void StreamingChatToolCallUpdateWithIdWorks()
894 {
895 string id = "tool_call_id";
896 StreamingChatToolCallUpdate streamingChatToolCallUpdate = OpenAIChatModelFactory.StreamingChatToolCallUpdate(toolCallId: id);
897
898 Assert.That(streamingChatToolCallUpdate.Index, Is.EqualTo(0));
899 Assert.That(streamingChatToolCallUpdate.ToolCallId, Is.EqualTo(id));
900 Assert.That(streamingChatToolCallUpdate.Kind, Is.EqualTo(default(ChatToolCallKind)));
901 Assert.That(streamingChatToolCallUpdate.FunctionName, Is.Null);
902 Assert.That(streamingChatToolCallUpdate.FunctionArgumentsUpdate, Is.Null);
903 }
904
905 [Test]
906 public void StreamingChatToolCallUpdateWithKindWorks()
907 {
908 ChatToolCallKind kind = ChatToolCallKind.Function;
909 StreamingChatToolCallUpdate streamingChatToolCallUpdate = OpenAIChatModelFactory.StreamingChatToolCallUpdate(kind: kind);
910
911 Assert.That(streamingChatToolCallUpdate.Index, Is.EqualTo(0));
912 Assert.That(streamingChatToolCallUpdate.ToolCallId, Is.Null);
913 Assert.That(streamingChatToolCallUpdate.Kind, Is.EqualTo(kind));
914 Assert.That(streamingChatToolCallUpdate.FunctionName, Is.Null);
915 Assert.That(streamingChatToolCallUpdate.FunctionArgumentsUpdate, Is.Null);
916 }
917
918 [Test]
919 public void StreamingChatToolCallUpdateWithFunctionNameWorks()
920 {
921 string functionName = "Margaret";
922 StreamingChatToolCallUpdate streamingChatToolCallUpdate = OpenAIChatModelFactory.StreamingChatToolCallUpdate(functionName: functionName);
923
924 Assert.That(streamingChatToolCallUpdate.Index, Is.EqualTo(0));
925 Assert.That(streamingChatToolCallUpdate.ToolCallId, Is.Null);
926 Assert.That(streamingChatToolCallUpdate.Kind, Is.EqualTo(default(ChatToolCallKind)));
927 Assert.That(streamingChatToolCallUpdate.FunctionName, Is.EqualTo(functionName));
928 Assert.That(streamingChatToolCallUpdate.FunctionArgumentsUpdate, Is.Null);
929 }
930
931 [Test]
932 public void StreamingChatToolCallUpdateWithFunctionArgumentsUpdateWorks()
933 {
934 BinaryData functionArgumentsUpdate = BinaryData.FromBytes("arguments_update"u8.ToArray());
935 StreamingChatToolCallUpdate streamingChatToolCallUpdate = OpenAIChatModelFactory.StreamingChatToolCallUpdate(functionArgumentsUpdate: functionArgumentsUpdate);
936
937 Assert.That(streamingChatToolCallUpdate.Index, Is.EqualTo(0));
938 Assert.That(streamingChatToolCallUpdate.ToolCallId, Is.Null);
939 Assert.That(streamingChatToolCallUpdate.Kind, Is.EqualTo(default(ChatToolCallKind)));
940 Assert.That(streamingChatToolCallUpdate.FunctionName, Is.Null);
941 Assert.That(streamingChatToolCallUpdate.FunctionArgumentsUpdate, Is.EqualTo(functionArgumentsUpdate));
942 }
943}
944