Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Aug 22, 2024
1 parent 6c717d8 commit 2fae0a9
Show file tree
Hide file tree
Showing 29 changed files with 3,562 additions and 11 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,3 @@
*.exe
*.out
*.app

build/*
build-library/*
59 changes: 57 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,57 @@
# chess23
Simple chess example mini-llm
# `chess23`

Welcome to your new `chess23` project and to the Internet Computer development community. By default, creating a new project adds this README and some template files to your project directory. You can edit these template files to customize your project and to include your own code to speed up the development cycle.

To get started, you might want to explore the project directory structure and the default configuration file. Working with this project in your development environment will not affect any production deployment or identity tokens.

To learn more before you start working with `chess23`, see the following documentation available online:

- [Quick Start](https://internetcomputer.org/docs/current/developer-docs/setup/deploy-locally)
- [SDK Developer Tools](https://internetcomputer.org/docs/current/developer-docs/setup/install)

If you want to start working on your project right away, you might want to try the following commands:

```bash
cd chess23/
dfx help
dfx canister --help
```

## Running the project locally

If you want to test your project locally, you can use the following commands:

```bash
# Starts the replica, running in the background
dfx start --background

# Deploys your canisters to the replica and generates your candid interface
dfx deploy
```

Once the job completes, your application will be available at `http://localhost:4943?canisterId={asset_canister_id}`.

If you have made changes to your backend canister, you can generate a new candid interface with

```bash
npm run generate
```

at any time. This is recommended before starting the frontend development server, and will be run automatically any time you run `dfx deploy`.

If you are making frontend changes, you can start a development server with

```bash
npm start
```

Which will start a server at `http://localhost:8080`, proxying API requests to the replica at port 4943.

### Note on frontend environment variables

If you are hosting frontend code somewhere without using DFX, you may need to make one of the following adjustments to ensure your project does not fetch the root key in production:

- set`DFX_NETWORK` to `ic` if you are using Webpack
- use your own preferred method to replace `process.env.DFX_NETWORK` in the autogenerated declarations
- Setting `canisters -> {asset_canister_id} -> declarations -> env_override to a string` in `dfx.json` will replace `process.env.DFX_NETWORK` with the string in the autogenerated declarations
- Write your own `createActor` constructor
215 changes: 215 additions & 0 deletions build/chess23.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
// Candid interface of the canister endpoints
// https://internetcomputer.org/docs/current/references/candid-ref/

type Prompt = record {
prompt : text;
steps : nat64;
temperature : float32;
topp : float32;
rng_seed : nat64;
};

// Motoko does not support float32, so we use float64, and then map PromptMo onto Prompt
type PromptMo = record {
prompt : text;
steps : nat64;
temperature : float64;
topp : float64;
rng_seed : nat64;
};

type Config = record {
dim : int;
hidden_dim : int;
n_layers : int;
n_heads : int;
n_kv_heads : int;
vocab_size : int;
seq_len : int;
};

// ----------------------------------------------------------
// New approach to endpoint return values:
// -> wrap a record in a Result

// --
type ApiError = variant {
InvalidId;
Other : text;
StatusCode : nat16;
ZeroAddress;
};

// --
// Returned by several endpoints.
// HTTPS status code wrapped in a Record wrapped in a Result
type StatusCodeRecordResult = variant {
Err : ApiError;
Ok : StatusCodeRecord;
};
type StatusCodeRecord = record { status_code : nat16 };

// --
// Returned by 'set_canister_mode'
type CanisterModeRecordResult = variant {
Err : ApiError;
Ok : CanisterModeRecord;
};
type CanisterModeRecord = record { canister_mode : text };

// --
// Returned by 'inference', 'nft_story_start', 'nft_story_continue'
// Section of a story, generated by a single inference call
type InferenceRecordResult = variant {
Err : ApiError;
Ok : InferenceRecord;
};
type InferenceRecord = record { inference : text };

// --
// A story, from beginning, build from multiple inference calls
type StoryRecordResult = variant {
Err : ApiError;
Ok : StoryRecord;
};
type StoryRecord = record { story : text };

// --
// Metadata for an NFT collection
type NFTCollectionRecordResult = variant {
Err : ApiError;
Ok : NFTCollectionRecord;
};
type NFTCollectionRecord = record {
nft_supply_cap : nat64;
nft_total_supply : nat64;
nft_symbol : text;
nft_name : text;
nft_description : text;
};

// --
// Returned by 'get_users'
type UsersRecordResult = variant {
Err : ApiError;
Ok : UsersRecord;
};
type UsersRecord = record {
user_count : nat64;
user_ids : vec text;
};

// --
// Returned by 'get_user_metadata'

type UserMetadataRecordResult = variant {
Err : ApiError;
Ok : UserMetadataRecord;
};
type UserMetadataRecord = record {
chats_start_time : vec nat64;
chats_total_steps : vec nat64;
};

// ----------------------------------------------------------

type NFTWhitelistRecord = record {
id : principal;
description : text;
};

type NFT = record {
token_id : text;
};

// --------------------------------------------------------------------------------
// HTTP Gateway Protocol
// https://internetcomputer.org/docs/current/references/http-gateway-protocol-spec#canister-http-interface
// https://internetcomputer.org/docs/current/references/http-gateway-protocol-spec
// https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-candid

type HeaderField = record { text; text };

type HttpRequest = record {
method : text;
url : text;
headers : vec HeaderField;
body : blob;
certificate_version : opt nat16;
};

// type HttpUpdateRequest = record {
// method: text;
// url: text;
// headers: vec HeaderField;
// body: blob;
// };

type HttpResponse = record {
status_code : nat16;
headers : vec HeaderField;
body : blob;
upgrade : opt bool;
// streaming_strategy: opt StreamingStrategy;
};

/* StreamingStrategy is NOT YET SUPPORTED
// Each canister that uses the streaming feature gets to choose their concrete
// type; the HTTP Gateway will treat it as an opaque value that is only fed to
// the callback method

type StreamingToken = === application-specific type ===

type StreamingCallbackHttpResponse = record {
body: blob;
token: opt StreamingToken;
};

type StreamingStrategy = variant {
Callback: record {
callback: func (StreamingToken) -> (opt StreamingCallbackHttpResponse) query;
token: StreamingToken;
};
};
*/

