Skip to content

Commit 69c3e38

Browse files
committed
oxford hackathon
1 parent fdf8821 commit 69c3e38

File tree

10 files changed

+532
-2
lines changed

10 files changed

+532
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ paths.txt
66
.*.swp
77
.DS_Store
88
secret
9+
.mops
910

1011
# llama2 models
1112
stories15M.bin

ctrlb_canister/Makefile

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
SHELL := /bin/bash
2+
3+
# Disable built-in rules and variables
4+
MAKEFLAGS += --no-builtin-rules
5+
MAKEFLAGS += --no-builtin-variables
6+
7+
NETWORK ?= local
8+
DFX_WEBSERVER_PORT ?= $(shell dfx info webserver-port)
9+
IDENTITY ?= $(shell dfx identity whoami)
10+
11+
###########################################################################
12+
# Some constants
13+
CANISTER_INSTALL_MODE ?= install
14+
CANISTER_CANDID_UI_IC ?= "a4gq6-oaaaa-aaaab-qaa4q-cai"
15+
16+
# Some defaults
17+
CANISTER_NAME ?= ctrlb_canister
18+
19+
20+
.PHONY: dfx-cycles-to-canister
21+
dfx-cycles-to-canister:
22+
@$(eval CANISTER_ID := $(shell dfx canister --network ic id ctrlb_canister))
23+
@echo "-------------------------------------------------------------------------"
24+
@echo "dfx identity : $(IDENTITY)"
25+
@echo "- balance before: "
26+
@dfx wallet --network ic balance
27+
@echo "-------------------------------------------------------------------------"
28+
@echo "ctrlb_canister before : $(CANISTER_ID)"
29+
@dfx canister --network=ic status ctrlb_canister
30+
@echo "-------------------------------------------------------------------------"
31+
@echo "Sending 0.5T cycles to ctrlb_canister"
32+
dfx wallet --network ic send $(CANISTER_ID) 500000000000
33+
@echo "-------------------------------------------------------------------------"
34+
@echo "dfx identity : $(IDENTITY)"
35+
@echo "- balance after: "
36+
@dfx wallet --network ic balance
37+
@echo "-------------------------------------------------------------------------"
38+
@echo "ctrlb_canister after : $(CANISTER_ID)"
39+
@dfx canister --network=ic status ctrlb_canister
40+
41+
.PHONY: dfx-canisters-of-project-ic
42+
dfx-canisters-of-project-ic:
43+
@$(eval IDENTITY_PRINCIPAL := $(shell dfx identity --network ic get-principal))
44+
@$(eval IDENTITY_CYCLES_WALLET := $(shell dfx identity --network ic get-wallet))
45+
@$(eval IDENTITY_ICP_WALLET := $(shell dfx ledger --network ic account-id))
46+
@$(eval IDENTITY_ICP_BALANCE := $(shell dfx ledger --network ic balance))
47+
@$(eval crtlb_canister_ID := $(shell dfx canister --network ic id ctrlb_canister))
48+
49+
@echo '-------------------------------------------------'
50+
@echo "NETWORK : ic"
51+
@echo "dfx identity : $(IDENTITY)"
52+
@echo "identity's principal : $(IDENTITY_PRINCIPAL)"
53+
@echo "identity's cycles wallet : $(IDENTITY_CYCLES_WALLET)"
54+
@echo "identity's ICP wallet : $(IDENTITY_ICP_WALLET)"
55+
@echo "identity's ICP balance : $(IDENTITY_ICP_BALANCE)"
56+
@echo '-------------------------------------------------'
57+
@echo "identity's cycles wallet : $(IDENTITY_CYCLES_WALLET)"
58+
@echo "- balance: "
59+
@dfx wallet --network ic balance
60+
@echo "- status: "
61+
@dfx canister --network=ic status $(IDENTITY_CYCLES_WALLET)
62+
@echo '-------------------------------------------------'
63+
@echo "ctrlb_canister : $(crtlb_canister_ID)"
64+
@dfx canister --network=ic status ctrlb_canister
65+
@echo '-------------------------------------------------'
66+
@echo 'View in browser at:'
67+
@echo "identity's wallet : https://$(IDENTITY_CYCLES_WALLET).raw.ic0.app/"
68+
@echo "Candid UI : https://$(CANISTER_CANDID_UI_IC).raw.ic0.app/"
69+
70+
71+
.PHONY: dfx-wallet-details
72+
dfx-wallet-details:
73+
@$(eval IDENTITY_CYCLES_WALLET := $(shell dfx identity --network $(NETWORK) get-wallet))
74+
@echo "-------------------------------------------------------------------------"
75+
@echo "make dfx-wallet-details NETWORK=$(NETWORK)"
76+
@if [[ ${NETWORK} == "ic" ]]; then \
77+
echo "View details at : https://$(IDENTITY_CYCLES_WALLET).raw.ic0.app/"; \
78+
else \
79+
echo "View details at : ?? http://localhost:$(DFX_WEBSERVER_PORT)?canisterId=$(IDENTITY_CYCLES_WALLET) ?? "; \
80+
fi
81+
82+
@echo "-------------------------------------------------------------------------"
83+
@echo -n "cycles canister id : " && dfx identity --network $(NETWORK) get-wallet
84+
@echo -n "cycles canister name : " && dfx wallet --network $(NETWORK) name
85+
@echo -n "cycles canister balance : " && dfx wallet --network $(NETWORK) balance
86+
@echo "-------------------------------------------------------------------------"
87+
@echo "controllers: "
88+
@dfx wallet --network $(NETWORK) controllers
89+
@echo "-------------------------------------------------------------------------"
90+
@echo "custodians: "
91+
@dfx wallet --network $(NETWORK) custodians
92+
@echo "-------------------------------------------------------------------------"
93+
@echo "addresses: "
94+
@dfx wallet --network $(NETWORK) addresses
95+
96+
.PHONY: dfx-wallet-controller-add
97+
dfx-wallet-controller-add:
98+
@[ "${PRINCIPAL}" ] || ( echo ">> Define PRINCIPAL to add as controller: 'make dfx-cycles-controller-add PRINCIPAL=....' "; exit 1 )
99+
@echo "NETWORK : $(NETWORK)"
100+
@echo "PRINCIPAL : $(PRINCIPAL)"
101+
@dfx wallet --network $(NETWORK) add-controller $(PRINCIPAL)
102+
103+
.PHONY: dfx-wallet-controller-remove
104+
dfx-wallet-controller-remove:
105+
@[ "${PRINCIPAL}" ] || ( echo ">> Define PRINCIPAL to remove as controller: 'make dfx-cycles-controller-remove PRINCIPAL=....' "; exit 1 )
106+
@echo "NETWORK : $(NETWORK)"
107+
@echo "PRINCIPAL : $(PRINCIPAL)"
108+
@dfx wallet --network $(NETWORK) remove-controller $(PRINCIPAL)

