UNPKG

ollama-api-facade-js

Version:

OllamaApiFacadeJS is an open-source library for running an ExpressJS backend as an Ollama API using LangChainJS. It supports local language models services like LmStudio and allows seamless message conversion and streaming between LangChainJS and Ollama c

48 lines 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChatRequest = void 0; const messages_1 = require("@langchain/core/messages"); const MessageUtils_1 = require("../utils/MessageUtils"); /** * Class representing a chat request. * This is submitted by the Ollama client and automatically mapped to LangChain message objects. */ class ChatRequest { constructor({ chat_id, id, messages, model, options, session_id, stream, }) { this.chat_id = chat_id; this.id = id; this.messages = messages; this.model = model; this.options = options; this.session_id = session_id; this.stream = stream; } /** * Adds a system message. * @param systemPrompt - The system message to be added. */ addSystemMessage(systemPrompt) { this.messages = (0, MessageUtils_1.addSystemMessage)(this.messages, systemPrompt); } /** * Retrieves the last human message from the chat messages. * @returns {HumanMessage} - The last human message. */ lastHumanMessage() { return (0, MessageUtils_1.lastHumanMessage)(this.messages); } /** * Replaces the last human message in the chat messages. * @param {HumanMessage | string} humanMessage - The new human message to replace the last one. Can be a HumanMessage object or a string. * @returns {BaseMessage[]} - The updated array of chat messages. */ replaceLastHumanMessage(humanMessage) { let message = humanMessage; if (typeof message === 'string') { message = new messages_1.HumanMessage(humanMessage); } return (0, MessageUtils_1.replaceLastHumanMessage)(this.messages, message); } } exports.ChatRequest = ChatRequest; //# sourceMappingURL=ChatModels.js.map