lightninglabs / langchainbitcoin Goto Github PK
View Code? Open in Web Editor NEWAI tools for giving LangChain agents access to Bitcoin and the ability to traverse L402 APIs
AI tools for giving LangChain agents access to Bitcoin and the ability to traverse L402 APIs
Today we create a series of wrappers around the base set of lnd gRPC API endpoints. This works well for simple calls like addinvoice
that have simple inputs, but for other calls, we want to be able to give more context to the agent in form of a better input schema.
Some examples of this are here: https://python.langchain.com/docs/modules/agents/tools/how_to/tool_input_validation
As an example, consider the new_address
tool. The input is actually an enum of the address type with the following values: WITNESS_PUBKEY_HASH
, TAPROOT_PUBKEY
, etc, etc. We can define a more structred input that looks something like:
class AddrTypes(Enum):
TAPROOT_PUBKEY = 0
WITNESS_PUBKEY_HASH = 1
class NewAddrSchema(BaseModel):
addr_type: AddrTypes = Field("the type of address to create")
Then each time we use the @tool
decorator, we also pass the schema for the input like @tool(args_schema=NewAddrSchema
).
For other calls that need more arguments, like finding a route on LN to a dest, then we can use a similar pattern to be able to profile few-shot examples for each of the fields, and also validate them.
Running LangChainBitcoin now returns the below error...
“openai.error.InvalidRequestError: The model text-davinci-003
has been deprecated”
It seems that the version of LangChain being used needs to be updated. I was able to update the version of LangChain being used from 0.0.205 to 0.1.13. That change also required changes to several other dependencies.
Updated: langchain 0.0.205 → 0.1.13
Updated: openai 0.27.6 → 1.10.0,<2.0.0
Updated: packaging 23.1 → 23.2,<24.0
Updated: typing_extensions 4.5.0 → 4.7,<5
Changes: platformdirs 3.6.0 → 2.6.2
Added: langchain-openai 0.1.1
With these changes the requirements can be installed without error, and the program can be run without receiving the text-davinci-003 deprecated error, however, some of the context for the prompts has been lost.
The API documentation in API_DOCS is being understood, but the prompt given via chain_new.run() is not. It seems that chain_new.run should be updated to chain_new.invoke, but that there will be other changes needed as well.
I suspect that what is being imported in the l402_api_chain.py file will need to be updated as well, but I haven’t found the solution just yet.
As is, we can easily integrate any of the APIs that are exported by lnd defined here: https://lightning.engineering/api-docs/api/lnd/index.html.
This includes normal LN node operation, but also introspecting into the channel graph, and also fetching and parsing blocks.
Here're some additional tools we should start to expose:
Checking status of invoices: https://lightning.engineering/api-docs/api/lnd/invoices/lookup-invoice-v2
Tracking LN payment status: https://lightning.engineering/api-docs/api/lnd/router/track-payment-v2
Wallet activities like creating+funding+signing PSBTs: https://lightning.engineering/api-docs/category/walletkit-service
Making on chain payments: https://lightning.engineering/api-docs/api/lnd/lightning/send-coins
Scanning for confirmed transactions: https://lightning.engineering/api-docs/api/lnd/lightning/get-transactions
Watching for relevant on chain events: https://lightning.engineering/api-docs/category/chainnotifier-service
Fetching Bitcoin blocks + headers: https://lightning.engineering/api-docs/category/chainkit-service
Opening + closing channels: https://lightning.engineering/api-docs/api/lnd/lightning/open-channel
Extracting the LN graph: https://lightning.engineering/api-docs/api/lnd/lightning/describe-graph
Looking up info for a given node: https://lightning.engineering/api-docs/api/lnd/lightning/get-node-info
Looking up chan info: https://lightning.engineering/api-docs/api/lnd/lightning/get-chan-info
Obtaining a node's forwarding history: https://lightning.engineering/api-docs/api/lnd/lightning/forwarding-history
Updating routing policy for channels: https://lightning.engineering/api-docs/api/lnd/lightning/update-channel-policy
Estimating on chain fees: https://lightning.engineering/api-docs/api/lnd/lightning/estimate-fee
Baking macaroons for other agents: https://lightning.engineering/api-docs/api/lnd/lightning/bake-macaroon
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.