GenAI.Tool.Schema.String (GenAI Core v0.3.1)

Copy Markdown

Represents a schema for string types, converting JSON schema attributes to Elixir struct fields.

Summary

Functions

Convert Json map to a GenAI.Tool.Schema.String struct, handling naming conventions.

Check if json is of type

Types

t()

@type t() :: %GenAI.Tool.Schema.String{
  description: String.t() | nil,
  format: String.t() | nil,
  max_length: integer() | nil,
  min_length: integer() | nil,
  pattern: String.t() | nil,
  type: String.t()
}

Functions

from_json(attributes)

@spec from_json(map()) :: t()

Convert Json map to a GenAI.Tool.Schema.String struct, handling naming conventions.

Examples

Is of Type

iex> GenAI.Tool.Schema.String.from_json(%{"type" => "string", "description" => "A string value"})
{:ok, %GenAI.Tool.Schema.String{type: "string", description: "A string value"}}

Not of Type

iex> GenAI.Tool.Schema.String.from_json(%{"type" => "number"})
{:error, :unrecognized_type}

is_type(arg1)

Check if json is of type

Examples

Is of Type

iex> GenAI.Tool.Schema.String.is_type(%{"type" => "string"})
true

Not of Type

iex> GenAI.Tool.Schema.String.is_type(%{"type" => "number"})
false