Giter Club home page Giter Club logo

touristshaun / functionchain Goto Github PK

View Code? Open in Web Editor NEW

This project forked from developersdigest/functionchain

0.0 0.0 0.0 49 KB

The FunctionChain is a tool that simplifies and organizes the process of invoking OpenAI functions in your Node.js applications. With this toolkit, you can easily scaffold out and isolate all the OpenAI function calls you need, making your code more modular, maintainable, and scalable.

JavaScript 100.00%

functionchain's Introduction

Demo

Demonstration

Installation

  1. Install the package using npm or yarn:
npm install ai-function-chain
# or
yarn add ai-function-chain
# or
pnpm install ai-function-chain
  1. Create a file named .env at the root of your project. Obtain your OpenAI API Key from here, and add it to the .env file:
OPENAI_API_KEY=your_openai_api_key

Setup

To setup FunctionChain:

  1. Create an index.js file in the root of your project.
  2. Import the FunctionChain class from ai-function-chain and instantiate it.
  3. Call the call method with a message. Optionally, you can specify a set of functions to execute.
import { FunctionChain } from "ai-function-chain";

const functionChain = new FunctionChain();

async function main() {
    const res1 = await functionChain.call("Get me the latest price of Bitcoin");
    const res2 = await functionChain.call("Open the calculator on my computer");
    const res3 = await functionChain.call("Get me the latest price of Ethereum", {
        functionArray: ["latestPrices"] // Optionally specify which functions to use
    });

    console.log(res1, res2, res3);
}

main();

Customization

You can customize FunctionChain instance by specifying different OpenAI model and a custom directory for your function modules:

const initOptions = {
  openaiOptions: {
    model: "gpt-3.5-turbo-0613", // specify a different model if needed
  },
  functionsDirectory: "./myFunctions", // specify a custom directory if you have one
};

const functionChain = new FunctionChain(initOptions);

Adding Custom Functions

  1. Create a new JavaScript file for your function in the functionsDirectory specified while creating the FunctionChain instance.
  2. Follow the following pattern to define your function:
import { exec } from 'child_process';

export const execute = (options) => {
    const { appName } = options;
    return new Promise((resolve, reject) => {
        exec(`open -a "${appName}"`, (error, stdout, stderr) => {
            if (error) {
                console.warn(error);
                reject(`Error opening ${appName}: ${error.message}`);
            }
            resolve(`${appName} opened successfully.`);
        });
    });
}

export const details = {
    name: "openApp",
    description: "Opens a specified application on your computer",
    parameters: {
        type: "object",
        properties: {
            appName: {
                type: "string",
                description: "The name of the application to open"
            },
        },
        required: ["appName"],
    },
    example: "Open the 'Calculator' application"
};

Running Your Project

After setting up index.js and adding your functions, run your project using:

npm run dev

functionchain's People

Contributors

developersdigest avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.