Class: Llaminate

Llaminate(config)

Represents the Llaminate service for managing and interacting with AI models.

Constructor

new Llaminate(config)

Constructs a new instance of the Llaminate class.
Parameters:
Name Type Description
config LlaminateConfig The configuration options for the Llaminate instance.
Throws:
Will throw an error if the provided configuration is invalid.
Example
const mistral = new Llaminate({
  endpoint: Llaminate.MISTRAL,
  key: "12345-abcde-67890-fghij-klm",
  model: "mistral-small-latest",
  system: ["You are a sarcastic assistant who answers very briefly and bluntly."]
  rpm: 720
});

Classes

Llaminate

Members

(static, readonly) this.config

The configuration options for the Llaminate instance. Most of these options can be overridden on a per-request basis by passing a configuration object to the `complete` or `stream` methods. Exceptions are: - `endpoint` and `key`, which are fixed for the instance and cannot be overridden on a per-request basis. - `system`, for which request-level system messages will be appended to the instance-level system messages rather than replacing them. - `rpm`, which is used to initialize the rate limiter and cannot be overridden on a per-request basis.
Properties:
Name Type Description
Llaminate.config LlaminateConfig The configuration options for the Llaminate instance.

Methods

(async) chat(configopt, callbackopt) → {Promise.<void>}

Starts an interactive chat session in the command line interface. The session can be exited by pressing Ctrl+C. The LLM usage tokens will be displayed when the session ends. While waiting for an LLM response, pressing Ctrl+C will cancel the in-flight request and return control to the prompt. NOTE: This is a placeholder method. To use chat functionality, you must import the chat module separately: `import "llaminate/chat"` or `import { chat } from "llaminate/chat"`.
Parameters:
Name Type Attributes Description
config LlaminateConfig <optional>
Optional configuration settings for this chat session. Supported behavior in chat mode: - Most instance settings can be overridden for the duration of the session. - `endpoint` and `key` are fixed for the instance and cannot be overridden. - `options.stream` has special meaning in this method: - `false`: each replies don't stream, only the final output is shown. - `true` or unset: replies stream the the output as they arrive.
callback ResponseCallback <optional>
Optional callback invoked after each completion is received from the LLM. This can be used to set the CLI output if it should be different from the raw LLM response, for example if the response is expected to be in a structured format and you want to display a specific part of the response rather than the whole thing.
Returns:
A promise that resolves when the chat session ends.
Type
Promise.<void>
Example
// EXAMPLE: Starting a chat session with custom system messages
await mistral.chat({
  system: [
    "You are a helpful assistant who answers in the style of Shakespeare.",
    "Use flowery language and old English phrasing in your responses."
  ]
});

clear(messagesopt)

Resets the chat history. This does not affect the configuration or any other settings.
Parameters:
Name Type Attributes Description
messages Array.<LlaminateMessage> <optional>
Optional array of messages to initialize the history with after clearing. If not provided, the history will simply be cleared to an empty array.
Returns:
void
Examples
// EXAMPLE 1: Populating and then clearing the history
mistral.complete("What's your name?"); // "John"
mistral.complete("How do you spell that?"); // "J-O-H-N"
mistral.clear();
mistral.complete("Tell me again?"); // "Tell you what again?"
// EXAMPLE 2: Clearing the history and initializing with new messages
mistral.complete("What's your name?"); // "John"
mistral.complete("How do you spell that?"); // "J-O-H-N"
const newHistory = [
  { role: Llaminate.SYSTEM, content: "You are a cat who can only speak in meows." },
  { role: Llaminate.USER, content: "What's your name?" }
];
mistral.clear(newHistory);
mistral.complete("Tell me again?"); // "Meow?"

(async) complete(prompt, configopt) → {Promise.<LlaminateResponse>}

