npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

langchainjs-mock-language-model

v1.0.8

Published

LangChain.js Mock Language Model is a package that provides a mock implementation of the `BaseLanguageModel` class from LangChain.js. It allows you to easily create mock language models for testing and development purposes.

Downloads

18

Readme

LangChain.js MockLanguageModel

LangChain.js Mock Language Model is a package that provides a mock implementation of the BaseLanguageModel class from LangChain.js. It allows you to easily create mock language models for testing and development purposes.

Installation

You can install the package using npm:

npm install langchainjs-mock-language-model

Usage

To use the mock language model, you need to import the MockLanguageModel class from the package and create an instance of it with the desired mock functions.

import { MockLanguageModel } from 'langchainjs-mock-language-model';

const mockModel = MockLanguageModel.from<string>({
  invokeMock: async (input: BaseLanguageModelInput, options?: Partial<BaseLanguageModelCallOptions> | undefined) => {
    if (input === '1') {
      return 'Hello';
    } else if (input === '2') {
      return 'Nice to meet you';
    } else {
      return 'Unknown input';
    }
  },
});

In the above example, we create a MockLanguageModel instance using the from factory method with a custom invokeMock function. The invokeMock function defines the behavior of the invoke method, which takes an input and returns a mocked response based on the input value.

You can also provide mock functions for other methods like generatePrompt, predict, predictMessages, _modelType, and _llmType.

Once you have created the mock language model instance, you can use it in your tests or development code as follows:

async function testMockModel() {
  const response1 = await mockModel.invoke('1');
  console.log(response1); // Output: 'Hello'

  const response2 = await mockModel.invoke('2');
  console.log(response2); // Output: 'Nice to meet you'

  const response3 = await mockModel.invoke('3');
  console.log(response3); // Output: 'Unknown input'
}

In this example, we call the invoke method of the mock language model with different inputs and log the responses.

Configuration

The MockLanguageModel class provides a static from method that accepts an object with optional mock functions for each method of the BaseLanguageModel class. You can provide custom implementations for these methods based on your testing or development requirements.

The available mock functions are:

  • generatePromptMock: Mock function for the generatePrompt method.
  • predictMock: Mock function for the predict method.
  • predictMessagesMock: Mock function for the predictMessages method.
  • modelTypeMock: Mock function for the _modelType method.
  • llmTypeMock: Mock function for the _llmType method.
  • invokeMock: Mock function for the invoke method.

If a mock function is not provided, the corresponding method will return a default value.

Contributing

Contributions to the LangChain.js Mock Language Model package are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.

License

This package is open-source and released under the MIT License.