Skip to content

Commit 2241627

Browse files
authored
Merge pull request #383 from deepgram/feat/agent-mip_opt_out
feat: adds support for agent mip_opt_out
2 parents ecff935 + 8112d16 commit 2241627

File tree

2 files changed

+169
-1
lines changed

2 files changed

+169
-1
lines changed

Deepgram.Tests/UnitTests/ClientTests/AgentClientTests.cs

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,165 @@ public void InjectUserMessageSchema_ToString_Should_Return_Valid_Json()
198198
parsed.RootElement.GetProperty("content").GetString().Should().Be("Hello! Can you hear me?");
199199
}
200200
}
201+
202+
#region MipOptOut Tests
203+
204+
[Test]
205+
public void Agent_MipOptOut_Should_Have_Default_Value_False()
206+
{
207+
// Arrange & Act
208+
var agent = new Agent();
209+
210+
// Assert
211+
using (new AssertionScope())
212+
{
213+
agent.MipOptOut.Should().BeFalse();
214+
}
215+
}
216+
217+
[Test]
218+
public void Agent_MipOptOut_Should_Be_Settable()
219+
{
220+
// Arrange & Act
221+
var agent = new Agent
222+
{
223+
MipOptOut = true
224+
};
225+
226+
// Assert
227+
using (new AssertionScope())
228+
{
229+
agent.MipOptOut.Should().BeTrue();
230+
}
231+
}
232+
233+
[Test]
234+
public void Agent_MipOptOut_Should_Serialize_To_Snake_Case()
235+
{
236+
// Arrange
237+
var agent = new Agent
238+
{
239+
MipOptOut = true
240+
};
241+
242+
// Act
243+
var result = agent.ToString();
244+
245+
// Assert
246+
using (new AssertionScope())
247+
{
248+
result.Should().NotBeNull();
249+
result.Should().Contain("mip_opt_out");
250+
result.Should().Contain("true");
251+
252+
// Verify it's valid JSON by parsing it
253+
var parsed = JsonDocument.Parse(result);
254+
parsed.RootElement.GetProperty("mip_opt_out").GetBoolean().Should().BeTrue();
255+
}
256+
}
257+
258+
[Test]
259+
public void Agent_MipOptOut_False_Should_Serialize_Correctly()
260+
{
261+
// Arrange
262+
var agent = new Agent
263+
{
264+
MipOptOut = false
265+
};
266+
267+
// Act
268+
var result = agent.ToString();
269+
270+
// Assert
271+
using (new AssertionScope())
272+
{
273+
result.Should().NotBeNull();
274+
result.Should().Contain("mip_opt_out");
275+
result.Should().Contain("false");
276+
277+
// Verify it's valid JSON by parsing it
278+
var parsed = JsonDocument.Parse(result);
279+
parsed.RootElement.GetProperty("mip_opt_out").GetBoolean().Should().BeFalse();
280+
}
281+
}
282+
283+
[Test]
284+
public void Agent_MipOptOut_Null_Should_Not_Serialize()
285+
{
286+
// Arrange
287+
var agent = new Agent
288+
{
289+
MipOptOut = null
290+
};
291+
292+
// Act
293+
var result = agent.ToString();
294+
295+
// Assert
296+
using (new AssertionScope())
297+
{
298+
result.Should().NotBeNull();
299+
result.Should().NotContain("mip_opt_out");
300+
301+
// Verify it's valid JSON by parsing it
302+
var parsed = JsonDocument.Parse(result);
303+
parsed.RootElement.TryGetProperty("mip_opt_out", out _).Should().BeFalse();
304+
}
305+
}
306+
307+
[Test]
308+
public void Agent_With_MipOptOut_Should_Serialize_With_Other_Properties()
309+
{
310+
// Arrange
311+
var agent = new Agent
312+
{
313+
Language = "en",
314+
Greeting = "Hello, I'm your agent",
315+
MipOptOut = true
316+
};
317+
318+
// Act
319+
var result = agent.ToString();
320+
321+
// Assert
322+
using (new AssertionScope())
323+
{
324+
result.Should().NotBeNull();
325+
result.Should().Contain("language");
326+
result.Should().Contain("greeting");
327+
result.Should().Contain("mip_opt_out");
328+
329+
// Verify it's valid JSON by parsing it
330+
var parsed = JsonDocument.Parse(result);
331+
parsed.RootElement.GetProperty("language").GetString().Should().Be("en");
332+
parsed.RootElement.GetProperty("greeting").GetString().Should().Be("Hello, I'm your agent");
333+
parsed.RootElement.GetProperty("mip_opt_out").GetBoolean().Should().BeTrue();
334+
}
335+
}
336+
337+
[Test]
338+
public void Agent_MipOptOut_Schema_Should_Match_API_Specification()
339+
{
340+
// Arrange - Test both default (false) and explicit true values
341+
var agentDefault = new Agent();
342+
var agentOptOut = new Agent { MipOptOut = true };
343+
344+
// Act
345+
var defaultResult = agentDefault.ToString();
346+
var optOutResult = agentOptOut.ToString();
347+
348+
// Assert
349+
using (new AssertionScope())
350+
{
351+
// Default should be false
352+
var defaultParsed = JsonDocument.Parse(defaultResult);
353+
defaultParsed.RootElement.GetProperty("mip_opt_out").GetBoolean().Should().BeFalse();
354+
355+
// Explicit true should be true
356+
var optOutParsed = JsonDocument.Parse(optOutResult);
357+
optOutParsed.RootElement.GetProperty("mip_opt_out").GetBoolean().Should().BeTrue();
358+
}
359+
}
360+
361+
#endregion
201362
}

Deepgram/Models/Agent/v2/WebSocket/Agent.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ public record Agent
3232
[JsonPropertyName("greeting")]
3333
public string? Greeting { get; set; }
3434

35+
/// <summary>
36+
/// To opt out of Deepgram Model Improvement Program
37+
/// </summary>
38+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
39+
[JsonPropertyName("mip_opt_out")]
40+
public bool? MipOptOut { get; set; } = false;
41+
3542
/// <summary>
3643
/// Override ToString method to serialize the object
3744
/// </summary>
3845
public override string ToString()
3946
{
4047
return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
4148
}
42-
49+
4350
}

0 commit comments

Comments
 (0)