@k-apps-io/llm-dsl-mongo
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

llm-dsl-mongo

a MongoDB implementation of @k-apps-io/llm-dsl ChatStorage

Installation

To install the package, run:

npm install @k-apps-io/llm-dsl-mongo

Collection Name

By default, the collection name is chat. However, this can be customized using the MONGO_CHAT_COLLECTION environment variable or by specifying the collection name directly when creating the model. See the example below for more details.

Usage

import mongoose from "mongoose";
import { DSL } from "@k-apps-io/llm-dsl";
import { ChatGPT, Options } from "@k-apps-io/llm-dsl-chatgpt";
import { useMongoStorage, Schema } from "@k-apps-io/llm-dsl-mongo";

// Define a Mongoose model for the chat storage
const Chat = mongoose.model("Chat", Schema, "myCollectionName");

// Initialize the MongoDB storage mechanism
const MongoStorage = useMongoStorage({ model: Chat });

// Set up the DSL with ChatGPT and MongoDB storage
const chat = new DSL<Options, any>({
  llm: new ChatGPT({}), // Configure ChatGPT with your desired options
  storage: MongoStorage,
  options: {
    model: "gpt-4o-mini", // Specify the model to use
  },
});

// Use the DSL to send a prompt and process the response
chat
  .prompt({ message: "hello" })
  .stream((chunk) => {
    if (chunk.type === "message") process.stdout.write(chunk.content);
  })
  .then(() => console.log("Done"))
  .catch((error) => {
    console.error("Error:", error);
    throw error;
  });

Readme

Keywords

none

Package Sidebar

Install

npm i @k-apps-io/llm-dsl-mongo

Weekly Downloads

0

Version

2.1.0

License

ISC

Unpacked Size

8.54 kB

Total Files

6

Last publish

Collaborators

  • imnotakopp