Skip to content

Commit

Permalink
oxford hackathon
Browse files Browse the repository at this point in the history
  • Loading branch information
icppWorld committed Apr 19, 2024
1 parent fdf8821 commit 69c3e38
Show file tree
Hide file tree
Showing 10 changed files with 532 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ paths.txt
.*.swp
.DS_Store
secret
.mops

# llama2 models
stories15M.bin
Expand Down
108 changes: 108 additions & 0 deletions ctrlb_canister/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
SHELL := /bin/bash

# Disable built-in rules and variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables

NETWORK ?= local
DFX_WEBSERVER_PORT ?= $(shell dfx info webserver-port)
IDENTITY ?= $(shell dfx identity whoami)

###########################################################################
# Some constants
CANISTER_INSTALL_MODE ?= install
CANISTER_CANDID_UI_IC ?= "a4gq6-oaaaa-aaaab-qaa4q-cai"

# Some defaults
CANISTER_NAME ?= ctrlb_canister


.PHONY: dfx-cycles-to-canister
dfx-cycles-to-canister:
@$(eval CANISTER_ID := $(shell dfx canister --network ic id ctrlb_canister))
@echo "-------------------------------------------------------------------------"
@echo "dfx identity : $(IDENTITY)"
@echo "- balance before: "
@dfx wallet --network ic balance
@echo "-------------------------------------------------------------------------"
@echo "ctrlb_canister before : $(CANISTER_ID)"
@dfx canister --network=ic status ctrlb_canister
@echo "-------------------------------------------------------------------------"
@echo "Sending 0.5T cycles to ctrlb_canister"
dfx wallet --network ic send $(CANISTER_ID) 500000000000
@echo "-------------------------------------------------------------------------"
@echo "dfx identity : $(IDENTITY)"
@echo "- balance after: "
@dfx wallet --network ic balance
@echo "-------------------------------------------------------------------------"
@echo "ctrlb_canister after : $(CANISTER_ID)"
@dfx canister --network=ic status ctrlb_canister

.PHONY: dfx-canisters-of-project-ic
dfx-canisters-of-project-ic:
@$(eval IDENTITY_PRINCIPAL := $(shell dfx identity --network ic get-principal))
@$(eval IDENTITY_CYCLES_WALLET := $(shell dfx identity --network ic get-wallet))
@$(eval IDENTITY_ICP_WALLET := $(shell dfx ledger --network ic account-id))
@$(eval IDENTITY_ICP_BALANCE := $(shell dfx ledger --network ic balance))
@$(eval crtlb_canister_ID := $(shell dfx canister --network ic id ctrlb_canister))

@echo '-------------------------------------------------'
@echo "NETWORK : ic"
@echo "dfx identity : $(IDENTITY)"
@echo "identity's principal : $(IDENTITY_PRINCIPAL)"
@echo "identity's cycles wallet : $(IDENTITY_CYCLES_WALLET)"
@echo "identity's ICP wallet : $(IDENTITY_ICP_WALLET)"
@echo "identity's ICP balance : $(IDENTITY_ICP_BALANCE)"
@echo '-------------------------------------------------'
@echo "identity's cycles wallet : $(IDENTITY_CYCLES_WALLET)"
@echo "- balance: "
@dfx wallet --network ic balance
@echo "- status: "
@dfx canister --network=ic status $(IDENTITY_CYCLES_WALLET)
@echo '-------------------------------------------------'
@echo "ctrlb_canister : $(crtlb_canister_ID)"
@dfx canister --network=ic status ctrlb_canister
@echo '-------------------------------------------------'
@echo 'View in browser at:'
@echo "identity's wallet : https://$(IDENTITY_CYCLES_WALLET).raw.ic0.app/"
@echo "Candid UI : https://$(CANISTER_CANDID_UI_IC).raw.ic0.app/"


.PHONY: dfx-wallet-details
dfx-wallet-details:
@$(eval IDENTITY_CYCLES_WALLET := $(shell dfx identity --network $(NETWORK) get-wallet))
@echo "-------------------------------------------------------------------------"
@echo "make dfx-wallet-details NETWORK=$(NETWORK)"
@if [[ ${NETWORK} == "ic" ]]; then \
echo "View details at : https://$(IDENTITY_CYCLES_WALLET).raw.ic0.app/"; \
else \
echo "View details at : ?? http://localhost:$(DFX_WEBSERVER_PORT)?canisterId=$(IDENTITY_CYCLES_WALLET) ?? "; \
fi

