• Stars
    star
    128
  • Rank 279,439 (Top 6 %)
  • Language
    Python
  • Created over 1 year ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

AI tools for giving LangChain agents access to Bitcoin and the ability to traverse L402 APIs

LangChainBitcoin

LangChainBitcoin is a suite of tools that enables langchain agents to directly interact with Bitcoin and also the Lightning Network. This package has two main features:

  • LLM Agent BitcoinTools: Using the newly available Open AP GPT-3/4 function calls and the built in set of abstractions for tools in langchain, users can create agents that are capaable of holding Bitcoin balance (on-chain and on LN), sending/receiving Bitcoin on LN, and also generally interacting with a Lightning node (lnd).

  • L402 HTTP API Traversal: LangChainL402 is a Python project that enables users of the requests package to easily navigate APIs that require L402 based authentication. This project also includes a LangChain APIChain compatible wrapper that enables LangChain agents to interact with APIs that require L402 for payment or authentication. This enables agents to access real-world resources behind a Lightning metered API.

Features

  • Provides a wrapper around requests library to handle LSATs and Lightning payments.

  • Easily integrates with APIs requiring L402-based authentication.

  • Designed to operate seamlessly with LND (Lightning Network Daemon).

  • Enables LangChain Agents traverse APIs that require L402 authentication within an API Chain.

  • Generic set of Bitcoin tools giving agents the ability to hold and use the Internet's native currency.

Installation

To install the LangChainL402 project, you can clone the repository directly from GitHub:

git clone https://github.com/lightninglabs/LangChainBitcoin.git
cd LangChainBitcoin

Please ensure you have all the necessary Python dependencies installed. You can install them using pip:

pip install -r requirements.txt

Usage

LLM Agent Bitcoin Tools

Check out the contained Jupyter notebook for an interactive example you can run/remix: LLM Bitcoin Tools.

L402 API Traversal

Check out the contained Jupyter notebook for an interactive example you can run/remix: LangChain402.

This project provides classes to handle Lightning payments (e.g., LndNode, LightningNode) and to manage HTTP requests with L402-based authentication (RequestsL402Wrapper, ResponseTextWrapper).

First, initialize the LndNode with your Lightning node's details. Then, you can use the modified L402APIChain wrapper around the normal APIChain class to instantiate an L402-aware API Chain. If the server responds with a 402 Payment Required status code, the library will automatically handle the payment and retry the request.

Here is a basic example:

import requests

from lightning import LndNode

from l402_api_chain import L402APIChain
from langchain.llms import OpenAI

# Initialize LndNode
lnd_node = LndNode(
    cert_path='path/to/tls.cert',
    macaroon_path='path/to/admin.macaroon',
    host='localhost',
    port=10018
)

# You can also use this with an API Chain instance like so:
llm = OpenAI(temperature=0)
chain_new = L402APIChain.from_llm_and_api_docs(
        llm, API_DOCS, lightning_node=lnd_node, verbose=True,
)

# Swap our the default wrapper with our L402 aware wrapper.
chain_new.requests_wrapper = lang_chain_request_L402

output = chain_new.run('LLM query here')
print(output)

More Repositories

1

lightning-app

An easy-to-use cross-platform Lightning wallet
JavaScript
901
star
2

neutrino

Privacy-Preserving Bitcoin Light Client
Go
899
star
3

loop

Lightning Loop: A Non-Custodial Off/On Chain Bridge
Go
546
star
4

lightning-terminal

Lightning Terminal: Your Home for Lightning Liquidity
Go
499
star
5

taproot-assets

A layer 1 daemon, for the Taproot Assets Protocol specification, written in Go (golang)
Go
457
star
6

pool

Lightning Pool: a non-custodial batched uniform clearing-price auction for Lightning Channel Leases (LCL). An LCL packages up inbound channel liquidity (ability to receive funds) as a fixed income asset with a maturity date expressed in blocks.
Go
253
star
7

aperture

โšก๏ธL402 (Lightning HTTP 402) Reverse Proxy โšก๏ธ
Go
233
star
8

chantools

A loose collection of tools all somehow related to lnd and Lightning Network channels.
Go
219
star
9

lndmon

๐Ÿ”Žlndmon: A drop-in monitoring solution for your lnd node using Prometheus+Grafana
Go
151
star
10

faraday

Lightning Channel Management & Optimization Tool
Go
130
star
11

lightning-node-connect

Go
78
star
12

L402

lsat protocol specification
71
star
13

lightning-faucet

A faucet for the Lightning Network!
Go
71
star
14

lightning-coindesk

A tutorial news app exemplifying Lightning Network micropayments integration
Python
54
star
15

docs.lightning.engineering

Building lapps, running lnd, and more
Markdown
50
star
16

lndclient

Golang client library for lnd
Go
48
star
17

lnc-web

Lightning Node Connect npm module for web
TypeScript
48
star
18

lightning-api

JavaScript
35
star
19

falafel

Go tool to generate go APIs for gRPC services for use on mobile/WASM platforms.
Go
34
star
20

lndinit

cloud infra tooling for lnd provisioning/unlocking
Go
26
star
21

lightning-dev-site

Lightning Network Daemon Developer Site
CSS
25
star
22

builders-guide-sample-app

TypeScript
14
star
23

lightninglabs.github.io

CSS
13
star
24

pool-paper

Lightning Pool: A Non-Custodial Channel Lease Marketplace
TeX
11
star
25

chanleakcheck

A tool to check if your lnd node was targeted by CVE-2019-12999
Go
10
star
26

lnc-rn

Lightning Node Connect npm module for React Native
TypeScript
8
star
27

lnc-core

Type definitions and utilities for Lightning Node Connect, leveraged by lnc-web and lnc-rn
TypeScript
7
star
28

dust-tool

dust exposure tool
Go
6
star
29

lightning-api-ng

Automated API-documentation generation source code for Lightning Lab's FOSS software suite
Go
5
star
30

lnd-fuzz

Shell
3
star
31

gh-actions

Vendored GitHub Action scripts
TypeScript
3
star
32

aezeedcheck

A offline CLI that allows one to verify their aezeed mnemonic
Go
2
star