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

feat: charge a small SUI token fee per inference #80

Open
wants to merge 6 commits into
base: alpha
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions sui/packages/atoma/sources/db.move
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ module atoma::db {
/// We perform cross validation when the user does not specify how many
/// nodes to sampled.
/// See `gate` and `settlement` modules for more info.
const InitialCrossValidationProbabilityPermille: u64 = 500;
const InitialCrossValidationProbabilityPermille: u64 = 10;
/// How many extra nodes to sample when cross validating.
const InitialCrossValidationExtraNodesCount: u64 = 10;
const InitialCrossValidationExtraNodesCount: u64 = 1;

/// To be able to identify the errors faster in the logs, we start the
/// counter from a number that's leet for "error_000".
Expand Down
4 changes: 2 additions & 2 deletions sui/packages/atoma/sources/gate.move
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module atoma::gate {
model: ascii::String,
pre_prompt_tokens: vector<u32>,
prepend_output_with_input: bool,
prompt: string::String,
prompt: vector<u8>,
random_seed: u64,
repeat_last_n: u64,
/// Represents a floating point number, little endian.
Expand Down Expand Up @@ -256,7 +256,7 @@ module atoma::gate {
model: ascii::String,
pre_prompt_tokens: vector<u32>,
prepend_output_with_input: bool,
prompt: string::String,
prompt: vector<u8>,
random_seed: u64,
repeat_last_n: u64,
repeat_penalty: u32,
Expand Down
65 changes: 9 additions & 56 deletions sui/packages/atoma/sources/prompts.move
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ module atoma::prompts {
use sui::random::Random;
use toma::toma::TOMA;

const ATOMA_FEE: u64 = 500_000_000; // 0.5 SUI
const ATOMA_FEE_RECIPIENT: address = @0x738146acb89851fc7e98a8148753b141155ef6a12aa2c32405aca8952c775040; // TODO: only for testing
const EInsufficientFee: u64 = 312012_200;

/// Submits an arbitrary text prompt.
/// The other alternative is to use programmable txs on client.
Expand All @@ -33,7 +36,7 @@ module atoma::prompts {
pre_prompt_tokens: vector<u32>,
prepend_output_with_input: bool,
max_fee_per_token: u64,
prompt: string::String,
prompt: vector<u8>,
should_stream_output: bool,
max_tokens: u64,
repeat_last_n: u64,
Expand All @@ -43,59 +46,15 @@ module atoma::prompts {
top_p: u32,
nodes_to_sample: Option<u64>,
random: &Random,
payment: &mut Coin<TOMA>,
ctx: &mut TxContext,
) {
let mut rng = random.new_generator(ctx);
let random_seed = rng.generate_u64();
let params = atoma::gate::create_text2text_prompt_params(
max_tokens,
model,
pre_prompt_tokens,
prepend_output_with_input,
prompt,
random_seed,
repeat_last_n,
repeat_penalty,
should_stream_output,
temperature,
top_k,
top_p,
);
atoma::gate::submit_text2text_prompt(
atoma,
wallet.balance_mut(),
params,
max_fee_per_token,
nodes_to_sample,
output_destination,
random,
ctx,
);
}
assert!(payment.value() >= ATOMA_FEE, EInsufficientFee);
let fee = sui::coin::split(payment, ATOMA_FEE, ctx);
sui::transfer::public_transfer(fee, ATOMA_FEE_RECIPIENT);

/// Submits a text prompt to Atoma network that asks for a joke.
entry fun tell_me_a_joke(
atoma: &mut AtomaDb,
wallet: &mut Coin<TOMA>,
model: ascii::String,
output_destination: vector<u8>,
max_fee_per_token: u64,
random: &Random,
ctx: &mut TxContext,
) {
let mut rng = random.new_generator(ctx);

let max_tokens = 64;
let pre_prompt_tokens = vector::empty();
let prepend_output_with_input = false;
let prompt = string::utf8(b"Tell me a joke please");
let random_seed = rng.generate_u64();
let repeat_last_n = 1;
let repeat_penalty = 1066192077; // 1.1
let should_stream_output = false;
let temperature = 1048576000; // 0.25
let top_k = 1;
let top_p = 1063675494; // 0.9
let params = atoma::gate::create_text2text_prompt_params(
max_tokens,
model,
Expand All @@ -115,13 +74,7 @@ module atoma::prompts {
wallet.balance_mut(),
params,
max_fee_per_token,
// we sample just one node because of the illustrative purposes of
// this prompt, so that we can deploy this contract on devnet and
// have it produce output without many nodes
//
// you can set this to none to let Atoma network decide how many
// nodes to sample
option::some(1),
nodes_to_sample,
output_destination,
random,
ctx,
Expand Down