Skip to content

Commit

Permalink
Merge pull request #30 from arcmindai/dev
Browse files Browse the repository at this point in the history
Add cycles battery canister and update post_upgrade arguments for arcmindai_controller
  • Loading branch information
kinwo committed Apr 7, 2024
2 parents 0a99422 + fb37468 commit d8b1568
Show file tree
Hide file tree
Showing 19 changed files with 664 additions and 110 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
BEAMFI_PRINCIPAL: ${{ secrets.BEAMFI_PRINCIPAL }}
BILLING_KEY: ${{ secrets.BILLING_KEY }}
BATTERY_API_KEY: ${{ secrets.BATTERY_API_KEY }}
BATTERY_PRINCIAL: ${{ secrets.BATTERY_PRINCIAL }}
- name: Debug URL
run: echo https://completedeploy-4gbndkvjta-uc.a.run.app?apiKey=${{ secrets.FB_API_KEY }}&canisterId=${{ steps.provision.outputs.controller_principal }}
- name: Call Firebase Function /complete_deploy and assert HTTP status 200
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/local-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ jobs:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
BEAMFI_PRINCIPAL: ${{ secrets.BEAMFI_PRINCIPAL }}
BILLING_KEY: ${{ secrets.BILLING_KEY }}
BATTERY_API_KEY: ${{ secrets.BATTERY_API_KEY }}
BATTERY_PRINCIAL: ${{ secrets.BATTERY_PRINCIAL }}
- name: Show Controller Principal
run: echo ${{ steps.provision.outputs.controller_principal }}
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
members = [
"src/arcmindai_controller",
"src/arcmindai_brain",
"src/arcmindai_tools"
"src/arcmindai_tools",
"src/cycles_battery"
]

