View Source Anthropix.XML (Anthropix v0.1.0)

Support module for encoding XML data into prompts. Mainly used to support function calling.

Summary

Functions

Encodes the given data into the specified message type.

Functions

@spec encode(atom(), term()) :: String.t()

Encodes the given data into the specified message type.

Supports encoding a list of Anthropix.Tool.t/0 structs into a :tools message, or a list of Anthropix.FunctionCall.t/0 structs into a :function_results message.

Examples

iex> Anthropix.XML.encode(:tools, [
...>   %Anthropix.Tool{name: "a", description: "aaa", params: [
...>     %{name: "b", description: "bbb", type: "string"}
...>   ]}
...> ])
"<tools><tool_description><tool_name>a</tool_name><description>aaa</description><parameters><parameter><name>b</name><description>bbb</description><type>string</type></parameter></parameters></tool_description></tools>"

iex> Anthropix.XML.encode(:function_results, [
...>   %Anthropix.FunctionCall{name: "a", result: "aaa"}
...> ])
"<function_results><result><tool_name>a</tool_name><stdout>aaa</stdout></result></function_results>"