-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Your Name
committed
Aug 22, 2024
1 parent
6c717d8
commit 2fae0a9
Showing
29 changed files
with
3,562 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,3 @@ | |
*.exe | ||
*.out | ||
*.app | ||
|
||
build/* | ||
build-library/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
c++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
icpp-pro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "tech_stack": { "language": {"c++": {} }, "cdk": {"icpp-pro": {} } } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
4.0.0rc1 |
This file was deleted.
Oops, something went wrong.
Submodule chess23-frontend
added at
54e82b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.