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

@graphteon/lambda-lm

v0.1.6

Published

[![npm version](https://img.shields.io/npm/v/lambdalm.svg)](https://www.npmjs.com/package/@graphteon/lambda-lm) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Downloads

36

Readme

LambdaLM

npm version License: MIT

LambdaLM is a powerful JavaScript library that enables function calling capabilities for Language Models (LLMs). It provides a seamless interface to define, manage, and execute functions that can be called directly by language models, enhancing their ability to perform specific tasks and interact with external systems.

Features

  • 🚀 Easy function registration and management
  • 🔄 Automatic parameter validation
  • 📦 Type-safe function calling
  • 🛠 Built-in error handling
  • 🔍 Function discovery and documentation
  • ⚡ Async function support

Installation

You can install LambdaLM using npm:

npm install @graphteon/lambda-lm

Or using yarn:

yarn add @graphteon/lambda-lm

Quick Start

Here's a simple example to get you started with LambdaLM:


const LambdaLM = require('@graphteon/lambda-lm');

async function lambdaCall() {
    const lambda = new LambdaLM();
    lambda.register([{
        spec: {
            "name": "Calculator",
            "description": "Calculate a math expression. For example, \"2 + 2\" or \"2 * 2\". The expression must be a valid JavaScript math expression.",
            "parameters": {
                "type": "object",
                "properties": {
                    "expression": {
                        "type": "string",
                        "description": "A valid JavaScript math expression for the calculation."
                    }
                },
                "required": ["expression"]
            }
        },
        handler: (params) => {
            return eval(params.expression);
        }
    }]);

    const res = await lambda.inference([{ "role": "user", "content" : "please calculate 2*(2/3)" }]); //{"role":"assistant","content":null,"tool_calls":[{"id":"call_HrsCajKTBKdVGO2zlpnha6zw","type":"function","function":{"name":"Calculator","arguments":"{\"expression\":\"2*(2/3)\"}"}}],"refusal":null,"finished":true} 
    
    if (res.tool_calls) {
        const spawn = await lambda.spawn();
        for await (const spw of spawn) {
            console.log('SPAWN RESULT :', JSON.stringify(spw), '\n')
        }
    }
}

lambdaCall()

Advanced Usage

Async Functions

LambdaLM supports async functions out of the box:

lambda.register({ spec : {
  name: 'FetchUserData',
  description: 'Fetch user data from an API',
  parameters: {
    userId: {
      type: 'string',
      description: 'The ID of the user to fetch'
    }
  }
},
  handler: async ({ userId }) => {
    const response = await fetch(`https://api.example.com/users/${userId}`);
    return response.json();
  }
});

Function Composition

You can compose multiple functions together:

lambda.registerFunction({
  name: 'processOrder',
  description: 'Process a complete order',
  parameters: {
    items: {
      type: 'array',
      description: 'Array of items in the order'
    },
    userId: {
      type: 'string',
      description: 'User ID making the order'
    }
  },
  handler: async ({ items, userId }) => {
    const userData = await lambda.call('fetchUserData', { userId });
    const total = await lambda.call('calculateTotal', {
      price: items.reduce((sum, item) => sum + item.price, 0),
      taxRate: userData.taxRate
    });
    return { total, user: userData };
  }
});

API Documentation

Class: LambdaLM

Methods

  • register(config: FunctionConfig): void
  • spawn(functionName: string): Promise<any>
  • list(): FunctionInfo[]

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use LambdaLM in your research or project, please cite it as follows:

@software{lambdalm2024,
  author = {Eka Tresna Irawan},
  title = {LambdaLM: Function Calling Library for Language Models},
  year = {2024},
  publisher = {GitHub},
  url = {https://github.com/graphteon/LambdaLM}
}

Acknowledgments

  • Inspired by the function calling capabilities of modern language models
  • Built with love for the AI and developer community
  • Special thanks to all contributors and users