Dria Oracle Node serves LLM workflow tasks directly from smart-contracts.
Install Dria Oracle Node with:
cargo install --git https://github.com/firstbatchxyz/dria-oracle-node
Create an .env
file by copying .env.example
. You have to fill the following variables:
- Get an RPC URL from a provider such as Alchemy or Infura, and set it as
RPC_URL
. - Provide an Ethereum wallet secret key to
SECRET_KEY
, make sure it has funds to pay for gas and tokens.
Note
The contract addresses are determined with respect to the chain connected via RPC URL, but you can override it via COORDINATOR_ADDRESS
environment variable.
In any case, you should not need to do this.
You can save gas costs using Arweave:
- Provide an Arweave wallet via
ARWEAVE_WALLET_PATH
variable so that you can use Arweave for large results. You can create one here. - You can set
ARWEAVE_BYTE_LIMIT
to determine the byte length threshold, beyond which values are uploaded to Arweave. It defaults to 1024, so any data less than that many bytes will be written as-is.
If you omit Arweave, it will only use the client for downloading things from Arweave, but will never upload.
As for the LLM providers:
- If you are using Ollama, make sure it is running and the host & port are correct.
- If you are using OpenAI, provide the
OPENAI_API_KEY
. - If you are using Gemini, provide the
GEMINI_API_KEY
. - If you are using OpenRouter, provide the
OPENROUTER_API_KEY
.
After installatioon, a binary called dria-oracle
will be created. You can see the available commands with:
dria-oracle help
The CLI provides several methods to interact with the oracle contracts.
Tip
By default logs will be info
level, but you can add a DEBUG=1
env variable and it will use debug
level instead.
You can set RUST_LOG
variable yourself as well.
To serve oracle requests, you MUST first register as your desired oracle type, i.e. generator
or validator
. These are handled by the registration commands register
and unregister
which accepts multiple arguments to register at once. You can then see your registrations with registrations
command.
Here is an example:
# 1. Register as both generator and validator
dria-oracle register generator validator
# 2. See that you are registered
dria-oracle registrations
# 3. Unregister from validator
dria-oracle unregister validator
Note
You will need to have some tokens in your balance, which will be approved automatically if required by the register command.
We launch our node using the start
command, followed by models of our choice and the oracle type that we would like to serve.
If we provide no oracle types, it will default to the ones that we are registered to.
dria-oracle start -m=gpt-4o-mini -m=llama3.1:latest
You can terminate the application from the terminal as usual (e.g. CTRL+C) to quit the node.
To save from gas fees, an Oracle node can upload its response to Arweave and then store the transaction id of that upload to the contract instead. This is differentiated by looking at the response, and see that it is exactly 64 hexadecimal characters. It is then decoded from hex and encoded to base64url
format, which can then be used to access the data at https//arweave.net/{txid-here}
. This requires an Arweave wallet.
Following the same logic, the Oracle node can read task inputs from Arweave as well. This does not require an Arweave a wallet.
You can view the status of a task by its task id:
dria-oracle view <task-id>
You can also view the task status updates between blocks with the tasks
command.
It accepts --from
and --to
arguments to indicate block numbers or tags, defaults from earliest
block to latest
block.
dria-oracle tasks # earliest to latest
dria-oracle tasks --from=100 # 100 to latest
dria-oracle tasks --to=100 # earliest to 100
dria-oracle tasks --from=100 --to=200 # 100 to 200
At any time, you can see your balance with:
dria-oracle balance
As you respond to tasks, you will have rewards available to you. You can see & claim them using your node:
# print rewards
dria-oracle rewards
# claim all rewards
dria-oracle claim
Although the oracle is only supposed to serve requests made from other parties, it is also able to make requests from the CLI. See usage with the help option:
dria-oracle request -h
It mainly takes an input argument, followed by multiple model arguments:
dria-oracle request "What is 2+2?" gpt-4o-mini phi3:3.8b
The request
command takes the following options:
--difficulty
for the proof-of-work difficulty for oracles that are responding to this request; the higher this is the more fees it will take to make the request.--num-gens
number of generations requested.--num-vals
number of validations required per request.
Note
Making a request from the Oracle node is mainly for testing purposes, and you are not expected to use this command at all. Furthermore, it is only used to make plaintext requests, instead of larger ones via Arweave or more complex ones via Workflows.
There are 3 types of requests:
- String: simple text
- Chat: an object of the form
{history_id: number, content: string}
which uses a previous task as history; TODO: history > nextTaskId handled? - Workflow: a stringified Workflow object
If you would like to contribute, please create an issue first! To start developing, clone the repository:
git clone https://github.com/firstbatchxyz/dria-oracle-node.git
Run tests with:
make test
Note that the tests make use of existing contracts, accessed via their contract addresses. The blockchain is forked locally to Anvil and tests are executed over them. Always make sure that you are using the latest contract addresses at src/contracts/addresses.rs
.
This is especially important if you keep getting "execution reverted" for no reason!
You can view the inline documentation with:
make docs
Lint and format with:
make lint # clippy
make format # rustfmt
This project is licensed under the Apache License 2.0.