| lms_server_ready | R Documentation |
Sends one GET request to the model list endpoint at host and reports
whether the answer came from an LM Studio server that this package can use.
The answer is TRUE only when the request returns HTTP status 200 and the
response body is a model list that list_models() can read. The two
functions apply the same shape rules, which the "Malformed model list"
section of list_models() states. An empty list counts, so a server that
lists no models gives TRUE.
lms_server_ready(host = "http://localhost:1234", timeout = 2, token = NULL)
host |
Character. The base URL of the LM Studio server. Defaults to "http://localhost:1234". |
timeout |
Numeric. The number of seconds to wait for the request
before giving up. Defaults to 2. A host that opens the port and never
answers reports |
token |
Character or |
Use this in place of a port check. Another process holding the port, a
server that has not finished starting, and a server that rejects the token
all answer the port and all report FALSE here.
TRUE or FALSE, always one value. This function raises no
condition of its own for a network failure, a refused connection, an
unparsable body, or a failed status. All of those report FALSE. A
token that is not one character string and not NULL still aborts,
because that is a fault in the call rather than a fact about the server.
A fault in the call is not a fact about the server, so it aborts rather
than reporting FALSE. These messages come from the packages underneath.
The httr2 ones name httr2's own arguments, url for host and seconds
for timeout. The curl one names no argument at all. Six such faults are
named below.
A host of NULL. httr2 reports that url must be a single string,
not NULL.
A host of more than one string. httr2 reports that url must be a
single string, not a character vector.
A host that is a character NA. httr2 reports that url must be a
single string, not a character NA.
A host that is one string but cannot be parsed as a URL. curl reports
that it failed to parse the URL and names the reason. The wording of the
reason depends on the libcurl version. For a host holding a space, the
reason is for example "Malformed input to a URL function" or "Bad
hostname". For an empty host, it says that the URL has no host, for
example "No host part in the URL" or "No host present".
A timeout below one millisecond. httr2 reports that seconds must be
greater than 1 ms.
A timeout that is not one number, such as a string or a vector of two.
httr2 reports that seconds must be a number, and names either the
value or its type.
Those six are not the whole list. Any host that is not one string aborts
the same way, whatever the reason, and httr2 names either the value or its
type. A host of 1 gives "not the number 1". A host of list("a")
gives "not a list". A host of character(0) gives "not an empty
character vector".
The token fault named above aborts the same way. It comes from this
package rather than from httr2.
lms_server_start() to start the server. lms_server_status()
for what the CLI reports about it.
## Not run:
lms_server_start(port = 1234)
if (lms_server_ready()) {
list_models()
}
# A server on another port, with a shorter wait
lms_server_ready(host = "http://localhost:8080", timeout = 0.5)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.