Giter Club home page Giter Club logo

cmnd-extension-sample-nodejs's Introduction

Getting Started:

This repository hosts a nodejs - Express applications, designed to execute various server-side tools and add them to CMND.ai dynamically based on requests. It allows users to query tool information and run specific tools by passing parameters.

  1. Clone the repository:
git clone [email protected]:CyprusCodes/cmnd-extension-sample-nodejs.git
  1. Navigate to the cloned directory:
cd cmnd-extension-sample-nodejs
  1. Install the node modules
npm install
  1. Navigate to the tools file

  2. Within the tools.js, create your tool definition by specifying its name, description, parameters, and the runCmd, which is the function itself, below is an example of function definition.

require("dotenv").config();
const axios = require("axios"); // Only for external API calls
const yup = require("yup");
const yupToJsonSchema = require("./yupToJsonSchema");

const yourSchema = yup.object({
  // Define your validation schema here Use yup methods to define validation rules for each parameter
  // Example:
  // parameter1: yup.string().required(),
  // parameter2: yup.number().positive(),
});

const yourJSONSchema = yupToJsonSchema(yourSchema);

const YOUR_TOOL_NAME = {
  name: "your_tool_name",
  description: "Describe what your tool does and how it works here", // Describe functionality
  category: "your_category", // Choose a relevant category
  subcategory: "your_subcategory", // Specify a subcategory if applicable
  functionType: "your_function_type", // Specify backend or frontend
  dangerous: false, // Set to true if user confirmation is required
  associatedCommands: [], // List any associated commands (if any)
  prerequisites: [], // List any prerequisites for your tool to run
  parameters: yourJSONSchema,
  rerun: true, // Set to false if rerun is not allowed
  rerunWithDifferentParameters: true, // Set to false if different parameters are not allowed
  runCmd: async (
    {
      /* Your parameter names here */
    }, memory // Comes from the server. You can add data to it that won't be a part of the chatbot's response
  ) => {
    try {
      // Implement your tool's logic here:

      const data = await axios.get(/* url based on parameters */);
      
      memory[your_key] = "" // The data you want to save (Optional)

      // If you updated the memory
      return {
        responseString: "", // The string to be sent as a response to the chatbot
        memory: memory // Return memory after updating it
      }

      // Or you can just return the data as the chatbot's response
      return JSON.stringify(data);

    } catch (err) {
      // Handle potential errors and return a meaningful message
      return "Error trying to execute the tool";
    }
  },
};

// Add your tool object to the tools array (assuming it exists)
const tools = [YOUR_TOOL_NAME, YOUR_OTHER_TOOL_NAME];
module.exports = tools; // Export the tool object
  1. Run your app (server):
npm start
  1. Any API keys required for your tools should be stored in your .env file.

Therefore, you will not need to modify the index.js in any case. Instead, you will only make changes to the tools.js file, where you will initially add your tool's schema definition, implement the tool, and finally configure the tool settings.

Run Your Server Publicly using ngrok

  1. Create an ngrok account and set up ngrok on your personal computer. ngrok accounts and setup
  2. After setting ngrok on you computer, run the server
npm start
  1. Now your app is runing on localhost, if you want to run it on public URL, you can run the below command in your terminal, but make sure the port of your app specified in your index.js or .env is the same as the port used by ngrok in your command
ngrok http 8000

โœ… And DONE! Your server is successfully redirected to from the url you get on your terminal. You can open the tools.js file in your code editor and investigate the tools and make further changes if necessary.

cmnd-extension-sample-nodejs's People

Contributors

daniel-teddy avatar ersel avatar abdomody35 avatar

Watchers

 avatar

Forkers

berketok-git

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.