ctrlb_canister/README.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# ctrlb_canister (Control & Load Balancer)
2+
3+
To bootstrap the code to be added to bioniq's launch canister
4+
5+
### Setup
6+
7+
Install mops (https://mops.one/docs/install)
8+
Install motoko dependencies:
9+
10+
```bash
11+
# from folder backend/ctrlb_canister:
12+
13+
mops install
14+
```
15+
16+
### Deploy
17+
18+
We assume you already have the `backend/llm_0` deployed, and the ctrlb_canister whitelisted.
19+
20+
Then you deploy the ctrlb_canister with:
21+
22+
```bash
23+
# from folder backend/ctrlb_canister:
24+
25+
# Activate the same python environment as you defined for deploying the LLMs
26+
# (This might not be needed, but I did it this way...)
27+
conda activate llama2_c
28+
29+
# Deploy, initialize and test it
30+
# WARNING: This will re-deploy the ctrlb_canister with loss of all existing data!
31+
scripts/deploy.sh --network [local/ic]
32+
```
33+
34+
### Test with dfx
35+
36+
```bash
37+
dfx canister call ctrlb_canister whoami
38+
39+
# Run with same identity used to deploy (as a controller)
40+
$ dfx canister call ctrlb_canister amiController
41+
(variant { Ok = record { status_code = 200 : nat16 } })
42+
43+
# This call checks if the ctrlb_canister is whitelisted in the llm_0
44+
$ dfx canister call ctrlb_canister isWhitelistLogicOk
45+
(variant { Ok = record { status_code = 200 : nat16 } })
46+
47+
# Call the Inference endpoint
48+
$ dfx canister call ctrlb_canister Inference '(record {prompt="Joe went swimming in the pool"; steps=30; temperature=0.1; topp=0.9; rng_seed=0})'
49+
(
50+
variant {
51+
Ok = record {
52+
token_id = "pklc3-dnt23-rylls-wtd3z-a4nod-5b6iu-gha67-4dj4k-uqzci-srgi5-6ae";
53+
story = "Joe went swimming in the pool. He saw a big, shiny rock. He wanted to swim in the sky. He wanted to swim in the sky. He wanted to swim in the sky.\nJohn wanted to swim in the sky. He wanted to swing on the rock. He put the rock in the rock and put it in his rock. He put it in his rock. He put it in his rock. He pulled the rock and pulled it.\nJohn was sad. He wanted to help the rock. He did not know what to do. He did not know what to do. He did not know what to do. He did not know what to do. He did not know what to do.\nJohn said, \"I want to play with you. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it. You can\'t find it.\"\nThey run to the house and find a new friend. They are happy. They played with their";
54+
prompt = record {
55+
temperature = 0.1 : float64;
56+
topp = 0.9 : float64;
57+
steps = 60 : nat64;
58+
rng_seed = 0 : nat64;
59+
prompt = "Joe went swimming in the pool";
60+
};
61+
}
62+
},
63+
)
64+
65+
# ----------------------------
66+
# Below is for NFT collection
67+
68+
# Update a story for an NFT
69+
$ dfx canister call ctrlb_canister NFTUpdate '(record {token_id="placeholder-0"})'
70+
```

ctrlb_canister/dfx.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 1,
3+
"canisters": {
4+
"ctrlb_canister": {
5+
"main": "src/Main.mo"
6+
}
7+
},
8+
"defaults": {
9+
"build": {
10+
"packtool": "mops sources"
11+
}
12+
}
13+
}

ctrlb_canister/mops.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[dependencies]
2+
base = "0.9.8"
3+
accountid = "https://github.com/aviate-labs/principal.mo#main"
4+
hex = "https://github.com/letmejustputthishere/motoko-hex#master"
5+
canistergeek = "https://github.com/usergeek/canistergeek-ic-motoko#v0.0.3"
6+
uuid = "https://github.com/aviate-labs/uuid.mo#v0.2.0"

0 commit comments

Comments
 (0)