[profile.release]
Expand Down
27 changes: 17 additions & 10 deletions dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@
"canisters": {
"arcmindai_controller": {
"candid": "src/arcmindai_controller/arcmindai_controller.did",
"package": "arcmindai_controller",
"type": "rust",
"optimize": "cycles",
"gzip": true,
"declarations": {
"node_compatibility": true
}
},
"gzip": true,
"optimize": "cycles",
"package": "arcmindai_controller",
"type": "rust"
},
"arcmindai_brain": {
"candid": "src/arcmindai_brain/arcmindai_brain.did",
"package": "arcmindai_brain",
"type": "rust",
"gzip": true,
"optimize": "cycles",
"gzip": true
"package": "arcmindai_brain",
"type": "rust"
},
"arcmindai_tools": {
"candid": "src/arcmindai_tools/arcmindai_tools.did",
"gzip": true,
"optimize": "cycles",
"package": "arcmindai_tools",
"type": "rust",
"type": "rust"
},
"cycles_battery": {
"candid": "src/cycles_battery/cycles_battery.did",
"gzip": true,
"optimize": "cycles",
"gzip": true
"package": "cycles_battery",
"type": "rust"
}
},
"defaults": {
Expand Down
13 changes: 11 additions & 2 deletions scripts/deploy_controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ if [[ -z "${BILLING_KEY}" ]]; then
exit 1
fi

if [[ -z "${BATTERY_API_KEY}" ]]; then
echo "BATTERY_API_KEY is unset."
exit 1
fi

# To deplopy locally, update IC_NETWORK to local. To deploy to ic, update IC_NETWORK to ic.
IC_NETWORK=${IC_NETWORK:-local}

BRAIN_PRINCIPAL=$(dfx canister --network $IC_NETWORK id arcmindai_brain)
TOOLS_PRINCIPAL=$(dfx canister --network $IC_NETWORK id arcmindai_tools)
BATTERY_PRINCIAL=$(dfx canister --network $IC_NETWORK id cycles_battery)

BROWSE_WEBSITE_GPT_MODEL=gpt-3.5-turbo-1106

# Deploy controller canister
echo Deploying controller canister with owner=$OWNER_PRINCIPAL, brain=$BRAIN_PRINCIPAL, browse_website_gpt_model=$BROWSE_WEBSITE_GPT_MODEL, tools=$TOOLS_PRINCIPAL, VECTOR_PRINCIPAL=$VECTOR_PRINCIPAL, BEAMFI_PRINCIPAL=$BEAMFI_PRINCIPAL, BILLING_KEY=$BILLING_KEY on $IC_NETWORK
dfx deploy --network $IC_NETWORK arcmindai_controller --argument "(opt principal \"$OWNER_PRINCIPAL\", opt principal \"$BRAIN_PRINCIPAL\", opt principal \"$TOOLS_PRINCIPAL\", opt principal \"$VECTOR_PRINCIPAL\", opt principal \"$BEAMFI_PRINCIPAL\", opt \"$BROWSE_WEBSITE_GPT_MODEL\", opt \"$BILLING_KEY\")"
# echo Deploying controller canister with owner=$OWNER_PRINCIPAL, brain=$BRAIN_PRINCIPAL, browse_website_gpt_model=$BROWSE_WEBSITE_GPT_MODEL, tools=$TOOLS_PRINCIPAL, VECTOR_PRINCIPAL=$VECTOR_PRINCIPAL, BEAMFI_PRINCIPAL=$BEAMFI_PRINCIPAL, BATTERY_PRINCIAL=$BATTERY_PRINCIAL, BILLING_KEY=$BILLING_KEY, BATTERY_API_KEY=$BATTERY_API_KEY on $IC_NETWORK
# dfx deploy --network $IC_NETWORK --mode reinstall arcmindai_controller --argument "(opt principal \"$OWNER_PRINCIPAL\", opt principal \"$BRAIN_PRINCIPAL\", opt principal \"$TOOLS_PRINCIPAL\", opt principal \"$VECTOR_PRINCIPAL\", opt principal \"$BEAMFI_PRINCIPAL\", opt principal \"$BATTERY_PRINCIAL\", opt \"$BROWSE_WEBSITE_GPT_MODEL\", opt \"$BILLING_KEY\", opt \"$BATTERY_API_KEY\")"
echo Deploying controller canister BATTERY_PRINCIAL=$BATTERY_PRINCIAL, BATTERY_API_KEY=$BATTERY_API_KEY on $IC_NETWORK
dfx deploy --network $IC_NETWORK arcmindai_controller --argument "(opt principal \"$OWNER_PRINCIPAL\", opt principal \"$BRAIN_PRINCIPAL\", opt principal \"$TOOLS_PRINCIPAL\", opt principal \"$VECTOR_PRINCIPAL\", opt principal \"$BEAMFI_PRINCIPAL\", opt principal \"$BATTERY_PRINCIAL\", opt \"$BROWSE_WEBSITE_GPT_MODEL\", opt \"$BILLING_KEY\", opt \"$BATTERY_API_KEY\")"
19 changes: 19 additions & 0 deletions scripts/deploy_cycles_battery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Validate required env vars
if [[ -z "${CYCLES_BATTERY_API_KEY}" ]]; then
echo "CYCLES_BATTERY_API_KEY is unset."
exit 1
fi

if [[ -z "${OWNER_PRINCIPAL}" ]]; then
echo "OWNER_PRINCIPAL is unset."
exit 1
fi

# To deplopy locally, update IC_NETWORK to local. To deploy to ic, update IC_NETWORK to ic.
IC_NETWORK=${IC_NETWORK:-local}

# Deploy cycles battery canister
echo Deploying cycles battery canister with owner=$OWNER_PRINCIPAL api_key=$CYCLES_BATTERY_API_KEY on $IC_NETWORK
dfx deploy --network $IC_NETWORK cycles_battery --argument "(opt principal \"$OWNER_PRINCIPAL\", opt \"$CYCLES_BATTERY_API_KEY\")"
10 changes: 9 additions & 1 deletion scripts/ledger_sample.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ Account ID of principal o5uxz-byaaa-aaaah-adnyq-cai:


Please stream 0.01 ICP tokens to principal ID evdxs-el2wl-mrpaf-ehe75-uwoax-mqoc6-e55si-ls4va-gyecy-ywbio-bae
Please stream 0.01 ICP tokens to principal ID hpikg-6exdt-jn33w-ndty3-fc7jc-tl2lr-buih3-cs3y7-tftkp-sfp62-gqe


Please stream 0.01 ICP tokens to principal ID hpikg-6exdt-jn33w-ndty3-fc7jc-tl2lr-buih3-cs3y7-tftkp-sfp62-gqe
# Demo
# 1 ICP = 100_000_000
# 0.07731000 ICP = 7_731_000
# 0.05 = 5_000_000
dfx canister --network ic call nns-ledger icrc1_balance_of "(record {owner = principal \"wcz6z-niaaa-aaaah-adxzq-cai\"; })"
dfx canister --network ic call nns-ledger icrc1_transfer "(record { to = record { owner = principal \"wcz6z-niaaa-aaaah-adxzq-cai\";}; amount = 5_000_000;})"

# Please stream 0.01 ICP tokens to principal ID evdxs-el2wl-mrpaf-ehe75-uwoax-mqoc6-e55si-ls4va-gyecy-ywbio-bae
14 changes: 12 additions & 2 deletions scripts/provision-instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ if [[ -z "${BILLING_KEY}" ]]; then
exit 1
fi

if [[ -z "${BATTERY_API_KEY}" ]]; then
echo "BATTERY_API_KEY is unset."
exit 1
fi

if [[ -z "${BATTERY_PRINCIAL}" ]]; then
echo "BATTERY_PRINCIAL is unset."
exit 1
fi

GPT_MODEL=gpt-4
BROWSE_WEBSITE_GPT_MODEL=gpt-3.5-turbo-1106

Expand Down Expand Up @@ -72,8 +82,8 @@ dfx canister --network $IC_NETWORK call arcmindai_tools get_owner
TOOLS_PRINCIPAL=$(dfx canister --network $IC_NETWORK id arcmindai_tools)

# Deploy controller canister
echo Deploying controller canister with owner $OWNER_PRINCIPAL, brain $BRAIN_PRINCIPAL, tools $TOOLS_PRINCIPAL, vector $VECTOR_PRINCIPAL, beamfi $BEAMFI_PRINCIPAL, browse_website_gpt_model $BROWSE_WEBSITE_GPT_MODEL, billing_key $BILLING_KEY on $IC_NETWORK
dfx deploy --network $IC_NETWORK arcmindai_controller --argument "(opt principal \"$OWNER_PRINCIPAL\", opt principal \"$BRAIN_PRINCIPAL\", opt principal \"$TOOLS_PRINCIPAL\", opt principal \"$VECTOR_PRINCIPAL\", opt principal \"$BEAMFI_PRINCIPAL\", opt \"$BROWSE_WEBSITE_GPT_MODEL\", opt \"$BILLING_KEY\")"
echo Deploying controller canister with owner=$OWNER_PRINCIPAL, brain=$BRAIN_PRINCIPAL, browse_website_gpt_model=$BROWSE_WEBSITE_GPT_MODEL, tools=$TOOLS_PRINCIPAL, VECTOR_PRINCIPAL=$VECTOR_PRINCIPAL, BEAMFI_PRINCIPAL=$BEAMFI_PRINCIPAL, BATTERY_PRINCIAL=$BATTERY_PRINCIAL, BILLING_KEY=$BILLING_KEY, BATTERY_API_KEY=$BATTERY_API_KEY on $IC_NETWORK
dfx deploy --network $IC_NETWORK arcmindai_controller --argument "(opt principal \"$OWNER_PRINCIPAL\", opt principal \"$BRAIN_PRINCIPAL\", opt principal \"$TOOLS_PRINCIPAL\", opt principal \"$VECTOR_PRINCIPAL\", opt principal \"$BEAMFI_PRINCIPAL\", opt principal \"$BATTERY_PRINCIAL\", opt \"$BROWSE_WEBSITE_GPT_MODEL\", opt \"$BILLING_KEY\", opt \"$BATTERY_API_KEY\")"

echo Controller Owner:
dfx canister --network $IC_NETWORK call arcmindai_controller get_owner
Expand Down
82 changes: 0 additions & 82 deletions scripts/provision.sh

This file was deleted.

16 changes: 16 additions & 0 deletions scripts/topup-canisters.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# To deplopy locally, update IC_NETWORK to local. To deploy to ic, update IC_NETWORK to ic.
IC_NETWORK=${IC_NETWORK:-local}

# Validate required env vars
if [[ -z "${CYCLES_BATTERY_API_KEY}" ]]; then
echo "CYCLES_BATTERY_API_KEY is unset."
exit 1
fi

GROUP_NAME="test"
REQ_CYCLES_AMOUNT=1000000
CYCLES_BALANCE=3100000000000


echo Calling cycles battery canister with GROUP_NAME=$GROUP_NAME CYCLES_BATTERY_API_KEY=$CYCLES_BATTERY_API_KEY, REQ_CYCLES_AMOUNT=$REQ_CYCLES_AMOUNT, CYCLES_BALANCE=$CYCLES_BALANCE on $IC_NETWORK
dfx canister --network $IC_NETWORK call cycles_battery topup_cycles "(\"$GROUP_NAME\", \"$CYCLES_BATTERY_API_KEY\", $REQ_CYCLES_AMOUNT, $CYCLES_BALANCE)"
4 changes: 4 additions & 0 deletions src/arcmindai_controller/arcmindai_controller.did
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ service : (
opt principal,
opt principal,
opt principal,
opt principal,
opt text,
opt text,
opt text,
) -> {
check_cycles_and_topup : () -> ();
clear_all_goals : () -> ();
cycles_used : () -> (nat64) query;
get_battery_canister : () -> (opt principal) query;
get_beamfi_canister : () -> (opt principal) query;
get_brain_canister : () -> (opt principal) query;
get_chathistory : () -> (vec ChatHistory) query;
Expand Down
Loading

0 comments on commit d8b1568

Please sign in to comment.