Nous.Types (nous v0.9.0)

View Source

Core type definitions for Nous AI.

This module defines all the types used throughout the library. No functions, just type specifications for documentation and Dialyzer.

Summary

Types

Message content - can be text or multi-modal.

Any message type

Model identifier - provider:model string

Model request message.

Model response message.

Output type specification - :string or an Ecto schema module

Message parts that can appear in requests to the model

Message parts that can appear in responses from the model

Stream event types

System prompt message part

Text response part from model

Thinking/reasoning part from model

Tool call information from the model.

Tool call part from model

Tool return information sent back to the model.

Tool return message part

User prompt message part

Types

content()

@type content() ::
  String.t()
  | {:text, String.t()}
  | {:image_url, String.t()}
  | {:audio_url, String.t()}
  | {:document_url, String.t()}

Message content - can be text or multi-modal.

Examples

"Just text"
{:text, "Formatted text"}
{:image_url, "https://example.com/image.png"}

message()

@type message() :: model_request() | model_response()

Any message type

model()

@type model() :: String.t()

Model identifier - provider:model string

model_request()

@type model_request() :: %{parts: [request_part()], timestamp: DateTime.t()}

Model request message.

A message we send to the model.

model_response()

@type model_response() :: %{
  parts: [response_part()],
  usage: Nous.Usage.t(),
  model_name: String.t(),
  timestamp: DateTime.t()
}

Model response message.

A message we receive from the model, including usage information.

output_type()

@type output_type() :: :string | module()

Output type specification - :string or an Ecto schema module

request_part()

@type request_part() :: system_prompt_part() | user_prompt_part() | tool_return_part()

Message parts that can appear in requests to the model

response_part()

@type response_part() :: text_part() | tool_call_part() | thinking_part()

Message parts that can appear in responses from the model

stream_event()

@type stream_event() ::
  {:text_delta, String.t()}
  | {:thinking_delta, String.t()}
  | {:tool_call_delta, any()}
  | {:finish, String.t()}
  | {:complete, any()}
  | {:error, term()}

Stream event types

system_prompt_part()

@type system_prompt_part() :: {:system_prompt, String.t()}

System prompt message part

text_part()

@type text_part() :: {:text, String.t()}

Text response part from model

thinking_part()

@type thinking_part() :: {:thinking, String.t()}

Thinking/reasoning part from model

tool_call()

@type tool_call() :: %{id: String.t(), name: String.t(), arguments: map()}

Tool call information from the model.

The model requests to call a tool with these parameters.

tool_call_part()

@type tool_call_part() :: {:tool_call, tool_call()}

Tool call part from model

tool_return()

@type tool_return() :: %{call_id: String.t(), result: any()}

Tool return information sent back to the model.

The result of executing a tool call.

tool_return_part()

@type tool_return_part() :: {:tool_return, tool_return()}

Tool return message part

user_prompt_part()

@type user_prompt_part() :: {:user_prompt, String.t() | [content()]}

User prompt message part