Skip to content

Commit

Permalink
- feature: publish cargo package shinkai_tools_runner (#11)
Browse files Browse the repository at this point in the history
* - feature: added cicd to release libraries in dev versions

* - fix: tools folders when compile for crate

* - fix: added missing tool

* - fix: cargo edit dep

* - fix: cargo toml to include tools as assets

* - fix: cargo include

* - fix: concurrent commands

* - fix: typo

* - fix: removed branch from ci trigger
  • Loading branch information
agallardol authored Jul 2, 2024
1 parent 9af572d commit 953adea
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 54 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/release-development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Release development

on:
push:
branches: [main]

defaults:
run:
working-directory: ./

jobs:
prebuild:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.package-version.outputs.version }}
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: get npm version
id: package-version
uses: Saionaro/[email protected]

publish-libraries:
needs: prebuild
runs-on: ubuntu-latest
environment: development
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node version
uses: actions/setup-node@v3
with:
node-version: 18
check-latest: false
registry-url: https://registry.npmjs.org
cache: 'npm'
cache-dependency-path: package-lock.json

- name: Cache cargo assets
id: cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: build-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Install dependencies
run: |
npm cache verify
npm ci --no-audit --prefer-offline
- name: Setup cargo version from npm
run: |
cargo install cargo-edit --force
cargo set-version ${{ needs.prebuild.outputs.version }}-dev.${{github.run_number}}
- name: Run NX publish
run: npx nx run-many -t publish --skip-nx-cache --verbose
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ target

.nx/cache
.nx/workspace-data
libs/shinkai-tools-runner/tools
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
},
"[toml]": {
"editor.defaultFormatter": "tamasfe.even-better-toml"
},
}
2 changes: 1 addition & 1 deletion Cargo.lock

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

13 changes: 10 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
[workspace]
members = [
"libs/shinkai-tools-runner",
]
members = ["libs/shinkai-tools-runner"]
resolver = "2"

[workspace.package]
version = "0.0.0"
repository = "https://github.com/dcSpark/shinkai-tools"
keywords = ["shinkai", "tools", "safe", "ai"]
license-file = "LICENSE"
homepage = "https://shinkai.com"
readme = "README.md"
edition = "2021"
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ use shinkai_tools_runner::tools::tool::Tool;

