Hey there! Over the past weekend, our team at Cenit Finance joined forces with our friend Jesús Ligero and participated in the ETHGlobal Lisbon Hackathon (May 2023) earning us eight different sponsor prizes, including the “Most innovative dApp” prize from Gnosis Chain.
Our project for the hackathon was NaturalChain, an AI toolkit for the Blockchain. At Cenit, we’ve been keenly following the incredible progress of language models these past few months, which is revolutionizing the way humans interact with machines. With NaturalChain, we wanted to bring that revolution into our ecosystem by giving Blockchain superpowers to Large Language Models (LLMs) like ChatGPT.
Over the weekend, we developed an AI agent capable of signing transactions, writing and deploying Smart Contracts, querying from APIs like The Graph and CoinMarketCap, as well as utilizing the full JSON-RPC API. You can ask it to do things for you like:
Let us tell you all about it!
Over the past few months, Large Language Models have showcased astounding advancements. The combination of high quantities of data, parameter size, and computing power used during training, seems to result in the emergence of capabilities like reasoning and planning.
While many of us have been leveraging these capabilities to facilitate our daily lives and work, these models are limited to interaction through chat by default. They can answer our questions, but they can’t act directly. A possible solution to this is to teach the models to use tools with which to carry out our requests. OpenAI, the creators of ChatGPT, are already working on this with their release of ChatGPT plugins.
That is already a huge powerup for Large Language models, but we can go even further! LangChain is an up and coming Open Source framework for creating AI applications. Using it we can create our own tools for Large Language Models, and compose AI agents capable of using these tools.
This was our main objective with NaturalChain: bring natural language interactivity to the blockchain by creating tools that let Large Language Models like ChatGPT interact with the Blockchain and related applications.
Throughout this hackathon we managed to create 8 different tools for interaction between Large Language Models and blockchain. We had ideas for many more, but time was limited! Our main focus was on interactivity with EVM-compatible chains, since we were at ETHGlobal. The tools we developed were:
Besides the actual code to execute these functions, each tool includes a natural language description of its utility in order to let the model know what it is used for. We found that the model understood very easily how to use each of the individual tools, handling multiple input parameters and, in some cases, complex output syntax.
However, one of the main difficulties we encountered was how to make the model understand when to use one tool instead of another in a complex task flow. This required a lot of prompt engineering and interactive adjustment.
So, how did we actually set up the model to make use of these tools? We set up an agent, which essentially means wrapping the user’s query to the model with pre-set instructions indicating how to handle the request and teaching the model what tools it has at its disposal and how to use them.
There are two main types of agents that can make use of tools: action-agents, which decide on an action to take (i.e. calling a tool) one at a time, and plan-and-execute agents, which first decide on a plan to solve the user’s query, and then execute that plan one action at a time. We could implement either for NaturalChain, but we decided to go with action-agents for the hackathon, which are good for small tasks and faster to execute, since they require less calls to the language model.
In either case, each consecutive “decision” by the agent is actually a call to a Large Language Model. In our case we decided to use the ChatGPT 3.5 API, since it is fast, cheap, and readily available. However, since we are using the LangChain framework under the hood, switching out to a different model would be just plug and play with a different API.
The diagram below shows how the various elements interact.
By combining and chaining all of the various tools, the agent is capable of answering complex requests, like creating and deploying a smart contract as in our example above.
NaturalChain is designed as an extensible and composable framework for anyone to easily build their own tools and agents on top of. That said, we wanted to play with it ourselves! Therefore, for the hackathon we also created a very simple web app in Streamlit where we could interact with the agent using a chat interface, like ChatGPT.
Here is an example of that:
And you can see the resulting contract yourself here: https://sepolia.etherscan.io/address/0x5F75E6c3EAd39Ddbc8fE8Ba8Ce84EeA1D781FaC1
In conclusion, the future is bright for NaturalChain! Our experience at the ETHGlobal Lisbon Hackathon has solidified our belief that AI and Blockchain together have immense potential to revolutionize the way we interact with technology. We're not just talking about making things easier; we're talking about empowering individuals, fostering creativity, and unlocking new possibilities.
We're excited about the progress we've made, but we're even more thrilled about the road ahead. We envision NaturalChain evolving into a tool that not only simplifies blockchain interaction but also acts as a bridge connecting more people to this revolutionary technology.
We're eager to continue expanding and refining our toolkit, integrating more powerful models, and experimenting with a variety of agents. But we can't do it alone. We invite you to join us in our journey by trying out our demo at http://naturalchain.cenit.finance/ and contributing to our open-source code at https://github.com/miguel-bm/naturalchain.
In the meantime, we will continue leveraging these revolutionary tools in our own work modeling and stress-testing tokenomics at Cenit Finance. Stay tuned for more updates!