Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plugin/cat/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cat.wasm:
tinygo build -o cat.wasm -no-debug -panic=trap -scheduler=none -target wasi main.go

clean:
rm cat.wasm
Binary file added plugin/cat/cat.wasm
Binary file not shown.
26 changes: 26 additions & 0 deletions plugin/cat/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
pdk "github.com/extism/go-pdk"
)

//export cat
func cat() int32 {
input := pdk.InputString()
header, ok := pdk.GetConfig("header")
var result string
if ok {
result += header
}

result += input

footer, ok := pdk.GetConfig("footer")
if ok {
result += footer
}
pdk.OutputString(result)
return 0
}

func main() {}
10 changes: 4 additions & 6 deletions plugin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ go 1.22.2

toolchain go1.22.5

require github.com/extism/go-pdk v1.0.2

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/eliben/go-sudoku v0.0.0-20240410134957-a27844886aa9 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 // indirect
github.com/eliben/go-sudoku v0.0.0-20240410134957-a27844886aa9
github.com/extism/go-pdk v1.1.0
)

require golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 // indirect
10 changes: 2 additions & 8 deletions plugin/go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/eliben/go-sudoku v0.0.0-20240410134957-a27844886aa9 h1:xaMzNcUVx015OIBRfcnRFTHnIGIElswoDZj9m31q4UM=
github.com/eliben/go-sudoku v0.0.0-20240410134957-a27844886aa9/go.mod h1:yTMJtYP8fpTUBEYklCGPE+T2KZHhhzrwWqSuZjCZT6k=
github.com/extism/go-pdk v1.0.2 h1:UB7oTW3tw2zoMlsUdBEDAAbhQg9OudzgNeyCwQYZ730=
github.com/extism/go-pdk v1.0.2/go.mod h1:Gz+LIU/YCKnKXhgge8yo5Yu1F/lbv7KtKFkiCSzW/P4=
github.com/go-mysql-org/go-mysql v1.8.0 h1:bN+/Q5yyQXQOAabXPkI3GZX43w4Tsj2DIthjC9i6CkQ=
github.com/go-mysql-org/go-mysql v1.8.0/go.mod h1:kwbF156Z9Sy8amP3E1SZp7/s/0PuJj/xKaOWToQiq0Y=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/extism/go-pdk v1.1.0 h1:K2On6XOERxrYdsgu0uLzCxeu/FYRHE8jId/hdEVSYoY=
github.com/extism/go-pdk v1.1.0/go.mod h1:Gz+LIU/YCKnKXhgge8yo5Yu1F/lbv7KtKFkiCSzW/P4=
golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 h1:ESSUROHIBHg7USnszlcdmjBEwdMj9VUvU+OPk4yl2mc=
golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
5 changes: 5 additions & 0 deletions plugin/ollama/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ollama.wasm:
tinygo build -o ollama.wasm -no-debug -panic=trap -scheduler=none -target wasi main.go

clean:
rm ollama.wasm
63 changes: 63 additions & 0 deletions plugin/ollama/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Ollama Client in Web Assembly

We have implemented three export functions such as 'chunk', 'embed' and 'generate'.

1. 'chunk' function to cut the text into multiple chunks
```
Configuration parameters:
1. chunk_size = size of the chunk, default 1024
2. chunk_overlap, number of byte overlapping, default 20

Input:
string of text input

Output:
JSON Array of chunks
```

2. 'embed' function to convert text into chunks of (embedding, chunk_text) pair.
```
Configuration parameters:
1. model, model name such as llama3.2
2. chunk_size = size of the chunk, default 1024
3. chunk_overlap, number of byte overlapping, default 20
4. address, address of the ollama host, default is http://localhost:11434.

Input:
input text in string format

Output:
JSON Array of Chunk with text and embedding. i.e. [{"chunk":"chunk text 1", "embedding":[1,2....]},...]
```


3. 'generate' function to generate result from prompt.

```
Configuration parameters:
1. model, model name such as llama3.2
2. address, address of the ollama host, default is http://localhost:11434.

Input:
prompt in string format

Output:
JSON Array of generated text
```


## Integration with MatrixOne Database

```
mysql> create table chunk(t varchar, e vecf32(3072));

mysql> insert into chunk select json_unquote(json_extract(result, "$.chunk")), json_unquote(json_extract(result, "$.embedding")) from
moplugin_table('https://github.com/matrixone/mojo/raw/main/plugin/ollama/ollama.wasm', 'embed', '{"model":"llama3.2"}', 'where is great wall?') as f;

mysql> select * from moplugin_table('https://github.com/matrixone/mojo/raw/main/plugin/ollama/ollama.wasm', 'generate', '{"model":"llama3.2"}', 'where is great
wall?') as f;
| "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." |
1 row in set (3.85 sec)


```
Loading