{"id":15442469,"url":"https://github.com/developersdigest/function-chain","last_synced_at":"2025-04-19T18:25:26.731Z","repository":{"id":177360381,"uuid":"660281106","full_name":"developersdigest/function-chain","owner":"developersdigest","description":"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.","archived":false,"fork":false,"pushed_at":"2023-07-10T17:26:15.000Z","size":13886,"stargazers_count":56,"open_issues_count":0,"forks_count":10,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-15T11:18:25.441Z","etag":null,"topics":["alpha-vantage","artificial-intelligence","automation","function-calling","functionchain","langchain","machine-learning","natural-language","natural-language-processing","nlp","openai","pinecone"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/developersdigest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-29T16:38:26.000Z","updated_at":"2025-03-18T10:55:11.000Z","dependencies_parsed_at":"2023-07-25T23:02:08.089Z","dependency_job_id":null,"html_url":"https://github.com/developersdigest/function-chain","commit_stats":null,"previous_names":["developersdigest/functionchain","developersdigest/function-chain"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developersdigest%2Ffunction-chain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developersdigest%2Ffunction-chain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developersdigest%2Ffunction-chain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developersdigest%2Ffunction-chain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/developersdigest","download_url":"https://codeload.github.com/developersdigest/function-chain/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249239231,"owners_count":21235820,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alpha-vantage","artificial-intelligence","automation","function-calling","functionchain","langchain","machine-learning","natural-language","natural-language-processing","nlp","openai","pinecone"],"created_at":"2024-10-01T19:27:53.549Z","updated_at":"2025-04-16T12:30:35.089Z","avatar_url":"https://github.com/developersdigest.png","language":"JavaScript","readme":"\u003c!-- ![Image](https://i.imgur.com/aFpv4iu.gif) --\u003e\n[FunctionChain: OpenAI Function Calling Simplified in Node.js](https://youtu.be/jmrFG7n3Nt8)\n\n# Quickstart\n\nThis guide will walk you through the basic steps required to get the `FunctionChain` library up and running.\n\n## Installation\n\n1. First of all, you need to clone the repository to your local machine:\n\n```bash\ngit clone https://github.com/developersdigest/FunctionChain\n```\n\n2. Move to the directory where the repository has been cloned and install the necessary dependencies using npm:\n\n```bash\ncd FunctionChain\nnpm install\n```\n\n3. Rename the `.env.example` to `.env` at the root of your project. Obtain your OpenAI API Key from [here](https://platform.openai.com/account/api-keys), and add it to the `.env` file:\n\n```bash\nOPENAI_API_KEY=your_openai_api_key\n```\n\n4. Now you can run with the example in `index.js` by using:\n\n```bash\nnode index.js\nor\nnpm run dev\n```\n\n## Setup\n\nTo setup `FunctionChain`, follow the steps below:\n\n1. Create an `index.js` file in the root of your project.\n2. Import the `FunctionChain` class from `ai-function-chain` and instantiate it.\n3. Call the `call` method with a message. Optionally, you can specify a set of functions to execute.\n\n```javascript\nimport { FunctionChain, fetchCryptoPrice, openApp } from \"ai-function-chain\";\n\nconst functionChain = new FunctionChain({\n  functions: [openApp, fetchCryptoPrice],\n});\n\nconst res1 = await functionChain.call(\"Open the calculator on my computer\");\nconst res2 = await functionChain.call(\"Get me the latest price of Bitcoin\");\nconst res3 = await functionChain.call(\"Get me the latest price of Ethereum\");\n\nconsole.log(`${res1} \\n${res2} \\n${res3}`);\n```\n\n## API Keys\n\nTo use `FunctionChain`, you must obtain and provide the appropriate API keys. \n\nREQUIRED: for all functions:\n\n```bash\nOPENAI_API_KEY=your_openai_api_key\n```\n\nYou need to obtain your OpenAI API Key [here](https://platform.openai.com/account/api-keys) and add it to the `.env` file.\n\nOPTIONAL: If you intend to use specific functions, you need to obtain the respective API keys:\n\n**For Alpha Vantage functions:**\n\n```bash\nALPHA_VANTAGE_API_KEY=your_alpha_vantage_api_key\n```\n\nGet your Alpha Vantage API key [here](https://www.alphavantage.co/support/#api-key)\n\n**For Pinecone functions:**\n\n```bash\nPINECONE_API_KEY=your_pinecone_api_key\nPINECONE_ENVIRONMENT=your_pinecone_environment\nPINECONE_INDEX=your_pinecone_index\n```\n\nGet your Pinecone API key [here](https://docs.pinecone.io/docs/node-client)\n\n**For Visual Crossing API functions:**\n\n```bash\nVISUAL_CROSSING_API_KEY=your_visual_crossing_api_key\n```\n\nGet your Visual Crossing API key [here](https://www.visualcrossing.com/weather-api)\n\n**For Huggingface API functions:**\n\n```bash\nHUGGING_FACE_API_KEY=your_hugging_face_api_key\n```\n\nYou can get your Huggingface API key [here](https://huggingface.co/settings/tokens) (A read only token)\n\n\n## Examples\n\nHere are some examples of how you can use FunctionChain:\n\n**Example 1: Unix Example (No additional API Key Required)** \n\n```javascript\nimport { FunctionChain, openApp } from \"ai-function-chain\";\n\nconst functionChain = new FunctionChain({functions: [openApp]});\n\nconst res = await functionChain.call(\"Open the calculator on my computer\");\n\nconsole.log(res);\n```\nAlternatively, you can run the following:\n```bash\nnode examples/unix-example.js\n```\n\n**Example 2: Crypto Prices (No API Key Required)**\n\n```javascript\nimport { FunctionChain, fetchCryptoPrice } from \"ai-function-chain\";\n\nconst functionChain = new FunctionChain({functions: [fetchCryptoPrice]});\n\nconst res1 = await functionChain.call(\"Get me the latest price of Bitcoin\");\n\nconst res2 = await functionChain.call(\"Get me the latest price of Ethereum\");\n\nconsole.log(`1. ${res1} \\n2. ${res2}`);\n```\nAlternatively, you can run the following:\n```bash\nnode examples/no-api-key-example.js\n```\n\n**Example 3: Pinecone Example (Pinecone API Key Required)**\n\nYou can get your Pinecone API Key [here](https://docs.pinecone.io/docs/node-client)\n\n```javascript\nimport { FunctionChain, createPinecone, updatePinecone, askPinecone } from \"ai-function-chain\";\n\nconst functionChain = new FunctionChain({functions: [createPinecone, updatePinecone, askPinecone]});\n\nconst create = await functionChain.call(\"Create a pinecone index called function-chain\");\nconst update = await functionChain.call(\"Add 'John Smith, his phone number is 123-456-7890 and email johnsmith@example.com' under the namespace my-contacts\");\nconst ask = await functionChain.call(\"What is John Smiths number? to-do's in my my-contacts pinecone namespace?\");\n\nconsole.log(`1. ${create} \\n2. ${update} \\n3. ${ask}`);\n```\nAlternatively, you can run the following:\n```bash\nnode examples/pinecone-example.js\n```\n\n**Example 4: Alpha Vantage API (Free API Key Required)**\n\nYou can get your Alpha Vantage API key [here](https://www.alphavantage.co/support/#api-key)\n\n```javascript\nimport { FunctionChain, getAlphaVantageCompanyOverview } from \"ai-function-chain\";\n\nconst functionChain = new FunctionChain({functions: [getAlphaVantageCompanyOverview]});\n\nconst res1 = await functionChain.call(\"What is Apple's market capitalization\");\nconst res2 = await functionChain.call(\"What is Microsoft's PE Ratio\");\nconst res3 = await functionChain.call(\"What is Amazon's Revenue (TTM)\");\nconst res4 = await functionChain.call(\"What is Alphabet's EBITDA\");\n\nconsole.log(`1. ${res1} \\n2. ${res2} \\n3. ${res3} \\n4. ${res4}`);\n```\nAlternatively, you can run the following:\n```bash\nnode examples/alpha-vantage-examples.js\n```\n\n**Example 5: Huggingface Inference (Free API Key Required)**\n\nYou can get your Huggingface API key [here](https://huggingface.co/settings/tokens) (A read only token)\n\n```javascript\nimport { FunctionChain, huggingFaceImageClassification } from \"ai-function-chain\";\n\nconst functionChain = new FunctionChain({functions: [huggingFaceImageClassification]}); \n\nconst res = await functionChain.call(\"What is this image? https://www.shutterstock.com/image-photo/yellow-lovebird-sitting-alone-on-260nw-1894954309.jpg\");\nconsole.log(res);\n```\nAlternatively, you can run the following:\n```bash\nnode examples/hugging-face-example.js\n```\n\n**Example 6: Visual Crossing API (API Key Required)**\n\nYou can get your Visual Crossing API key [here](https://www.visualcrossing.com/weather-api)\n\n```javascript\nimport { FunctionChain, getVisualCrossingWeatherForecast } from \"ai-function-chain\";\n\nconst functionChain = new FunctionChain({functions: [getVisualCrossingWeatherForecast]});\n\nconst res = await functionChain.call(\"What's the weather this week in Toronto\");\nconsole.log(res);\n```\nAlternatively, you can run the following:\n```bash\nnode examples/weather-visual-crossing-example.js\n```\n\n### Example 7: Using the Wikipedia API (No API Key required)\n\nThis example demonstrates how you can use the `wikipedia` function from the AI Function Chain to retrieve a summary of a Wikipedia page:\n\n```javascript\nimport { FunctionChain, wikipedia } from \"ai-function-chain\";\n\nconst functionChain = new FunctionChain({\n  functions: [wikipedia],\n  skipFinalAPICall: true,\n});\n\nconst res = await functionChain.call(\"In one sentence, look up on wikipedia, what is Langchain?\");\nconsole.log(res);\n```\n\nYou can also run this example directly from the command line:\n\n```\nnode examples/wikipedia-example.js\n```\n\n**Note:** In this example, we're using the `skipFinalAPICall: true` option. This ensures that the result is obtained directly from the `wikipedia` function, without making a final API call to OpenAI.\n\n### Example 8: Using the Code Interpreter\n\nThis example demonstrates how you can use the `codeInterpreter` function from the AI Function Chain to execute code snippets in Node.js:\n\n```javascript\nimport { FunctionChain, codeInterpreter } from \"ai-function-chain\";\n\nconst functionChain = new FunctionChain({ functions: [codeInterpreter] });\n\nlet res1 = await functionChain.call(\"Using node.js execute a function that will give me a random number\");\nconsole.log(res1);\n\nlet res2 = await functionChain.call(`\n  Execute this in Node.js:\n  const fibonacci = (n) =\u003e {\n    if (n \u003c= 1) return n;\n    return fibonacci(n - 1) + fibonacci(n - 2);\n  };\n  fibonacci(10);\n`);\nconsole.log(res2);\n\nlet res3 = await functionChain.call(\"Execute a twoSum function in node.js\");\nconsole.log(res3);\n```\n\n# Function Descriptions\n\n## wikipedia\n- **Name**: wikipedia\n- **Description**: Search for \"JavaScript\" on Wikipedia.\n\n## codeInterpreter\n- **Name**: codeInterpreter\n- **Description**: Function can execute Node.js code directly code requested within a Node.js V8 runtime written in Javascript and returns the result. Doesn't support any new require or import statements yet\n\n## fetchCryptoPrice\n- **Name**: fetchCryptoPrice\n- **Description**: Fetches the price of a cryptocurrency from CoinGecko.\n\n## getAlphaVantageCompanyOverview\n- **Name**: getAlphaVantageCompanyOverview\n- **Description**: Fetches company information, financial ratios, and other key metrics for the specified equity using the Alpha Vantage API. This includes the following information: Symbol, Asset Type, Name, Description, CIK, Exchange, Currency, Country, Sector, Industry, Address, Fiscal Year End, Latest Quarter, Market Capitalization, EBITDA, PE Ratio, PEG Ratio, Book Value, Dividend Per Share, Dividend Yield, EPS, Revenue Per Share (TTM), Profit Margin, Operating Margin (TTM), Return on Assets (TTM), Return on Equity (TTM), Revenue (TTM), Gross Profit (TTM), Diluted EPS (TTM), Quarterly Earnings Growth (YoY), Quarterly Revenue Growth (YoY), Analyst Target Price, Trailing PE, Forward PE, Price to Sales Ratio (TTM), Price to Book Ratio, EV to Revenue, EV to EBITDA, Beta, 52-Week High, 52-Week Low, 50-Day Moving Average, 200-Day Moving Average, Shares Outstanding, Dividend Date, Ex-Dividend Date.\n\n## getAlphaVantageIntraday\n- **Name**: getAlphaVantageIntraday\n- **Description**: Fetches intraday data for a specified stock without extended hours.\n\n## askPinecone\n- **Name**: askPinecone\n- **Description**: This function queries/asks a question to a Pinecone index and returns the top answer. The Pinecone client, index name, and API keys are specified in the .env file or function parameters.\n\n## createPinecone\n- **Name**: createPinecone\n- **Description**: This function checks if a specified Pinecone index exists. If it does not exist, it will create a new one. Do not confuse this with updating an index.\n\n## updatePinecone\n- **Name**: updatePinecone\n- **Description**: This function updates a Pinecone index with vector embeddings generated from a given text with an optional namespace if passed. The Pinecone client, index name, and API keys are specified in the .env file or function parameters.\n\n## openApp\n- **Name**: openApp\n- **Description**: Opens a specified application on your computer\n\n## takeScreenshot\n- **Name**: takeScreenshot\n- **Description**: Captures a screenshot from the terminal\n\n## getVisualCrossingWeatherForecast\n- **Name**: getVisualCrossingWeatherForecast\n- **Description**: Fetches weather forecast for the specified location using the Visual Crossing API. This includes temperature, humidity, wind speed, and other important weather data.\n\n\n# Contribution\n\nContributions to the `FunctionChain` library are more than welcome! If you have any helpful functions you'd like to contribute, or if there's a library you'd like to see integrated with `FunctionChain`, please feel free to reach out or submit a pull request.\n\nYou can contribute in several ways:\n\n- **Submit a pull request**: If you've written any functions that you'd like to share with the community, you can submit a pull request on the GitHub repository.\n- **Open an issue**: If you've identified a bug or have a feature request, you can open an issue on the GitHub repository.\n- **Get in touch**: If you have ideas or questions, feel free to reach out directly. Your feedback and ideas are invaluable in continuing to improve `FunctionChain`.\n\nI am excited to see how you use `FunctionChain` and to hear your ideas for improvements!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevelopersdigest%2Ffunction-chain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevelopersdigest%2Ffunction-chain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevelopersdigest%2Ffunction-chain/lists"}