Skip to content

Commit 9d610c2

Browse files
author
Vamshi Maskuri
committed
Add Ollama API client and related components
1 parent fcc5547 commit 9d610c2

File tree

18 files changed

+1599
-3
lines changed

18 files changed

+1599
-3
lines changed

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
[workspace]
22
resolver = "2"
33

4-
members = ["llm", "llm-anthropic", "llm-grok", "llm-openai", "llm-openrouter"]
4+
members = ["llm", "llm-anthropic", "llm-grok","llm-ollama", "llm-openai", "llm-openrouter"]
55

66
[profile.release]
77
debug = false
88
lto = true
99
opt-level = 's'
1010

1111
[workspace.dependencies]
12+
base64 = "0.22.1"
1213
golem-rust = "1.5.3"
1314
log = "0.4.27"
1415
reqwest = { git = "https://github.com/golemcloud/reqwest", branch = "update-april-2025", features = ["json"] }

Makefile.toml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ install_crate = { crate_name = "cargo-component", version = "0.20.0" }
3030
command = "cargo-component"
3131
args = ["build", "-p", "golem-llm-grok", "--no-default-features"]
3232

33+
[tasks.build-ollama]
34+
install_crate = { crate_name = "cargo-component", version = "0.20.0" }
35+
command = "cargo-component"
36+
args = ["build", "-p", "golem-llm-ollama"]
37+
38+
[tasks.build-ollama-portable]
39+
install_crate = { crate_name = "cargo-component", version = "0.20.0" }
40+
command = "cargo-component"
41+
args = ["build", "-p", "golem-llm-ollama", "--no-default-features"]
42+
3343
[tasks.build-openai]
3444
install_crate = { crate_name = "cargo-component", version = "0.20.0" }
3545
command = "cargo-component"
@@ -54,6 +64,7 @@ args = ["build", "-p", "golem-llm-openrouter", "--no-default-features"]
5464
dependencies = [
5565
"build-anthropic",
5666
"build-grok",
67+
"build-ollama",
5768
"build-openai",
5869
"build-openrouter",
5970
]
@@ -62,6 +73,7 @@ dependencies = [
6273
dependencies = [
6374
"build-anthropic-portable",
6475
"build-grok-portable",
76+
"build-ollama-portable",
6577
"build-openai-portable",
6678
"build-openrouter-portable",
6779
]
@@ -76,6 +88,7 @@ cm_run_task build
7688
7789
cp target/wasm32-wasip1/debug/golem_llm_anthropic.wasm components/debug/golem_llm_anthropic.wasm
7890
cp target/wasm32-wasip1/debug/golem_llm_grok.wasm components/debug/golem_llm_grok.wasm
91+
cp target/wasm32-wasip1/debug/golem_llm_ollama.wasm components/debug/golem_llm_ollama.wasm
7992
cp target/wasm32-wasip1/debug/golem_llm_openai.wasm components/debug/golem_llm_openai.wasm
8093
cp target/wasm32-wasip1/debug/golem_llm_openrouter.wasm components/debug/golem_llm_openrouter.wasm
8194
@@ -84,6 +97,7 @@ cm_run_task build-portable
8497
8598
cp target/wasm32-wasip1/debug/golem_llm_anthropic.wasm components/debug/golem_llm_anthropic-portable.wasm
8699
cp target/wasm32-wasip1/debug/golem_llm_grok.wasm components/debug/golem_llm_grok-portable.wasm
100+
cp target/wasm32-wasip1/debug/golem_llm_ollama.wasm components/debug/golem_llm_ollama-portable.wasm
87101
cp target/wasm32-wasip1/debug/golem_llm_openai.wasm components/debug/golem_llm_openai-portable.wasm
88102
cp target/wasm32-wasip1/debug/golem_llm_openrouter.wasm components/debug/golem_llm_openrouter-portable.wasm
89103
'''
@@ -114,6 +128,16 @@ install_crate = { crate_name = "cargo-component", version = "0.20.0" }
114128
command = "cargo-component"
115129
args = ["build", "-p", "golem-llm-grok", "--release", "--no-default-features"]
116130

131+
[tasks.release-ollama]
132+
install_crate = { crate_name = "cargo-component", version = "0.20.0" }
133+
command = "cargo-component"
134+
args = ["build", "-p", "golem-llm-ollama", "--release"]
135+
136+
[tasks.release-ollama-portable]
137+
install_crate = { crate_name = "cargo-component", version = "0.20.0" }
138+
command = "cargo-component"
139+
args = ["build", "-p", "golem-llm-ollama", "--release", "--no-default-features"]
140+
117141
[tasks.release-build-openai]
118142
install_crate = { crate_name = "cargo-component", version = "0.20.0" }
119143
command = "cargo-component"
@@ -144,6 +168,7 @@ args = [
144168
dependencies = [
145169
"release-build-anthropic",
146170
"release-build-grok",
171+
"release-build-ollama",
147172
"release-build-openai",
148173
"release-build-openrouter",
149174
]
@@ -152,6 +177,7 @@ dependencies = [
152177
dependencies = [
153178
"release-build-anthropic-portable",
154179
"release-build-grok-portable",
180+
"release-build-ollama-portable",
155181
"release-build-openai-portable",
156182
"release-build-openrouter-portable",
157183
]
@@ -168,6 +194,7 @@ cm_run_task release-build
168194
169195
cp target/wasm32-wasip1/release/golem_llm_anthropic.wasm components/release/golem_llm_anthropic.wasm
170196
cp target/wasm32-wasip1/release/golem_llm_grok.wasm components/release/golem_llm_grok.wasm
197+
cp target/wasm32-wasip1/release/golem_llm_ollama.wasm components/release/golem_llm_ollama.wasm
171198
cp target/wasm32-wasip1/release/golem_llm_openai.wasm components/release/golem_llm_openai.wasm
172199
cp target/wasm32-wasip1/release/golem_llm_openrouter.wasm components/release/golem_llm_openrouter.wasm
173200
@@ -176,6 +203,7 @@ cm_run_task release-build-portable
176203
177204
cp target/wasm32-wasip1/release/golem_llm_anthropic.wasm components/release/golem_llm_anthropic-portable.wasm
178205
cp target/wasm32-wasip1/release/golem_llm_grok.wasm components/release/golem_llm_grok-portable.wasm
206+
cp target/wasm32-wasip1/release/golem_llm_ollama.wasm components/release/golem_llm_ollama-portable.wasm
179207
cp target/wasm32-wasip1/release/golem_llm_openai.wasm components/release/golem_llm_openai-portable.wasm
180208
cp target/wasm32-wasip1/release/golem_llm_openrouter.wasm components/release/golem_llm_openrouter-portable.wasm
181209
'''
@@ -195,6 +223,7 @@ dependencies = ["wit-update"]
195223
# "llm/wit/deps/golem-llm/golem-llm.wit",
196224
# "llm-anthropic/wit/deps/golem-llm/golem-llm.wit",
197225
# "llm-grok/wit/deps/golem-llm/golem-llm.wit",
226+
# "llm-ollama/wit/deps/golem-llm/golem-llm.wit",
198227
# "llm-openai/wit/deps/golem-llm/golem-llm.wit",
199228
# "llm-openrouter/wit/deps/golem-llm/golem-llm.wit",
200229
#] } }
@@ -213,6 +242,10 @@ rm -r llm-grok/wit/deps
213242
mkdir llm-grok/wit/deps/golem-llm
214243
cp wit/golem-llm.wit llm-grok/wit/deps/golem-llm/golem-llm.wit
215244
cp wit/deps/wasi:io llm-grok/wit/deps
245+
rm -r llm-ollama/wit/deps
246+
mkdir llm-ollama/wit/deps/golem-llm
247+
cp wit/golem-llm.wit llm-ollama/wit/deps/golem-llm/golem-llm.wit
248+
cp wit/deps/wasi:io llm-ollama/wit/deps
216249
rm -r llm-openai/wit/deps
217250
mkdir llm-openai/wit/deps/golem-llm
218251
cp wit/golem-llm.wit llm-openai/wit/deps/golem-llm/golem-llm.wit
@@ -277,15 +310,17 @@ dependencies = ["build"]
277310
description = "Builds all test components with golem-cli"
278311
install_crate = "cargo-binstall"
279312
script = '''
280-
cargo-binstall golem-cli@1.2.2-dev.11 --locked --force --no-confirm
281-
cargo-binstall wac-cli --locked --force --no-confirm
313+
#cargo-binstall golem-cli@1.2.2-dev.11 --locked --force --no-confirm
314+
#cargo-binstall wac-cli --locked --force --no-confirm
282315
cd test
283316
golem-cli --version
284317
golem-cli app clean
285318
golem-cli app build -b anthropic-debug
286319
golem-cli app clean
287320
golem-cli app build -b grok-debug
288321
golem-cli app clean
322+
golem-cli app build -b ollama-debug
323+
golem-cli app clean
289324
golem-cli app build -b openai-debug
290325
golem-cli app clean
291326
golem-cli app build -b openrouter-debug

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ There are 8 published WASM files for each release:
1010
|--------------------------------------|--------------------------------------------------------------------------------------|
1111
| `golem-llm-anthropic.wasm` | LLM implementation for Anthropic AI, using custom Golem specific durability features |
1212
| `golem-llm-grok.wasm` | LLM implementation for xAI (Grok), using custom Golem specific durability features |
13+
| `golem-llm-ollama.wasm` | LLM implementation for xAI (Grok), using custom Golem specific durability features |
1314
| `golem-llm-openai.wasm` | LLM implementation for OpenAI, using custom Golem specific durability features |
1415
| `golem-llm-openrouter.wasm` | LLM implementation for OpenRouter, using custom Golem specific durability features |
1516
| `golem-llm-anthropic-portable.wasm` | LLM implementation for Anthropic AI, with no Golem specific dependencies. |
1617
| `golem-llm-grok-portable.wasm` | LLM implementation for xAI (Grok), with no Golem specific dependencies. |
18+
| `golem-llm-ollama-portable.wasm` | LLM implementation for xAI (Grok), with no Golem specific dependencies. |
1719
| `golem-llm-openai-portable.wasm` | LLM implementation for OpenAI, with no Golem specific dependencies. |
1820
| `golem-llm-openrouter-portable.wasm` | LLM implementation for OpenRouter, with no Golem specific dependencies. |
1921

@@ -32,6 +34,7 @@ Each provider has to be configured with an API key passed as an environment vari
3234
|------------|----------------------|
3335
| Anthropic | `ANTHROPIC_API_KEY` |
3436
| Grok | `XAI_API_KEY` |
37+
| Ollama | `OLLAMA_BASE_URL` |
3538
| OpenAI | `OPENAI_API_KEY` |
3639
| OpenRouter | `OPENROUTER_API_KEY` |
3740

llm-ollama/Cargo.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[package]
2+
name = "golem-llm-ollama"
3+
version = "0.0.0"
4+
edition = "2021"
5+
license = "Apache-2.0"
6+
homepage = "https://golem.cloud"
7+
repository = "https://github.com/golemcloud/golem-llm"
8+
description = "WebAssembly component for working with Ollama APIs, integrated into Golem Cloud local model support"
9+
10+
[lib]
11+
path = "src/lib.rs"
12+
crate-type = ["cdylib"]
13+
14+
[features]
15+
default = ["durability"]
16+
durability = ["golem-rust/durability", "golem-llm/durability"]
17+
18+
[dependencies]
19+
golem-llm = { path = "../llm", version = "0.0.0", default-features = false }
20+
21+
base64 = { workspace = true }
22+
golem-rust = { workspace = true }
23+
log = { workspace = true }
24+
reqwest = { workspace = true }
25+
serde = { workspace = true }
26+
serde_json = { workspace = true }
27+
wit-bindgen-rt = { workspace = true }
28+
29+
[package.metadata.component]
30+
package = "golem:llm-ollama"
31+
32+
[package.metadata.component.bindings]
33+
generate_unused_types = true
34+
35+
[package.metadata.component.bindings.with]
36+
"golem:llm/llm@1.0.0" = "golem_llm::golem::llm::llm"
37+
"wasi:io/poll@0.2.0" = "golem_rust::wasm_rpc::wasi::io::poll"
38+
39+
[package.metadata.component.target]
40+
path = "wit"
41+
42+
[package.metadata.component.target.dependencies]
43+
"golem:llm" = { path = "wit/deps/golem-llm" }
44+
"wasi:io" = { path = "wit/deps/wasi:io"}

llm-ollama/src/bindings.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!
2+
// Options used:
3+
// * runtime_path: "wit_bindgen_rt"
4+
// * with "wasi:io/poll@0.2.0" = "golem_rust::wasm_rpc::wasi::io::poll"
5+
// * with "golem:llm/llm@1.0.0" = "golem_llm::golem::llm::llm"
6+
// * generate_unused_types
7+
use golem_rust::wasm_rpc::wasi::io::poll as __with_name0;
8+
use golem_llm::golem::llm::llm as __with_name1;
9+
#[cfg(target_arch = "wasm32")]
10+
#[link_section = "component-type:wit-bindgen:0.36.0:golem:llm-ollama@1.0.0:llm-library:encoded world"]
11+
#[doc(hidden)]
12+
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1891] = *b"\
13+
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xe1\x0d\x01A\x02\x01\
14+
A\x05\x01B\x0a\x04\0\x08pollable\x03\x01\x01h\0\x01@\x01\x04self\x01\0\x7f\x04\0\
15+
\x16[method]pollable.ready\x01\x02\x01@\x01\x04self\x01\x01\0\x04\0\x16[method]p\
16+
ollable.block\x01\x03\x01p\x01\x01py\x01@\x01\x02in\x04\0\x05\x04\0\x04poll\x01\x06\
17+
\x03\0\x12wasi:io/poll@0.2.0\x05\0\x02\x03\0\0\x08pollable\x01BO\x02\x03\x02\x01\
18+
\x01\x04\0\x08pollable\x03\0\0\x01m\x04\x04user\x09assistant\x06system\x04tool\x04\
19+
\0\x04role\x03\0\x02\x01m\x06\x0finvalid-request\x15authentication-failed\x13rat\
20+
e-limit-exceeded\x0einternal-error\x0bunsupported\x07unknown\x04\0\x0aerror-code\
21+
\x03\0\x04\x01m\x06\x04stop\x06length\x0atool-calls\x0econtent-filter\x05error\x05\
22+
other\x04\0\x0dfinish-reason\x03\0\x06\x01m\x03\x03low\x04high\x04auto\x04\0\x0c\
23+
image-detail\x03\0\x08\x01k\x09\x01r\x02\x03urls\x06detail\x0a\x04\0\x09image-ur\
24+
l\x03\0\x0b\x01q\x02\x04text\x01s\0\x05image\x01\x0c\0\x04\0\x0ccontent-part\x03\
25+
\0\x0d\x01ks\x01p\x0e\x01r\x03\x04role\x03\x04name\x0f\x07content\x10\x04\0\x07m\
26+
essage\x03\0\x11\x01r\x03\x04names\x0bdescription\x0f\x11parameters-schemas\x04\0\
27+
\x0ftool-definition\x03\0\x13\x01r\x03\x02ids\x04names\x0earguments-jsons\x04\0\x09\
28+
tool-call\x03\0\x15\x01ky\x01r\x04\x02ids\x04names\x0bresult-jsons\x11execution-\
29+
time-ms\x17\x04\0\x0ctool-success\x03\0\x18\x01r\x04\x02ids\x04names\x0derror-me\
30+
ssages\x0aerror-code\x0f\x04\0\x0ctool-failure\x03\0\x1a\x01q\x02\x07success\x01\
31+
\x19\0\x05error\x01\x1b\0\x04\0\x0btool-result\x03\0\x1c\x01r\x02\x03keys\x05val\
32+
ues\x04\0\x02kv\x03\0\x1e\x01kv\x01ps\x01k!\x01p\x14\x01p\x1f\x01r\x07\x05models\
33+
\x0btemperature\x20\x0amax-tokens\x17\x0estop-sequences\"\x05tools#\x0btool-choi\
34+
ce\x0f\x10provider-options$\x04\0\x06config\x03\0%\x01r\x03\x0cinput-tokens\x17\x0d\
35+
output-tokens\x17\x0ctotal-tokens\x17\x04\0\x05usage\x03\0'\x01k\x07\x01k(\x01r\x05\
36+
\x0dfinish-reason)\x05usage*\x0bprovider-id\x0f\x09timestamp\x0f\x16provider-met\
37+
adata-json\x0f\x04\0\x11response-metadata\x03\0+\x01p\x16\x01r\x04\x02ids\x07con\
38+
tent\x10\x0atool-calls-\x08metadata,\x04\0\x11complete-response\x03\0.\x01r\x03\x04\
39+
code\x05\x07messages\x13provider-error-json\x0f\x04\0\x05error\x03\00\x01q\x03\x07\
40+
message\x01/\0\x0ctool-request\x01-\0\x05error\x011\0\x04\0\x0achat-event\x03\02\
41+
\x01k\x10\x01k-\x01r\x02\x07content4\x0atool-calls5\x04\0\x0cstream-delta\x03\06\
42+
\x01q\x03\x05delta\x017\0\x06finish\x01,\0\x05error\x011\0\x04\0\x0cstream-event\
43+
\x03\08\x04\0\x0bchat-stream\x03\x01\x01h:\x01p9\x01k<\x01@\x01\x04self;\0=\x04\0\
44+
\x1c[method]chat-stream.get-next\x01>\x01@\x01\x04self;\0<\x04\0%[method]chat-st\
45+
ream.blocking-get-next\x01?\x01i\x01\x01@\x01\x04self;\0\xc0\0\x04\0\x1d[method]\
46+
chat-stream.subscribe\x01A\x01p\x12\x01@\x02\x08messages\xc2\0\x06config&\03\x04\
47+
\0\x04send\x01C\x01o\x02\x16\x1d\x01p\xc4\0\x01@\x03\x08messages\xc2\0\x0ctool-r\
48+
esults\xc5\0\x06config&\03\x04\0\x08continue\x01F\x01i:\x01@\x02\x08messages\xc2\
49+
\0\x06config&\0\xc7\0\x04\0\x06stream\x01H\x04\0\x13golem:llm/llm@1.0.0\x05\x02\x04\
50+
\0\"golem:llm-ollama/llm-library@1.0.0\x04\0\x0b\x11\x01\0\x0bllm-library\x03\0\0\
51+
\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.220.1\x10wit-bind\
52+
gen-rust\x060.36.0";
53+
#[inline(never)]
54+
#[doc(hidden)]
55+
pub fn __link_custom_section_describing_imports() {
56+
wit_bindgen_rt::maybe_link_cabi_realloc();
57+
}

0 commit comments

Comments
 (0)