Skip to content

Commit 023da17

Browse files
authored
Merge pull request #1 from cpegeric/plugin_framework
add olllama and wikidump wasm
2 parents 2999279 + 26284c6 commit 023da17

File tree

13 files changed

+694
-14
lines changed

13 files changed

+694
-14
lines changed

plugin/cat/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cat.wasm:
2+
tinygo build -o cat.wasm -no-debug -panic=trap -scheduler=none -target wasi main.go
3+
4+
clean:
5+
rm cat.wasm

plugin/cat/cat.wasm

12.2 KB
Binary file not shown.

plugin/cat/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
pdk "github.com/extism/go-pdk"
5+
)
6+
7+
//export cat
8+
func cat() int32 {
9+
input := pdk.InputString()
10+
header, ok := pdk.GetConfig("header")
11+
var result string
12+
if ok {
13+
result += header
14+
}
15+
16+
result += input
17+
18+
footer, ok := pdk.GetConfig("footer")
19+
if ok {
20+
result += footer
21+
}
22+
pdk.OutputString(result)
23+
return 0
24+
}
25+
26+
func main() {}

plugin/go.mod

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ go 1.22.2
44

55
toolchain go1.22.5
66

7-
require github.com/extism/go-pdk v1.0.2
8-
97
require (
10-
filippo.io/edwards25519 v1.1.0 // indirect
11-
github.com/eliben/go-sudoku v0.0.0-20240410134957-a27844886aa9 // indirect
12-
github.com/go-sql-driver/mysql v1.8.1 // indirect
13-
golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 // indirect
8+
github.com/eliben/go-sudoku v0.0.0-20240410134957-a27844886aa9
9+
github.com/extism/go-pdk v1.1.0
1410
)
11+
12+
require golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 // indirect

plugin/go.sum

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
2-
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
31
github.com/eliben/go-sudoku v0.0.0-20240410134957-a27844886aa9 h1:xaMzNcUVx015OIBRfcnRFTHnIGIElswoDZj9m31q4UM=
42
github.com/eliben/go-sudoku v0.0.0-20240410134957-a27844886aa9/go.mod h1:yTMJtYP8fpTUBEYklCGPE+T2KZHhhzrwWqSuZjCZT6k=
5-
github.com/extism/go-pdk v1.0.2 h1:UB7oTW3tw2zoMlsUdBEDAAbhQg9OudzgNeyCwQYZ730=
6-
github.com/extism/go-pdk v1.0.2/go.mod h1:Gz+LIU/YCKnKXhgge8yo5Yu1F/lbv7KtKFkiCSzW/P4=
7-
github.com/go-mysql-org/go-mysql v1.8.0 h1:bN+/Q5yyQXQOAabXPkI3GZX43w4Tsj2DIthjC9i6CkQ=
8-
github.com/go-mysql-org/go-mysql v1.8.0/go.mod h1:kwbF156Z9Sy8amP3E1SZp7/s/0PuJj/xKaOWToQiq0Y=
9-
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
10-
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
3+
github.com/extism/go-pdk v1.1.0 h1:K2On6XOERxrYdsgu0uLzCxeu/FYRHE8jId/hdEVSYoY=
4+
github.com/extism/go-pdk v1.1.0/go.mod h1:Gz+LIU/YCKnKXhgge8yo5Yu1F/lbv7KtKFkiCSzW/P4=
115
golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 h1:ESSUROHIBHg7USnszlcdmjBEwdMj9VUvU+OPk4yl2mc=
126
golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=

plugin/ollama/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ollama.wasm:
2+
tinygo build -o ollama.wasm -no-debug -panic=trap -scheduler=none -target wasi main.go
3+
4+
clean:
5+
rm ollama.wasm

plugin/ollama/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Ollama Client in Web Assembly
2+
3+
We have implemented three export functions such as 'chunk', 'embed' and 'generate'.
4+
5+
1. 'chunk' function to cut the text into multiple chunks
6+
```
7+
Configuration parameters:
8+
1. chunk_size = size of the chunk, default 1024
9+
2. chunk_overlap, number of byte overlapping, default 20
10+
11+
Input:
12+
string of text input
13+
14+
Output:
15+
JSON Array of chunks
16+
```
17+
18+
2. 'embed' function to convert text into chunks of (embedding, chunk_text) pair.
19+
```
20+
Configuration parameters:
21+
1. model, model name such as llama3.2
22+
2. chunk_size = size of the chunk, default 1024
23+
3. chunk_overlap, number of byte overlapping, default 20
24+
4. address, address of the ollama host, default is http://localhost:11434.
25+
26+
Input:
27+
input text in string format
28+
29+
Output:
30+
JSON Array of Chunk with text and embedding. i.e. [{"chunk":"chunk text 1", "embedding":[1,2....]},...]
31+
```
32+
33+
34+
3. 'generate' function to generate result from prompt.
35+
36+
```
37+
Configuration parameters:
38+
1. model, model name such as llama3.2
39+
2. address, address of the ollama host, default is http://localhost:11434.
40+
41+
Input:
42+
prompt in string format
43+
44+
Output:
45+
JSON Array of generated text
46+
```
47+
48+
49+
## Integration with MatrixOne Database
50+
51+
```
52+
mysql> create table chunk(t varchar, e vecf32(3072));
53+
54+
mysql> insert into chunk select json_unquote(json_extract(result, "$.chunk")), json_unquote(json_extract(result, "$.embedding")) from
55+
moplugin_table('https://github.com/matrixone/mojo/raw/main/plugin/ollama/ollama.wasm', 'embed', '{"model":"llama3.2"}', 'where is great wall?') as f;
56+
57+
mysql> select * from moplugin_table('https://github.com/matrixone/mojo/raw/main/plugin/ollama/ollama.wasm', 'generate', '{"model":"llama3.2"}', 'where is great
58+
wall?') as f;
59+
| "The Great Wall of China is located in China, specifically along the northern border of the country. It stretches across several provinces and municipalities, including:\\n\\n1. Beijing Municipality (where the most famous and well-preserved sections are)\\n2. Tianjin Municipality\\n3. Hebei Province\\n4. Shanxi Province\\n5. Inner Mongolia Autonomous Region\\n\\nThe wall follows the mountain ranges of the northern China, winding its way through valleys and plains, and covers a total length of approximately 13,171 miles (21,196 km). It was built over several centuries to protect the Chinese Empire from invasions by nomadic tribes.\\n\\nSome popular locations to visit the Great Wall include:\\n\\n* Badaling Great Wall (near Beijing)\\n* Mutianyu Great Wall (also near Beijing)\\n* Jinshanling Great Wall (in Hebei Province)\\n* Simatai Great Wall (also in Hebei Province)\\n\\nIt's worth noting that while the wall is a UNESCO World Heritage Site and one of China's most famous landmarks, many sections have been destroyed or damaged over time due to natural erosion, human activities, or wars." |
60+
1 row in set (3.85 sec)
61+
62+
63+
```

0 commit comments

Comments
 (0)