An adapter turns gptr's request context into one provider's wire format and its stream back
into gptr events. HTTP and process adapters give build() and parse(); inprocess adapters
give stream(), a generator factory; classifier adapters give classify.
Arguments
- api
The wire api this adapter implements (the name providers bind to).
- transport
"http_sse","http_ndjson","http_json","process_jsonl"or"inprocess".- build
function(model, context, opts)returning a request spec.- parse
function(model, opts)returning a stream normalizer.- stream
function(model, context, opts)returning a generator (inprocess).- classify
Named list for classifier adapters:
build(model, state, questions, opts)andparse(model, status, headers, body, questions), orrun(model, state, questions, opts)forinprocess. Classifier response parsing has a separate signature from the ordinary chat streamparse(model, opts).- capabilities
Named list of adapter capabilities.
Examples
gptr_adapter("echo", transport = "inprocess",
stream = function(model, context, opts) {
state = new.env()
state$done = FALSE
function() {
if (state$done) return(NULL)
state$done = TRUE
list(events = list())
}
})
#> <gptr_adapter echo>
#> api: echo
#> transport: inprocess
#> stream: <fn>
#> capabilities: <list of 0>
#> api_version: 1.0