A client of one provider. Created with LLM.new.

Summary

Methods

Sends a chat request.

Methods

Client:chat(request, callback)

server packages/llm/lib/llm.lua:313

Sends a chat request. The callback receives the response, or nil and an error.

The response is a Map with the fields: text (String all text of the reply), tool_calls (List of Maps with id, name and input, empty if there are none), stop_reason ('end', 'tool_use', 'max_tokens', 'refusal' or the provider's own reason), refusal (details of a refusal, if the provider gives any), usage (Map with input_tokens and output_tokens), model, message (the assistant message to append to the conversation) and raw (the decoded reply).

The error is a Map with status (HTTP status, 0 if there was no reply), message, type (the provider's error type, if any) and body (the raw reply, if any).

client:chat('Say hello.', function(response, err)
  print(response and response.text or err.message)
end)

Parameters

  • request String/Map a single user message, or a Map with the fields: messages [List<Map> the conversation] system=nil [String system prompt] tools=nil [List<Map> tools with name, description and parameters (a JSON schema)] stop=nil [List<String> stop sequences] model, max_tokens, effort=nil [overrides of the client's settings] extra=nil [Map extra fields merged into the request body]
  • callback Function receives the response, or nil and the error

Defined in