-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from tghamm/feature/3.2.1
Ensures Role is returned as Enum #31
- Loading branch information
Showing
6 changed files
with
49 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Anthropic.SDK.Messaging; | ||
|
||
namespace Anthropic.SDK.Extensions | ||
{ | ||
public class RoleTypeConverter : JsonConverter<RoleType> | ||
{ | ||
public override RoleType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
string value = reader.GetString(); | ||
return value switch | ||
{ | ||
"user" => RoleType.User, | ||
"assistant" => RoleType.Assistant, | ||
_ => throw new JsonException($"Unknown role type: {value}") | ||
}; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, RoleType value, JsonSerializerOptions options) | ||
{ | ||
string roleString = value switch | ||
{ | ||
RoleType.User => "user", | ||
RoleType.Assistant => "assistant", | ||
_ => throw new InvalidOperationException("Invalid role type") | ||
}; | ||
writer.WriteStringValue(roleString); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
using System.Text; | ||
|
||
namespace Anthropic.SDK.Messaging | ||
{ | ||
public enum RoleType | ||
{ | ||
[EnumMember(Value = "user")] | ||
User, | ||
[EnumMember(Value = "assistant")] | ||
Assistant | ||
} | ||
} |