Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
A vision initiated by ORA


In this section, we provide a list of educational tutorials, that will help you get started with Onchain AI Oracle (OAO).
ai/fi = AI + DeFi
Permissionless Technology for AI x Crypto
Usage Guide for Anyone to Use Onchain AI Directly as User
Initial Model Offering












constructor(IAIOracle _aiOracle) AIOracleCallbackReceiver(_aiOracle) {}function aiOracleCallback(uint256 requestId, bytes calldata output, bytes calldata callbackData) external override onlyAIOracleCallback()aiOracle.requestCallback(modelId, input, address(this), gas_limit, callbackData);


Frequently Asked Questions
ssh-keygen -t rsa -b 4096 -C "[email protected]"docker build -t ubuntu-opml-dev .git clone [email protected]:OPML-Labs/mlgo.gitcd mlgopip install -r requirements.txtcd examples/mnistpython3 convert-h5-to-ggml.py models/mnist/mnist-small.state_dictcd ../mnist_mips && ./build.sh# How to run instructions:
# 1. Generate ssh command: ssh-keygen -t rsa -b 4096 -C "[email protected]"
# - Save the key in local repo where Dockerfile is placed as id_rsa
# - Add the public key to the GitHub account
# 2. Build docker image: docker build -t ubuntu-opml-dev .
# 3. Run the hardhat: docker run -it --rm --name ubuntu-opml-dev-container ubuntu-opml-dev bash -c "npx hardhat node"
# 4. Run the challange script on the same container: docker exec -it ubuntu-opml-dev-container bash -c "./demo/challenge_simple.sh"
# Use an official Ubuntu as a parent image
FROM ubuntu:22.04# Set environment variables to non-interactive to avoid prompts during package installations
ENV DEBIAN_FRONTEND=noninteractive
# Update the package list and install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
cmake \
git \
golang \
wget \
curl \
python3 \
python3-pip \
python3-venv \
unzip \
file \
openssh-client \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install Node.js and npm
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -y nodejs# Copy SSH keys into the container
COPY id_rsa /root/.ssh/id_rsa
RUN chmod 600 /root/.ssh/id_rsa
# Configure SSH to skip host key verification
RUN echo "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config# Set the working directory
WORKDIR /root
# Clone the OPML repository
RUN git clone [email protected]:ora-io/opml.git --recursive
WORKDIR /root/opml# Build the OPML project
RUN make build
# Change permission for the challenge script
RUN chmod +x demo/challenge_simple.sh
# Default command
CMD ["bash"]docker run -it --rm --name ubuntu-opml-dev-container ubuntu-opml-dev bash -c "npx hardhat node"docker exec -it ubuntu-opml-dev-container bash -c "./demo/challenge_simple.sh"





