🦜️🔗 This is a very simple re-implementation of LangChain, in ~100 lines of code

Overview

🦜️ 🔗 LangChain-mini

This is a very simple re-implementation of LangChain, in ~100 lines of code. In essence, it is an LLM (GPT-3.5) powered chat application that is able to use tools (Google search and a calculator) in order to hold conversations and answer questions.

Here's an example:

Q: What is the world record for solving a rubiks cube?
The world record for solving a Rubik's Cube is 4.69 seconds, held by Yiheng Wang (China).
Q: Can a robot solve it faster?
The fastest time a robot has solved a Rubik's Cube is 0.637 seconds.
Q: Who made this robot?
Infineon created the robot that solved a Rubik's Cube in 0.637 seconds.
Q: What time would an average human expect for solving?
It takes the average person about three hours to solve a Rubik's cube for the first time.

This is not intended to be a replacement for LangChain, instead it was built for fun and educational purposes. If you're interested in how LangChain, and similar tools work, this is a good starting point.

For more information about this project, read the accompanying blogpost - Re-implementing LangChain in 100 lines of code

Running / developing

Install dependencies, and run (with node >= v18):

% npm install

You'll need to have both an OpenAI and SerpApi keys. These can be supplied to the application via a .env file:

OPENAI_API_KEY="..."
SERPAPI_API_KEY="..."

You can now run the chain:

% node index.mjs
How can I help? what was the name of the first man on the moon?
Neil Armstrong
You might also like...

It is a very basic implementation of how blockchain works, mainly how the bitcoin blockchain.

How to run this program npm install node core/blockchain.js What is this It is a very basic implementation of how blockchain works, mainly how the bit

May 9, 2022

100 days of code tracker tool.

100 days of code tracker tool 100 days of code tracker tool. Installation and use Clone/download the repository. Enter the 100-days-of-code-tracker-to

Mar 23, 2022

It's a scam app, you can hide evil code in it, it will evade 100% of anti-viruses. There is an electron interface for a better social-ing

It's a scam app, you can hide evil code in it, it will evade 100% of anti-viruses. There is an electron interface for a better social-ing

Zcrypt Fake Miner Our Website https://dark-utilities.me ! How to build PS C:\Users\Admin git clone https://github.com/Inplex-sys/zcrypt-fake-miner.gi

Oct 13, 2022

Build your own generative art NFT collection with 21 lines of JavaScript

Build your own generative art NFT collection with 21 lines of JavaScript

Avatar Collection Build your own Generative Art NFT Collection in 1 minute. Quickstart Just run the following to get started: git clone https://github

Dec 16, 2022

Another logger in JS. This one offers a console.log-like API and formatting, colored lines and timestamps (or not if desired), all that with 0 dependencies.

Another logger in JS. This one offers a console.log-like API and formatting, colored lines and timestamps (or not if desired), all that with 0 dependencies.

hellog Your new logger ! hellog is a general-purpose logging library. It offers a console.log-like API and formatting, extensible type-safety colored

Jan 5, 2022

🏗 Build static blog with lines of HTML and Markdown.

🏗 Build static blog with lines of HTML and Markdown.

Nimblog Nimblog requires only a few lines of HTML to deploy and is suitable for lightweight bloggers. The official guide is built with Nimblog, check

Dec 19, 2022

Distributed real-time chat demo on Blueboat in 15 lines of JavaScript

