ChatClient
Overview
This is the ChatClient class that wraps around a LLM to chat with it. It has support for adding files (images, videos, audio, pdf, text) to the chat.
Methods Summarized
Methods Detailed
addBytes(bytes)
Adds a file by bytes to the chat message. The bytes must be a image/*, video/*, audio/*, application/pdf or text/ content type
Parameters
Array bytes The bytes of that must be send. The content type will be detected automatically.
Returns: ChatClient The this
addBytes(bytes, contentType)
Adds a file by bytes to the chat message. The bytes must be a image/*, video/*, audio/*, application/pdf or text/ content type
Parameters
Array bytes The bytes of that must be send. The content type will be detected automatically.
String contentType the content the file, must be a image/*, video/*, audio/*, application/pdf or text/ content type
Returns: ChatClient The this
addFile(file)
Add a file (String or JSFile) to the chat message. The file must be a image/*, video/*, audio/*, application/pdf or text/ content type This will be guessed based on the file extension or content.
Parameters
Object file A JSFile or String (path to a file on the server)
Returns: ChatClient The this
addFile(file, contentType)
Add a file (String or JSFile) to the chat message. The file must be a image/*, video/*, audio/*, application/pdf or text/ content type
Parameters
Object file A JSFile or String (path to a file on the server)
String contentType the content the file, must be a image/*, video/*, audio/*, application/pdf or text/ content type
Returns: ChatClient The this
chat(userMessage)
Send a userMessage to the ai. This will return a promise that will be resolved with the response. This response is a Promise that will get a ChatResponse object in the then or the promise will be rejected with an error.
Parameters
String userMessage The user message
Returns: Promise {Promise<plugins.ai.ChatResponse>} A promise that will be resolved with the assistant response.
chat(userMessage, partialResponse, onComplete, onError)
Send a userMessage to the ai. This will call the provided functions on partial response, complete response and error. So this can be used for streaming responses.
Parameters
String userMessage The user message send to the ai.
Function partialResponse {(partialResponse:String)=>void} A function that will be called with each partial string response from the ai.
Function onComplete {(response:plugins.ai.ChatResponse)=>void} A function that will be called when the response is complete, it will be called with the ChatResponse object.
Function onError {(error:Exception)=>void} A function that will be called when an error occurs.
Returns: void
Last updated
Was this helpful?