service : {
// canister endpoints
canister_init : () -> ();
set_canister_mode : (text) -> (StatusCodeRecordResult);
health : () -> (StatusCodeRecordResult) query;
ready : () -> (StatusCodeRecordResult) query;

// LLM initialization endpoints
reset_model : () -> (StatusCodeRecordResult);
reset_tokenizer : () -> (StatusCodeRecordResult);
upload_model_bytes_chunk : (vec nat8) -> (StatusCodeRecordResult);
upload_tokenizer_bytes_chunk : (vec nat8) -> (StatusCodeRecordResult);
initialize : () -> (StatusCodeRecordResult);
get_model_config : () -> (Config) query;

// Chat endpoints for canister_mode=chat-principal
new_chat : () -> (StatusCodeRecordResult);
inference : (Prompt) -> (InferenceRecordResult);
inference_mo : (PromptMo) -> (InferenceRecordResult);

// admin endpoints
whoami : () -> (text) query;
get_users : () -> (UsersRecordResult) query;
get_user_metadata : (text) -> (UserMetadataRecordResult) query;

// http endpoints
http_request : (request : HttpRequest) -> (HttpResponse) query;

// nft endpoints (for canister_mode=nft-ordinal)
nft_whitelist : (NFTWhitelistRecord) -> (StatusCodeRecordResult);
nft_ami_whitelisted : () -> (StatusCodeRecordResult);
nft_init : (NFTCollectionRecord) -> (StatusCodeRecordResult);
nft_metadata : () -> (NFTCollectionRecordResult) query;
nft_mint : (NFT) -> (StatusCodeRecordResult);
nft_story_start : (NFT, Prompt) -> (InferenceRecordResult);
nft_story_start_mo : (NFT, PromptMo) -> (InferenceRecordResult);
nft_story_continue : (NFT, Prompt) -> (InferenceRecordResult);
nft_story_continue_mo : (NFT, PromptMo) -> (InferenceRecordResult);
nft_get_story : (NFT) -> (StoryRecordResult) query;
};
Binary file added build/chess23.wasm
Binary file not shown.
Binary file added build/chess23_wasi.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions build/custom_section_cdk_languages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c++
1 change: 1 addition & 0 deletions build/custom_section_cdk_name.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
icpp-pro
1 change: 1 addition & 0 deletions build/custom_section_dfx.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "tech_stack": { "language": {"c++": {} }, "cdk": {"icpp-pro": {} } } }
1 change: 1 addition & 0 deletions build/custom_section_version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0.0rc1
5 changes: 0 additions & 5 deletions canister_ids.json

This file was deleted.

1 change: 1 addition & 0 deletions chess23-frontend
Submodule chess23-frontend added at 54e82b
30 changes: 29 additions & 1 deletion dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,36 @@
"type": "custom",
"candid": "src/chess23.did",
"wasm": "build/chess23.wasm"
}
},
"chess23_backend": {
"build": "npx azle chess23_backend",
"candid": "chess23_frontend/src/chess23_backend/chess23_backend.did",
"gzip": true,
"main": "chess23_frontend/src/chess23_backend/src/index.ts",
"tech_stack": {
"cdk": {
"azle": {}
},
"language": {
"javascript": {},
"typescript": {}
}
},
"type": "custom",
"wasm": ".azle/chess23_backend/chess23_backend.wasm"
},
"chess23_frontend": {
"dependencies": [
"chess23_backend"
],
"source": [
"chess23_frontend/src/chess23_frontend/dist"
],
"type": "assets",
"workspace": "chess23_frontend"
}
},

"defaults": {
"build": {
"args": "",
Expand Down
Loading

0 comments on commit 2fae0a9

Please sign in to comment.