NornsSdk.Format (norns_sdk v0.1.0)

Copy Markdown View Source

Translates between the provider-neutral wire format (used by the Norns orchestrator) and ReqLLM's types.

Neutral format

Messages:

  • %{"role" => "user", "content" => "text"}
  • %{"role" => "assistant", "content" => "text", "tool_calls" => [%{"id" => ..., "name" => ..., "arguments" => ...}]}
  • %{"role" => "tool", "tool_call_id" => "tc_1", "name" => "search", "content" => "result"}

Tool definitions:

  • %{"name" => "search", "description" => "...", "parameters" => %{...}}

Finish reasons: "stop", "tool_call", "length", "error"

Summary

Functions

Convert an Anthropic API response body to neutral format.

Convert a ReqLLM Response to neutral wire format.

Normalize a model string to ReqLLM's provider:model format.

Convert neutral-format messages to Anthropic API format.

Convert neutral tool definitions to Anthropic format.

Convert neutral-format messages to a ReqLLM Context.

Convert neutral tool definitions to ReqLLM Tool structs.

Functions

from_anthropic_response(body)

Convert an Anthropic API response body to neutral format.

from_req_llm_response(response)

@spec from_req_llm_response(ReqLLM.Response.t()) :: map()

Convert a ReqLLM Response to neutral wire format.

normalize_model(model)

@spec normalize_model(String.t()) :: String.t()

Normalize a model string to ReqLLM's provider:model format.

If the string already contains a colon, it's passed through. Otherwise, infers the provider from the model name (claude → anthropic, gpt/o1/o3 → openai, gemini → google).

to_anthropic_messages(messages)

Convert neutral-format messages to Anthropic API format.

to_anthropic_tools(tools)

Convert neutral tool definitions to Anthropic format.

to_req_llm_context(messages)

@spec to_req_llm_context([map()]) :: ReqLLM.Context.t()

Convert neutral-format messages to a ReqLLM Context.

to_req_llm_tools(tools)

@spec to_req_llm_tools([map()]) :: [ReqLLM.Tool.t()]

Convert neutral tool definitions to ReqLLM Tool structs.