forge script script/Prompt.s.sol --rpc-url $RPC_URL --broadcast --verify --etherscan-api-key $ETHERSCAN_KEYgit clone -b OAO_interaction_tutorial [email protected]:ora-io/Interaction_With_OAO_Template.git --recursivecd Interaction_With_OAO_Templatecp .env.example .envforge installimport "OAO/contracts/interfaces/IAIOracle.sol";
import "OAO/contracts/AIOracleCallbackReceiver.sol";constructor(IAIOracle _aiOracle) AIOracleCallbackReceiver(_aiOracle){}function calculateAIResult(uint256 modelId, string calldata prompt) payable external {
bytes memory input = bytes(prompt);
bytes memory callbackData = bytes("");
address callbackAddress = address(this);
uint256 requestId = aiOracle.requestCallback{value: msg.value}(
modelId, input, callbackAddress, callbackGasLimit[modelId], callbackData
);
}address owner;
modifier onlyOwner() {
require(msg.sender == owner, "Only owner");
_;
}
mapping(uint256 => uint64) public callbackGasLimit;
function setCallbackGasLimit(uint256 modelId, uint64 gasLimit) external onlyOwner {
callbackGasLimit[modelId] = gasLimit;
}
constructor(IAIOracle _aiOracle) AIOracleCallbackReceiver(_aiOracle) {
owner = msg.sender;
callbackGasLimit[50] = 500_000; // Stable-Diffusion
callbackGasLimit[11] = 5_000_000; // Llama
}event promptRequest(
uint256 requestId,
address sender,
uint256 modelId,
string prompt
);
struct AIOracleRequest {
address sender;
uint256 modelId;
bytes input;
bytes output;
}
mapping(uint256 => AIOracleRequest) public requests;
function calculateAIResult(uint256 modelId, string calldata prompt) payable external {
bytes memory input = bytes(prompt);
bytes memory callbackData = bytes("");
address callbackAddress = address(this);
uint256 requestId = aiOracle.requestCallback{value: msg.value}(
modelId, input, callbackAddress, callbackGasLimit[modelId], callbackData
);
AIOracleRequest storage request = requests[requestId];
request.input = input;
request.sender = msg.sender;
request.modelId = modelId;
emit promptRequest(requestId, msg.sender, modelId, prompt);
}event promptsUpdated(
uint256 requestId,
uint256 modelId,
string input,
string output,
bytes callbackData
);
mapping(uint256 => mapping(string => string)) public prompts;
function getAIResult(uint256 modelId, string calldata prompt) external view returns (string memory) {
return prompts[modelId][prompt];
}
function aiOracleCallback(uint256 requestId, bytes calldata output, bytes calldata callbackData) external override onlyAIOracleCallback() {
AIOracleRequest storage request = requests[requestId];
require(request.sender != address(0), "request does not exist");
request.output = output;
prompts[request.modelId][string(request.input)] = string(output);
emit promptsUpdated(requestId, request.modelId, string(request.input), string(output), callbackData);
}function estimateFee(uint256 modelId) public view returns (uint256) {
return aiOracle.estimateFee(modelId, callbackGasLimit[modelId]);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "OAO/contracts/interfaces/IAIOracle.sol";
import "OAO/contracts/AIOracleCallbackReceiver.sol";
contract Prompt is AIOracleCallbackReceiver {
event promptsUpdated(
uint256 requestId,
uint256 modelId,
string input,
string output,
bytes callbackData
);
event promptRequest(
uint256 requestId,
address sender,
uint256 modelId,
string prompt
);
struct AIOracleRequest {
address sender;
uint256 modelId;
bytes input;
bytes output;
}
address owner;
modifier onlyOwner() {
require(msg.sender == owner, "Only owner");
_;
}
mapping(uint256 => AIOracleRequest) public requests;
mapping(uint256 => uint64) public callbackGasLimit;
constructor(IAIOracle _aiOracle) AIOracleCallbackReceiver(_aiOracle) {
owner = msg.sender;
callbackGasLimit[50] = 500_000; // Stable-Diffusion
callbackGasLimit[11] = 5_000_000; // Llama
}
function setCallbackGasLimit(uint256 modelId, uint64 gasLimit) external onlyOwner {
callbackGasLimit[modelId] = gasLimit;
}
mapping(uint256 => mapping(string => string)) public prompts;
function getAIResult(uint256 modelId, string calldata prompt) external view returns (string memory) {
return prompts[modelId][prompt];
}
function aiOracleCallback(uint256 requestId, bytes calldata output, bytes calldata callbackData) external override onlyAIOracleCallback() {
AIOracleRequest storage request = requests[requestId];
require(request.sender != address(0), "request does not exist");
request.output = output;
prompts[request.modelId][string(request.input)] = string(output);
emit promptsUpdated(requestId, request.modelId, string(request.input), string(output), callbackData);
}
function estimateFee(uint256 modelId) public view returns (uint256) {
return aiOracle.estimateFee(modelId, callbackGasLimit[modelId]);
}
function calculateAIResult(uint256 modelId, string calldata prompt) payable external {
bytes memory input = bytes(prompt);
bytes memory callbackData = bytes("");
address callbackAddress = address(this);
uint256 requestId = aiOracle.requestCallback{value: msg.value}(
modelId, input, callbackAddress, callbackGasLimit[modelId], callbackData
);
AIOracleRequest storage request = requests[requestId];
request.input = input;
request.sender = msg.sender;
request.modelId = modelId;
emit promptRequest(requestId, msg.sender, modelId, prompt);
}
}source .env// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {Script} from "forge-std/Script.sol";
import {Prompt} from "../src/Prompt.sol";
import {IAIOracle} from "OAO/contracts/interfaces/IAIOracle.sol";
contract PromptScript is Script {
address OAO_PROXY;
function setUp() public {
OAO_PROXY = [OAO_PROXY_address_here];
}
function run() public {
uint privateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(privateKey);
new Prompt(IAIOracle(OAO_PROXY));
vm.stopBroadcast();
}
}






