enum

OpenAI::MessageRole

Inherits Enum < Comparable < Value < Object

Constants

Unknown = 0
User = 1
Assistant = 2
System = 3
Critic = 4
Discriminator = 5
Developer = 6
Tool = 7

Constructors

new(pull : JSON::PullParser) : self
Source

Instance methods

assistant?

Returns true if this enum value equals Assistant

Source
critic?

Returns true if this enum value equals Critic

Source
developer?

Returns true if this enum value equals Developer

Source
discriminator?

Returns true if this enum value equals Discriminator

Source
system?

Returns true if this enum value equals System

Source
to_json(json : JSON::Builder) : Nil

Serializes this enum member by name.

For non-flags enums, the serialization is a JSON string. The value is the member name (see #to_s) transformed with String#underscore.

enum Stages
  INITIAL
  SECOND_STAGE
end

Stages::INITIAL.to_json      # => %("initial")
Stages::SECOND_STAGE.to_json # => %("second_stage")

For flags enums, the serialization is a JSON array including every flagged member individually serialized in the same way as a member of a non-flags enum. None is serialized as an empty array, All as an array containing all members.

@[Flags]
enum Sides
  LEFT
  RIGHT
end

Sides::LEFT.to_json                  # => %(["left"])
(Sides::LEFT | Sides::RIGHT).to_json # => %(["left","right"])
Sides::All.to_json                   # => %(["left","right"])
Sides::None.to_json                  # => %([])

ValueConverter.to_json offers a different serialization strategy based on the member value.

Source
tool?

Returns true if this enum value equals Tool

Source
unknown?

Returns true if this enum value equals Unknown

Source
user?

Returns true if this enum value equals User

Source