@echo "-------------------------------------------------------------------------"
@echo -n "cycles canister id : " && dfx identity --network $(NETWORK) get-wallet
@echo -n "cycles canister name : " && dfx wallet --network $(NETWORK) name
@echo -n "cycles canister balance : " && dfx wallet --network $(NETWORK) balance
@echo "-------------------------------------------------------------------------"
@echo "controllers: "
@dfx wallet --network $(NETWORK) controllers
@echo "-------------------------------------------------------------------------"
@echo "custodians: "
@dfx wallet --network $(NETWORK) custodians
@echo "-------------------------------------------------------------------------"
@echo "addresses: "
@dfx wallet --network $(NETWORK) addresses

.PHONY: dfx-wallet-controller-add
dfx-wallet-controller-add:
@[ "${PRINCIPAL}" ] || ( echo ">> Define PRINCIPAL to add as controller: 'make dfx-cycles-controller-add PRINCIPAL=....' "; exit 1 )
@echo "NETWORK : $(NETWORK)"
@echo "PRINCIPAL : $(PRINCIPAL)"
@dfx wallet --network $(NETWORK) add-controller $(PRINCIPAL)

.PHONY: dfx-wallet-controller-remove
dfx-wallet-controller-remove:
@[ "${PRINCIPAL}" ] || ( echo ">> Define PRINCIPAL to remove as controller: 'make dfx-cycles-controller-remove PRINCIPAL=....' "; exit 1 )
@echo "NETWORK : $(NETWORK)"
@echo "PRINCIPAL : $(PRINCIPAL)"
@dfx wallet --network $(NETWORK) remove-controller $(PRINCIPAL)
70 changes: 70 additions & 0 deletions ctrlb_canister/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# ctrlb_canister (Control & Load Balancer)

To bootstrap the code to be added to bioniq's launch canister

### Setup

Install mops (https://mops.one/docs/install)
Install motoko dependencies:

```bash
# from folder backend/ctrlb_canister:

mops install
```

### Deploy

We assume you already have the `backend/llm_0` deployed, and the ctrlb_canister whitelisted.

Then you deploy the ctrlb_canister with:

```bash
# from folder backend/ctrlb_canister:

# Activate the same python environment as you defined for deploying the LLMs
# (This might not be needed, but I did it this way...)
conda activate llama2_c

# Deploy, initialize and test it
# WARNING: This will re-deploy the ctrlb_canister with loss of all existing data!
scripts/deploy.sh --network [local/ic]
```

### Test with dfx

```bash
dfx canister call ctrlb_canister whoami

# Run with same identity used to deploy (as a controller)
$ dfx canister call ctrlb_canister amiController
(variant { Ok = record { status_code = 200 : nat16 } })

# This call checks if the ctrlb_canister is whitelisted in the llm_0
$ dfx canister call ctrlb_canister isWhitelistLogicOk
(variant { Ok = record { status_code = 200 : nat16 } })

# Call the Inference endpoint
$ 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})'
(
variant {
Ok = record {
token_id = "pklc3-dnt23-rylls-wtd3z-a4nod-5b6iu-gha67-4dj4k-uqzci-srgi5-6ae";
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";
prompt = record {
temperature = 0.1 : float64;
topp = 0.9 : float64;
steps = 60 : nat64;
rng_seed = 0 : nat64;
prompt = "Joe went swimming in the pool";
};
}
},
)

# ----------------------------
# Below is for NFT collection

# Update a story for an NFT
$ dfx canister call ctrlb_canister NFTUpdate '(record {token_id="placeholder-0"})'
```
13 changes: 13 additions & 0 deletions ctrlb_canister/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"canisters": {
"ctrlb_canister": {
"main": "src/Main.mo"
}
},
"defaults": {
"build": {
"packtool": "mops sources"
}
}
}
6 changes: 6 additions & 0 deletions ctrlb_canister/mops.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[dependencies]
base = "0.9.8"
accountid = "https://github.com/aviate-labs/principal.mo#main"
hex = "https://github.com/letmejustputthishere/motoko-hex#master"
canistergeek = "https://github.com/usergeek/canistergeek-ic-motoko#v0.0.3"
uuid = "https://github.com/aviate-labs/uuid.mo#v0.2.0"
Loading

0 comments on commit 69c3e38

Please sign in to comment.