Sends a prompt to the LLM service and returns a chat completion response.
Parameters:
Name Type Attributes Description
prompt string | Array.<LlaminateMessage> The input prompt or messages to send to the service.
config LlaminateConfig <optional>
Optional configuration settings for this completion.
Throws:
Will throw an error if the prompt is invalid, the response is unsuccessful, or if the response does not conform to the expected format.
Returns:
A promise resolving to a LlaminateResponse from the service.
Type
Promise.<LlaminateResponse>
Examples
// EXAMPLE 1: Simple prompt with default configuration
const response = await mistral.complete("What's the capital of France?");
console.log(response.message); // "Paris"
// EXAMPLE 2: System messages set through configuration
const response = await mistral.complete("What's the capital of France?",
  { system: [
    "You are a children's geography tutor.",
    "Always reply as if you are explaining to a child."
  ] } );
// EXAMPLE 3: An image attachment (supported depends on LLM model)
const response = await mistral.complete(
  "Generate a helpful HTML `alt` tag for this image.", {
  attachments: [ { type: Llaminate.JPEG, url: "https://example.com/image.jpg" } ]
});
// EXAMPLE 4: Prompt with a pre-rolled conversation history
const history = [
  { role: "user", content: "What's a good name for a houseplant?" },
  { role: "assistant", content: "How about Fernie Sanders?" },
  { role: "user", content: "Nice. Any other suggestions?" },
  { role: "assistant", content: "How about Leaf Erickson?" }
];
const prompt = "Great. What could be its nickname?";
const response = await mistral.complete(prompt, { history });
// EXAMPLE 5: Rolling the conversation history into the prompt
const messages = history.concat({ role: "user", content: prompt });
const response = await mistral.complete(messages);

export(windowopt) → {Array.<LlaminateMessage>}

Exports the chat history. By default, this exports the entire chat history. If a window is specified, only the most recent messages are returned. The window counts back each of the most recent user message, it includes assistant responses to these, and any system prompts set in the global configuration.
Parameters:
Name Type Attributes Description
window number <optional>
The length of the window to retrieve.
Returns:
An array of chat history messages.
Type
Array.<LlaminateMessage>
Examples
// EXAMPLE 1: Exporting the entire history of messages
const history = mistral.export();
localStorage.setItem('mistral-history', JSON.stringify(history));
// EXAMPLE 2: Getting a window of recent messages
// Returns the last 5 user-assistant interactions and all system prompts
const history = mistral.export(5);
console.log(history.length);
// e.g. 14 = 5 user messages + 5 assistant replies (one that included a
// tool call) + 2 system prompts

(async, generator) stream(prompt, configopt) → {LlaminateResponse}

Sends a prompt to the LLM service and streams the response. A streamed response may include more that one message, depending on the response from the service. Individual messages will be terminated with a special character (ASCII RS, \x1E) to signal the end of the message. The final message in the stream will be terminated with a special character (ASCII EOT, \x04) to signal the end of the stream.
Parameters:
Name Type Attributes Description
prompt string | Array.<LlaminateMessage> The input prompt or messages to send to the service.
config LlaminateConfig <optional>
Optional configuration settings for this completion.
Throws:
Will throw an error if the prompt is invalid, the response is unsuccessful, or if the response does not conform to the expected format.
Yields:
An asynchronous generator yielding responses from the service.
Type
LlaminateResponse
Examples
// EXAMPLE 1: Streaming the response to a simple prompt
const stream = mistral.stream("Tell me a joke and explain it.");
for await (const response of stream) {
  console.log(response.message);
}
// EXAMPLE 2: Streaming a response with a structured output
const stream = mistral.stream("Tell me a joke and explain it.", {
  schema: {
    type: "object",
    properties: {
      joke: {
        type: "string",
        description: "Your response to the user's query."
      },
      explanation: {
        type: "string",
        description: "Your internal thoughts about the user's query."
      },
    },
    required: ["joke", "explanation"],
    additionalProperties: false,
  }
});
for await (const response of stream) {
  // Initially streams as a string until the JSON schema can be validated
  console.log(response.message);
  console.log(response.message?.joke);
  console.log(response.message?.explanation);
}

(async, static) chat()

Starts an interactive chat session for the provided Llaminate instance. This static helper is equivalent to calling `instance.chat(...)`. NOTE: This is a placeholder method. To use chat functionality, you must import the chat module separately: `import "llaminate/chat"`.