#[tokio::main]
async fn main() {
let code = get_tool("shinkai-tool-echo").unwrap();
let tool_definition = get_tool("shinkai-tool-echo").unwrap();
let mut tool = Tool::new();
let _ = tool.load_from_code(code, "").await;
let run_result = tool.run("{ \"message\": \"valparaíso\" }").await;
let _ = tool
.load_from_code(&tool_definition.code.clone().unwrap(), "")
.await;
let run_result = tool.run("{ \"message\": \"new york\" }").await.unwrap();
assert_eq!(run_result.data["message"], "echoing: new york");
}
```
21 changes: 18 additions & 3 deletions libs/shinkai-tools-runner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
[package]
name = "shinkai_tools_runner"
version = "0.7.0"
edition = "2021"
description = "Rust library to execute shinkai-tools in a safe and performant environment"
version = { workspace = true }
edition = { workspace = true }
keywords = ["shinkai", "tools", "runner", "safe", "ai"]
include = [
"src/**/*",
"tools/**/*",
"Cargo.toml",
"Cargo.lock"
]
license-file = { workspace = true }
homepage = { workspace = true }
readme = { workspace = true }

[dependencies]
futures = "0.3.30"
nanoid = "0.4.0"
patch = "0.7.0"
reqwest = { version = "0.11.26", features = ["blocking"] }
rquickjs = { version = "0.6.2", features = ["full-async", "futures", "dump-promise"] }
rquickjs = { version = "0.6.2", features = [
"full-async",
"futures",
"dump-promise",
] }
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.117"
tokio = { version = "1.36.0", features = ["full"] }
Expand Down
41 changes: 25 additions & 16 deletions libs/shinkai-tools-runner/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"executor": "nx:run-commands",
"outputs": ["{options.outputPath}"],
"options": {
"command": "nx run-many -t build --projects=tag:tool"
"parallel": false,
"commands": [
"nx run-many -t build --projects=tag:tool",
"npx copyfiles --up 2 --verbose dist/apps/shinkai-tool-*/definition.json libs/shinkai-tools-runner/tools"
]
}
},
"build": {
Expand All @@ -22,12 +26,9 @@
"command": "cargo build"
},
"configurations": {
"development": {
},
"development": {},
"production": {
"args": [
"--release"
]
"args": ["--release"]
}
}
},
Expand All @@ -41,12 +42,9 @@
"command": "cargo test --features=built-in-tools"
},
"configurations": {
"development": {
},
"development": {},
"production": {
"args": [
"--release"
]
"args": ["--release"]
}
}
},
Expand All @@ -59,11 +57,22 @@
"command": "cargo clippy"
},
"configurations": {
"development": {
},
"production": {
}
"development": {},
"production": {}
}
},
"publish": {
"dependsOn": ["build-tools"],
"executor": "nx:run-commands",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"command": "cargo publish -p shinkai_tools_runner --allow-dirty"
},
"configurations": {
"development": {},
"production": {}
}
}
}
}
}
55 changes: 30 additions & 25 deletions libs/shinkai-tools-runner/src/built_in_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,53 @@ lazy_static! {
let mut m = HashMap::new();
m.insert(
"shinkai-tool-echo",
Box::leak(Box::new(
serde_json::from_str::<ToolDefinition>(include_str!(
"../../../dist/apps/shinkai-tool-echo/definition.json"
))
&*Box::leak(Box::new(
serde_json::from_str::<ToolDefinition>(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tools/shinkai-tool-echo/definition.json"
)))
.unwrap(),
)) as &'static ToolDefinition,
)),
);
m.insert(
"shinkai-tool-weather-by-city",
Box::leak(Box::new(
serde_json::from_str::<ToolDefinition>(include_str!(
"../../../dist/apps/shinkai-tool-weather-by-city/definition.json"
))
&*Box::leak(Box::new(
serde_json::from_str::<ToolDefinition>(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tools/shinkai-tool-weather-by-city/definition.json"
)))
.unwrap(),
)) as &'static ToolDefinition,
)),
);
m.insert(
"shinkai-tool-web3-eth-balance",
Box::leak(Box::new(
serde_json::from_str::<ToolDefinition>(include_str!(
"../../../dist/apps/shinkai-tool-web3-eth-balance/definition.json"
))
&*Box::leak(Box::new(
serde_json::from_str::<ToolDefinition>(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tools/shinkai-tool-web3-eth-balance/definition.json"
)))
.unwrap(),
)) as &'static ToolDefinition,
)),
);
m.insert(
"shinkai-tool-web3-eth-uniswap",
Box::leak(Box::new(
serde_json::from_str::<ToolDefinition>(include_str!(
"../../../dist/apps/shinkai-tool-web3-eth-uniswap/definition.json"
))
&*Box::leak(Box::new(
serde_json::from_str::<ToolDefinition>(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tools/shinkai-tool-web3-eth-uniswap/definition.json"
)))
.unwrap(),
)) as &'static ToolDefinition,
)),
);
m.insert(
"shinkai-tool-math-exp",
Box::leak(Box::new(
serde_json::from_str::<ToolDefinition>(include_str!(
"../../../dist/apps/shinkai-tool-math-exp/definition.json"
))
&*Box::leak(Box::new(
serde_json::from_str::<ToolDefinition>(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tools/shinkai-tool-math-exp/definition.json"
)))
.unwrap(),
)) as &'static ToolDefinition,
)),
);
m
};
Expand Down
Loading

0 comments on commit 953adea

Please sign in to comment.