Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function runZKInference() public {

// Extract and use model output
if (output.is_simulation_result == false) {
TensorLib.Number prediction = output.numbers[0].values[0];
TensorLib.Number memory prediction = output.numbers[0].values[0];
// Use prediction in your business logic...
}
}
Expand Down Expand Up @@ -132,19 +132,20 @@ function getPrediction(string memory _base, string memory _quote, uint32 _total_
base: _base,
quote: _quote,
total_candles: _total_candles,
candle_duration_in_mins: 1,
order: CandleOrder.Ascending,
candle_types: candles
});

// Execute inference using historical data
ModelOutput memory output = OG_HISTORICAL_CONTRACT.runHistoricalInference(
ModelOutput memory output = OG_HISTORICAL_CONTRACT.runInferenceOnPriceFeed(
"QmcLzTJ6yWF5wgW2CAkhNyJ5Tj2sb7YxkeXVVxo3WNW315",
"open_high_low_close",
input);

// Handle result
if (output.is_simulation_result == false) {
TensorLib.Number prediction = output.numbers[0].values[0];
TensorLib.Number memory prediction = output.numbers[0].values[0];
// Use prediction...
}
}
Expand All @@ -171,8 +172,8 @@ The OpenGradient Network is an EVM chain compatible with most existing EVM frame

## Learn More

- [**Model Hub**](hub.opengradient.ai): Browse available models
- [**Docs**](docs.opengradient.ai): Official docs
- [**Model Hub**](https://hub.opengradient.ai): Browse available models
- [**Docs**](https://docs.opengradient.ai): Official docs

## Contributing

Expand Down
11 changes: 8 additions & 3 deletions examples/run_historical.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
pragma solidity ^0.8.18;

import "../src/interfaces/OGHistorical.sol";
import "../lib/TensorLib.sol";
import "../src/lib/TensorLib.sol";

contract HistoricalInference {
TensorLib.Number[] public results;
TensorLib.Number public resultNumber;

function queryCandlesPrice(string memory _base, string memory _quote, uint32 _total_candles) public{
CandleType[] memory candles = new CandleType[](4);
candles[0]=CandleType.Open;
Expand All @@ -16,6 +19,7 @@ contract HistoricalInference {
base: _base,
quote: _quote,
total_candles: _total_candles,
candle_duration_in_mins: 1,
order: CandleOrder.Ascending, // Choose Ascending or descending timestamps for candles
candle_types: candles
});
Expand All @@ -39,15 +43,16 @@ contract HistoricalInference {
base: _base,
quote: _quote,
total_candles: _total_candles,
candle_duration_in_mins: 1,
order: CandleOrder.Ascending, // Choose Ascending or descending timestamps for candles
candle_types: candles
});

// execute inference
ModelOutput memory output = OG_HISTORICAL_CONTRACT.runHistoricalInference(
ModelOutput memory output = OG_HISTORICAL_CONTRACT.runInferenceOnPriceFeed(
"QmcLzTJ6yWF5wgW2CAkhNyJ5Tj2sb7YxkeXVVxo3WNW315",
"open_high_low_close",
input_query);
input);

// handle result
if (output.is_simulation_result == false) {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/OGHistorical.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "../lib/TensorLib.sol";
/// @dev The OGHistorical contract's address.
address constant OG_HISTORICAL_ADDRESS = 0x00000000000000000000000000000000000000F5;

/// @dev The OGInference contract's instance.
/// @dev The OGHistorical contract's instance.
OGHistorical constant OG_HISTORICAL_CONTRACT = OGHistorical(OG_HISTORICAL_ADDRESS);

enum CandleOrder {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/OGInference.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.18;

import "../lib/TensorLib.sol";

/// @dev The OGInfernece contract's address.
/// @dev The OGInference contract's address.
address constant OG_INFERENCE_ADDRESS = 0x00000000000000000000000000000000000000F4;

/// @dev The OGInference contract's instance.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/TensorLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ library TensorLib {
uint256 multiplier = 1;

for (uint256 i = shape.length; i > 0; i--) {
require(indices[i-1] >= 0 && indices[i-1] < shape[i-1], "Index out of bounds");
require(indices[i-1] < shape[i-1], "Index out of bounds");
flatIndex += uint256(indices[i-1]) * multiplier;
multiplier *= uint256(shape[i-1]);
}
Expand Down