Liking cljdoc? Tell your friends :D

toolnexus.translate


args-objectclj/s

(args-object args)

Parses a tool-call arguments value into a map, tolerating BOTH wire forms: §11 requires a port to accept arguments supplied as an object as well as the JSON string, because some clients send it that way. A malformed string is not fatal — it yields {}.

Parses a tool-call `arguments` value into a map, tolerating BOTH wire forms:
§11 requires a port to accept `arguments` supplied as an object as well as the
JSON string, because some clients send it that way. A malformed string is not
fatal — it yields `{}`.
sourceraw docstring

args-stringclj/s

(args-string args)

Renders a tool-call arguments value as the JSON STRING the OpenAI wire format uses, so a caller can hand it to a conforming client byte-for-byte.

Renders a tool-call `arguments` value as the JSON STRING the OpenAI wire
format uses, so a caller can hand it to a conforming client byte-for-byte.
sourceraw docstring

content-textclj/s

(content-text content)

Flattens an OpenAI content value to text: the string form and the parts-array form. Parts with no string text contribute nothing.

Flattens an OpenAI `content` value to text: the string form and the
parts-array form. Parts with no string `text` contribute nothing.
sourceraw docstring

finish-reason-forclj/s

(finish-reason-for has-tool-calls? provider-stop)

Maps a provider stop reason onto an OpenAI finish reason.

TOOL CALLS WIN: a turn that emitted any tool call is always "tool_calls" to a conforming client, whatever the provider said (§11). Otherwise max_tokens/length -> "length", refusal/content_filter -> "content_filter", everything else -> "stop".

Maps a provider stop reason onto an OpenAI finish reason.

TOOL CALLS WIN: a turn that emitted any tool call is always `"tool_calls"`
to a conforming client, whatever the provider said (§11). Otherwise
max_tokens/length -> "length", refusal/content_filter -> "content_filter",
everything else -> "stop".
sourceraw docstring

has-system-message?clj/s

(has-system-message? messages)

True when the message list already carries a system-ish message.

True when the message list already carries a system-ish message.
sourceraw docstring

openai-messages-to-anthropicclj/s

(openai-messages-to-anthropic messages)

Converts an OpenAI messages array into Anthropic-native messages plus the extracted system prompt, preserving the tool structure a text flattening destroys (§11):

  • an assistant turn's tool_calls become tool_use blocks, with arguments re-parsed from its JSON string into an OBJECT;
  • a tool-role result becomes a tool_result block keyed by its tool_call_id, MERGED into a single user turn when consecutive;
  • system/developer messages are HOISTED out, since Anthropic takes system separately (multiple ones join with a blank line).

Returns {:messages [...] :system "..."}.

Converts an OpenAI `messages` array into Anthropic-native messages plus the
extracted system prompt, preserving the tool structure a text flattening
destroys (§11):

  - an assistant turn's `tool_calls` become `tool_use` blocks, with
    `arguments` re-parsed from its JSON string into an OBJECT;
  - a `tool`-role result becomes a `tool_result` block keyed by its
    `tool_call_id`, MERGED into a single user turn when consecutive;
  - `system`/`developer` messages are HOISTED out, since Anthropic takes
    system separately (multiple ones join with a blank line).

Returns `{:messages [...] :system "..."}`.
sourceraw docstring

openai-tool-choice-to-anthropicclj/s

(openai-tool-choice-to-anthropic choice)

Maps OpenAI tool_choice onto Anthropic's shape. Returns nil for absent / "auto" (the provider default) and for anything unrecognized, so nothing is sent and the provider decides.

Maps OpenAI `tool_choice` onto Anthropic's shape. Returns nil for absent /
`"auto"` (the provider default) and for anything unrecognized, so nothing is
sent and the provider decides.
sourceraw docstring

openai-tools-to-anthropicclj/s

(openai-tools-to-anthropic tools)

Converts an OpenAI tools array into Anthropic tool declarations. Entries that are already provider-native pass through; anything unrecognized is skipped. A missing parameters becomes an empty object schema.

Converts an OpenAI `tools` array into Anthropic tool declarations. Entries
that are already provider-native pass through; anything unrecognized is
skipped. A missing `parameters` becomes an empty object schema.
sourceraw docstring

tool-calls-jsonclj/s

(tool-calls-json result)

Renders a result's tool calls as an OpenAI tool_calls array, ready to put on an assistant message. Convenience for assembling a response envelope.

Renders a result's tool calls as an OpenAI `tool_calls` array, ready to put on
an assistant message. Convenience for assembling a response envelope.
sourceraw docstring

tool-calls-ofclj/s

(tool-calls-of m)

Reads an assistant message's OpenAI tool_calls into [{:id :name :arguments}], arguments in the JSON-string wire form. An entry with no function is skipped.

Reads an assistant message's OpenAI `tool_calls` into
`[{:id :name :arguments}]`, arguments in the JSON-string wire form. An entry
with no `function` is skipped.
sourceraw docstring

translateclj/s

(translate client request)

SPEC §11 — exactly ONE provider call, returned in OpenAI shape. Drives no loop, executes no tool, touches no conversation store.

client is a toolnexus.client/create-client map. request:

:messages the OpenAI messages array, VERBATIM (assistant turns with tool_calls, tool-role results with tool_call_id) :tools the OpenAI tools array, VERBATIM — declaration-only :toolkit an ordinary toolkit, DECLARED via the §5 adapters and NEVER executed; composes with :tools, toolkit declarations first :toolChoice the OpenAI tool_choice, VERBATIM (mapped for anthropic) :system overrides the system prompt :maxTokens overrides the per-provider default (anthropic default 4096)

Returns:

{:text "" :toolCalls [{:id :name :arguments}] :finishReason "stop"|"tool_calls"|"length"|"content_filter" :usage {:prompt-tokens :completion-tokens :total-tokens} :model "" :raw <the provider's decoded response>}

:arguments is a JSON STRING — the OpenAI wire form.

SPEC §11 — exactly ONE provider call, returned in OpenAI shape. Drives no
loop, executes no tool, touches no conversation store.

`client` is a `toolnexus.client/create-client` map. `request`:

  :messages     the OpenAI `messages` array, VERBATIM (assistant turns with
                `tool_calls`, `tool`-role results with `tool_call_id`)
  :tools        the OpenAI `tools` array, VERBATIM — declaration-only
  :toolkit      an ordinary toolkit, DECLARED via the §5 adapters and NEVER
                executed; composes with :tools, toolkit declarations first
  :toolChoice   the OpenAI `tool_choice`, VERBATIM (mapped for anthropic)
  :system       overrides the system prompt
  :maxTokens    overrides the per-provider default (anthropic default 4096)

Returns:

  {:text "" :toolCalls [{:id :name :arguments}] :finishReason
   "stop"|"tool_calls"|"length"|"content_filter"
   :usage {:prompt-tokens :completion-tokens :total-tokens}
   :model "" :raw <the provider's decoded response>}

`:arguments` is a JSON STRING — the OpenAI wire form.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close