uji.wire
Wires turn a model call into the HTTP format of one kind of API, and stream
the answer back. uji ships three, openai-chat, anthropic and gemini, as
Lua modules in uji.wires. Copying one of them is the easiest way to start a
new one.
uji.wire.add(name, spec)
Registers a wire, or replaces the wire with the same name. spec.stream is a
function that receives a request and a reply table. It may return a function
that cancels the call.
The request has these fields:
model, the model idsystem, the system promptmessages, the conversation in uji’s message format, where a user or tool message may haveimages, a list of tables withmedia_type, base64data,name,widthandheighttools, a list ofname,descriptionandparameterseffort, one ofoff,minimal,low,mediumandhighmax_output, the output token limitcache, one ofoff,shortandlongsession, the session idprovider, withid,base_urlandcompatauth, withkey, andoauthfor subscription sign-in
The reply table has four functions:
reply.text(delta)streams answer text.reply.reasoning(delta)streams reasoning text.reply.done(answer)finishes the call.answerhastext, and optionallyreasoning,tool_callsandusage. Each tool call hasid,nameandarguments, whereargumentsis a JSON string.usagehasinput,output,cache_readandcache_write.reply.fail(failure)ends the call with an error.failure.kindis"http", withstatus,messageandretry_after, or"auth", withstatus, or"provider", withmessage. uji retrieshttpfailures with a status of 408, 409, 425, 429 or 5xx, andhttpfailures with no status, such as a dropped connection.
uji.wire.add("echo", {
stream = function(request, reply)
local last = request.messages[#request.messages]
reply.text("you said: ")
reply.done({ text = "you said: " .. (last.text or "") })
end,
})
uji.wire.remove(name)
Removes a wire and returns true if it existed.
uji.wire.remove("echo")
uji.wire.list()
Returns the names of the registered wires.
local wires = uji.wire.list()