View Source GptAgent.Assistant (gpt_agent v8.1.0)

Provides representation of the schema of an OpenAI GPT assistant

Summary

Functions

Returns the struct's type spec t() description for debugging purposes.

Ensures that struct conforms to its t() type and all preconditions are fulfilled.

Ensures that struct conforms to its t() type and all preconditions are fulfilled.

Creates a struct validating type conformance and preconditions.

Creates a struct validating type conformance and preconditions.

Returns the list of struct's fields having type others then nil or any().

Returns the list of struct's fields defined with explicit types in its t() type spec.

Types

Functions

Returns the struct's type spec t() description for debugging purposes.

Domo compiled validation functions for the given struct based on the described type spec.

Link to this function

ensure_type(struct, opts \\ [])

View Source

Ensures that struct conforms to its t() type and all preconditions are fulfilled.

Returns struct when it's valid in the shape of {:ok, struct}. Otherwise returns the error in the shape of {:error, message_by_field}.

Takes the same options as new/2.

Useful for struct validation when its fields changed with map syntax or with Map module functions.

Options are the same as for new/2.

Examples

alias GptAgent.Assistant

struct = Assistant.new!(first_field: value1, second_field: value2, ...)

{:ok, _updated_struct} =
  Assistant.ensure_type(%{struct | first_field: new_value})

{:ok, _updated_struct} =
  struct
  |> Map.put(:first_field, new_value1)
  |> Map.put(:second_field, new_value2)
  |> Assistant.ensure_type()

Ensures that struct conforms to its t() type and all preconditions are fulfilled.

Returns struct when it's valid. Raises an ArgumentError otherwise.

Useful for struct validation when its fields changed with map syntax or with Map module functions.

Examples

alias GptAgent.Assistant

struct = Assistant.new!(first_field: value1, second_field: value2, ...)

Assistant.ensure_type!(%{struct | first_field: new_value})

struct
|> Map.put(:first_field, new_value1)
|> Map.put(:second_field, new_value2)
|> Assistant.ensure_type!()
@spec function(params :: keyword() | map()) :: GptAgent.Assistant.Function.t()

Creates a new GptAgent.Assistant.Function

params are the same as the fields of GptAgent.Assistant.Function

Link to this function

new(enumerable \\ [], opts \\ [])

View Source

Creates a struct validating type conformance and preconditions.

The argument is any Enumerable that emits two-element tuples (key-value pairs) during enumeration.

Returns the instance of the struct built from the given enumerable in the shape of {:ok, struct_value}. Does so only if struct's field values conform to its t() type and all field's type and struct's type precondition functions return ok.

If conditions described above are not fulfilled, the function returns an appropriate error in the shape of {:error, message_by_field}. message_by_field is a keyword list where the key is the name of the field and value is the string with the error message.

Keys in the enumerable that don't exist in the struct are automatically discarded.

Options

  • maybe_filter_precond_errors - when set to true, the values in message_by_field instead of string become a list of error messages from precondition functions. If there are no error messages from precondition functions for a field's type, then all errors are returned unfiltered. Helpful in taking one of the custom errors after executing precondition functions in a deeply nested type to communicate back to the user. F.e. when the field's type is another struct. Default is false.

Examples

alias GptAgent.Assistant

Assistant.new(first_field: value1, second_field: value2, ...)

Creates a struct validating type conformance and preconditions.

The argument is any Enumerable that emits two-element tuples (key-value pairs) during enumeration.

Returns the instance of the struct built from the given enumerable. Does so only if struct's field values conform to its t() type and all field's type and struct's type precondition functions return ok.

Raises an ArgumentError if conditions described above are not fulfilled.

This function will check if every given key-value belongs to the struct and raise KeyError otherwise.

Examples

alias GptAgent.Assistant

Assistant.new!(first_field: value1, second_field: value2, ...)
@spec parameter(params :: keyword() | map()) ::
  GptAgent.Assistant.Function.Parameter.t()

Creates a new GptAgent.Assistant.Function.Parameter

params are the same as the fields of GptAgent.Assistant.Function.Parameter

Link to this function

required_fields(opts \\ [])

View Source

Returns the list of struct's fields having type others then nil or any().

Does not return meta fields with __underscored__ names.

Useful for validation of the required fields for emptiness. F.e. with validate_required/2 call in the Ecto changeset.

Options

  • :include_meta - when set to true, adds fields with __underscored__ names to the return list. Default is false.
Link to this macro

schema(params)

View Source (macro)

Creates a new GptAgent.Assistant

params are passed unaltered to GptAgent.Assistant.new!/1; this macro is just a bit of syntactic sugar.

Link to this function

typed_fields(opts \\ [])

View Source

Returns the list of struct's fields defined with explicit types in its t() type spec.

Does not return meta fields with __underscored__ names and fields having any() type by default.

Includes fields that have nil type into the return list.

Options

  • :include_any_typed - when set to true, adds fields with any() type to the return list. Default is false.

  • :include_meta - when set to true, adds fields with __underscored__ names to the return list. Default is false.