Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support llm precompile #1706

Closed
wants to merge 12 commits into from
Closed
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
4 changes: 4 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ import (

memiavlstore "github.com/crypto-org-chain/cronos/store"
"github.com/crypto-org-chain/cronos/v2/client/docs"
"github.com/crypto-org-chain/cronos/v2/llm"
"github.com/crypto-org-chain/cronos/v2/x/cronos"
cronosclient "github.com/crypto-org-chain/cronos/v2/x/cronos/client"
cronoskeeper "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper"
Expand Down Expand Up @@ -685,6 +686,9 @@ func New(
func(ctx sdk.Context, rules ethparams.Rules) vm.PrecompiledContract {
return cronosprecompiles.NewIcaContract(ctx, app.ICAControllerKeeper, &app.CronosKeeper, appCodec, gasConfig)
},
func(ctx sdk.Context, rules ethparams.Rules) vm.PrecompiledContract {
return cronosprecompiles.NewLLamaContract(gasConfig, llm.NewBuiltinModel())
},
},
)

Expand Down
13 changes: 13 additions & 0 deletions integration_tests/contracts/contracts/TestLLama.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {ILLamaModule} from "./src/LLama.sol";

contract TestLLama {
address constant llamaContract = 0x0000000000000000000000000000000000000067;
ILLamaModule llama = ILLamaModule(llamaContract);

function inference(string calldata prompt, int64 seed, int32 steps) public returns (string memory) {
return llama.inference(prompt, seed, steps);
}
}
14 changes: 14 additions & 0 deletions integration_tests/test_llama.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from .utils import ADDRS, CONTRACTS, deploy_contract, send_transaction


def test_call(cronos):
w3 = cronos.w3
addr = ADDRS["validator"]
contract = deploy_contract(w3, CONTRACTS["TestLLama"])
prompt = ""
seed = 2
steps = 256
data = {"from": addr, "gasPrice": w3.eth.gas_price, "gas": 600000}
tx = contract.functions.inference(prompt, seed, steps).build_transaction(data)
receipt = send_transaction(w3, tx)
assert receipt.status == 1
1 change: 1 addition & 0 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"TestICA": "TestICA.sol",
"Random": "Random.sol",
"TestRelayer": "TestRelayer.sol",
"TestLLama": "TestLLama.sol",
}


Expand Down
Loading
Loading