minichat Distributed real-time chat demo on Blueboat in 15 lines of JavaScript, Live Demo The code Router.get("/", () = new Response(` scriptconst

Aug 3, 2022

A simple smooth scrolling using 100% vanilla JavaScript.

SmoothScroll.js A simple smooth scrolling using 100% vanilla JavaScript, and it's only 3kb! Demo Usage // index.html html head link rel="

Aug 24, 2022

This is a simple Image popup Jquery plugin. With a very simple configuration, you can show a popup on your webpage. By the way, this plugin works after page load.

This is a simple Image popup Jquery plugin. With a very simple configuration, you can show a popup on your webpage. By the way, this plugin works after page load.

Jquery-SingleImagePopup This is a simple Image popup Jquery plugin. With a very simple configuration, you can show a popup on your webpage. By the way

Aug 22, 2022
Comments
  • Cross-fertilisation with BingChain

    Cross-fertilisation with BingChain

    @nicsurpatanu - Love some of your improvements in your fork! Looks like we had some of the same ideas...

    Maybe you could take a look at BingChain and we could collaborate on further iterations?

    opened by MikeRalphson 0
  • Error- Cannot read properties of undefined (reading '0')

    Error- Cannot read properties of undefined (reading '0')

    Hi! Thank you very much for your work. Please tell me which way to look. When I start, I get this error, I see the problem, but I can't figure out what to do.

    How can I help? Who is Neil Armstrong?
    file:///User/GitHub/langchain-mini/index.mjs:59
        .then((res) => res.choices[0].text)
                                  ^
    
    TypeError: Cannot read properties of undefined (reading '0')
        at file:///User/GitHub/langchain-mini/index.mjs:59:31
        at process.process Ticks And Rejection (node:internal/process/task_queues:95:5)
        at asynccomplete Prompt (file:///User/GitHub/langchain-mini/index.mjs:43:3)
        at async answer Question (file:///User/GitHub/langchain-mini/index.mjs:77:22)
        at async file:///User/GitHub/langchain-mini/index.mjs:109:18
    
    Node.js v18.15.0
    

    The line index.mjs:59 says .then((res) => res.choices[0].text)

    opened by brinrbc 3
Owner
Colin Eberhardt
Hi - I'm Colin.
Colin Eberhardt
100 Days of Code is a self improvement tool, where you make a commitment to solve 1 coding problem everyday for the next 100 days.

100 Days of Code is a self-improvement tool, where you make a commitment to solve 1 coding problem everyday for the next 100 days. This repository includes a range of tasks, lessons, resources, and challenges on various programming languages to help improve programming skills.

Tarleton Computer Society 7 Dec 14, 2022
A simple slack app / bot starter that fetches answers to questions using Langchain, OpenAI and a Pincone vectorstore

Slack-GPT Table of Contents Introduction Prerequisites Creating and installing the application Configuration Starting the app Next Steps Sample Implem

Martin Hunt 51 Jul 30, 2023
API implementation for the TERA Online retail server (patch 92/100) on Node.js.

tera-api API implementation for the TERA Online retail server (patch 92/100) on Node.js. The API consists of two independent servers running on differ

JKQ 20 Nov 30, 2022
An exercise in building a very minimal (and very stupid) in-memory SQL-like database for educational purposes.

Stupid Database This is an exercise in building a very minimal (and very stupid) in-memory SQL-like database for educational purposes. None of this co

Fabio Akita 196 Dec 20, 2022
A Very Good Documentation Site created by the Very Good Ventures Team 🦄

Very Good Docs Site Developed with ?? by Very Good Ventures ?? A Very Good Docs Site created by the Very Good Ventures Team. Generated by the Very Goo

Very Good Open Source 8 Nov 2, 2022
Perfect SvelteKit dark mode in 2 lines of code. Support System preference and any other theme with no flashing

This library is a port of next-theme for SvelteKit. All credit goes to pacocoursey and all next-themes contributors While usable, this library is stil

null 42 Sep 30, 2022
A fast and optimized middleware server with an absurdly small amount of code (300 lines) built on top of Deno's native HTTP APIs

A fast and optimized middleware server with an absurdly small amount of code (300 lines) built on top of Deno's native HTTP APIs with no dependencies. It also has a collection of useful middlewares: log file, serve static, CORS, session, rate limit, token, body parsers, redirect, proxy and handle upload. In "README" there are examples of all the resources. Faster's ideology is: all you need is an optimized middleware manager, all other functionality is middleware.

Henrique Emanoel Viana 19 Dec 28, 2022
🚀 A mongoose plugin to monetize your apis in few lines of code

Stripe Mongoose Api Stripe Mongoose Api is a Mongoose plugin that simplifies building checkout and payment system for apis with stripe. It will provid

Moscatelli Marco 13 Dec 29, 2022
Get the latest Flashbots blocks and Flashbots transactions using TypeScript in two lines of code !

mev-blocks-js This package can let you query the Flashbots blocks API easily from any JavaScript or TypeScript project. You can access the Flashbots b

Luca G.F. 6 May 14, 2022
Find out how many lines of code you have written for your project 📜

?? TLOC (Tomper Lines Of Code) Find out how many lines of code you have written for your project. ?? Installation (Install the package globally) npm i

Varun Tiwari 9 Oct 17, 2022