Skip to content

Commit b107bb7

Browse files
committed
Ollama: new action components
1 parent ff70ac9 commit b107bb7

File tree

14 files changed

+730
-8
lines changed

14 files changed

+730
-8
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import app from "../../ollama.app.mjs";
2+
3+
export default {
4+
key: "ollama-copy-model",
5+
name: "Copy Model",
6+
description: "Copies a model, creating a model with another name from an existing model. [See the documentation](https://github.com/ollama/ollama/blob/main/docs/api.md#copy-a-model).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
source: {
12+
propDefinition: [
13+
app,
14+
"model",
15+
],
16+
},
17+
destination: {
18+
type: "string",
19+
label: "New Model Name",
20+
description: "The new name for the copied model.",
21+
},
22+
},
23+
methods: {
24+
copyModel(args = {}) {
25+
return this.app.post({
26+
path: "/copy",
27+
...args,
28+
});
29+
},
30+
},
31+
async run({ $ }) {
32+
const {
33+
copyModel,
34+
source,
35+
destination,
36+
} = this;
37+
38+
await copyModel({
39+
$,
40+
data: {
41+
source,
42+
destination,
43+
},
44+
});
45+
$.export("$summary", "Successfully copied model.");
46+
return {
47+
success: true,
48+
};
49+
},
50+
};
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import app from "../../ollama.app.mjs";
2+
3+
export default {
4+
key: "ollama-create-model",
5+
name: "Create Model",
6+
description: "Create a model from a modelfile. [See the documentation](https://github.com/ollama/ollama/blob/main/docs/api.md#create-a-model).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
type: "string",
13+
label: "Name",
14+
description: "The name of the model.",
15+
},
16+
modelfile: {
17+
type: "string",
18+
label: "Model File",
19+
description: "Contents of the Modelfile. Eg. `FROM llama3 SYSTEM You are mario from Super Mario Bros`",
20+
},
21+
stream: {
22+
propDefinition: [
23+
app,
24+
"stream",
25+
],
26+
},
27+
},
28+
methods: {
29+
createModel(args = {}) {
30+
return this.app.post({
31+
path: "/create",
32+
...args,
33+
});
34+
},
35+
},
36+
async run({ $ }) {
37+
const {
38+
createModel,
39+
name,
40+
modelfile,
41+
stream,
42+
} = this;
43+
44+
const response = await createModel({
45+
$,
46+
data: {
47+
name,
48+
modelfile,
49+
stream,
50+
},
51+
});
52+
$.export("$summary", "Successfully created model.");
53+
return response;
54+
},
55+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import app from "../../ollama.app.mjs";
2+
3+
export default {
4+
key: "ollama-delete-model",
5+
name: "Delete Model",
6+
description: "Delete a model and its data. [See the documentation](https://github.com/ollama/ollama/blob/main/docs/api.md#delete-a-model)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
propDefinition: [
13+
app,
14+
"model",
15+
],
16+
},
17+
},
18+
methods: {
19+
deleteModel(args = {}) {
20+
return this.app.delete({
21+
path: "/delete",
22+
...args,
23+
});
24+
},
25+
},
26+
async run({ $ }) {
27+
const {
28+
deleteModel,
29+
name,
30+
} = this;
31+
32+
await deleteModel({
33+
$,
34+
data: {
35+
name,
36+
},
37+
});
38+
$.export("$summary", "Successfully deleted model.");
39+
return {
40+
success: true,
41+
};
42+
},
43+
};
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import app from "../../ollama.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "ollama-generate-chat-completion",
6+
name: "Generate Chat Completion",
7+
description: "Generates the next message in a chat with a provided model. [See the documentation](https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-chat-completion).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
model: {
13+
propDefinition: [
14+
app,
15+
"model",
16+
],
17+
},
18+
messages: {
19+
type: "string[]",
20+
label: "Messages",
21+
description: "The messages of the chat, this can be used to keep a chat memory. Each row should be set as a JSON format string. Eg. `{\"role\": \"user\", \"content\": \"Hello\"}`. The message object has the following fields:\n- `role`: the role of the message, either `system`, `user`, `assistant`, or `tool`.\n- `content`: The content of the message.\n- `images` (optional): a list of images to include in the message (for multimodal models such as `llava`).\n- `tool_calls`(optional): a list of tools the model wants to use.",
22+
},
23+
tools: {
24+
type: "string[]",
25+
label: "Tools",
26+
description: "A list of tools the model can use. Each row should be set as a JSON format string.",
27+
optional: true,
28+
},
29+
options: {
30+
propDefinition: [
31+
app,
32+
"options",
33+
],
34+
},
35+
stream: {
36+
propDefinition: [
37+
app,
38+
"stream",
39+
],
40+
},
41+
keepAlive: {
42+
propDefinition: [
43+
app,
44+
"keepAlive",
45+
],
46+
},
47+
},
48+
methods: {
49+
generateChatCompletion(args = {}) {
50+
return this.app.post({
51+
path: "/chat",
52+
...args,
53+
});
54+
},
55+
},
56+
async run({ $ }) {
57+
const {
58+
generateChatCompletion,
59+
model,
60+
messages,
61+
tools,
62+
options,
63+
stream,
64+
keepAlive,
65+
} = this;
66+
67+
const response = await generateChatCompletion({
68+
$,
69+
data: {
70+
model,
71+
messages: utils.parseArray(messages),
72+
tools: utils.parseArray(tools),
73+
options,
74+
stream,
75+
keep_alive: keepAlive,
76+
},
77+
});
78+
79+
$.export("$summary", "Successfully generated chat completion.");
80+
return response;
81+
},
82+
};
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import app from "../../ollama.app.mjs";
2+
3+
export default {
4+
key: "ollama-generate-completion",
5+
name: "Generate Completion",
6+
description: "Generates a response for a given prompt with a provided model. [See the documentation](https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-completion).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
model: {
12+
propDefinition: [
13+
app,
14+
"model",
15+
],
16+
},
17+
prompt: {
18+
propDefinition: [
19+
app,
20+
"prompt",
21+
],
22+
},
23+
suffix: {
24+
propDefinition: [
25+
app,
26+
"suffix",
27+
],
28+
},
29+
images: {
30+
propDefinition: [
31+
app,
32+
"images",
33+
],
34+
},
35+
options: {
36+
propDefinition: [
37+
app,
38+
"options",
39+
],
40+
},
41+
stream: {
42+
propDefinition: [
43+
app,
44+
"stream",
45+
],
46+
},
47+
keepAlive: {
48+
propDefinition: [
49+
app,
50+
"keepAlive",
51+
],
52+
},
53+
},
54+
methods: {
55+
generateCompletion(args = {}) {
56+
return this.app.post({
57+
path: "/generate",
58+
...args,
59+
});
60+
},
61+
},
62+
async run({ $ }) {
63+
const {
64+
generateCompletion,
65+
model,
66+
prompt,
67+
suffix,
68+
images,
69+
options,
70+
stream,
71+
keepAlive,
72+
} = this;
73+
74+
const response = await generateCompletion({
75+
$,
76+
data: {
77+
model,
78+
prompt,
79+
suffix,
80+
images,
81+
options,
82+
stream,
83+
keep_alive: keepAlive,
84+
},
85+
});
86+
$.export("$summary", "Successfully generated completion.");
87+
return response;
88+
},
89+
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import app from "../../ollama.app.mjs";
2+
3+
export default {
4+
key: "ollama-generate-embeddings",
5+
name: "Generate Embeddings",
6+
description: "Generate embeddings from a model. [See the documentation](https://github.com/ollama/ollama/blob/main/docs/api.md#generate-embeddings).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
model: {
12+
propDefinition: [
13+
app,
14+
"model",
15+
],
16+
},
17+
input: {
18+
type: "string[]",
19+
label: "Input",
20+
description: "The list of texts to generate embeddings for.",
21+
},
22+
truncate: {
23+
type: "boolean",
24+
label: "Truncate",
25+
description: "Truncates the end of each input to fit within context length. Returns error if `false` and context length is exceeded. Defaults to `true`.",
26+
optional: true,
27+
},
28+
options: {
29+
propDefinition: [
30+
app,
31+
"options",
32+
],
33+
},
34+
keepAlive: {
35+
propDefinition: [
36+
app,
37+
"keepAlive",
38+
],
39+
},
40+
},
41+
methods: {
42+
generateEmbeddings(args = {}) {
43+
return this.app.post({
44+
path: "/embed",
45+
...args,
46+
});
47+
},
48+
},
49+
async run({ $ }) {
50+
const {
51+
generateEmbeddings,
52+
model,
53+
input,
54+
truncate,
55+
options,
56+
keepAlive,
57+
} = this;
58+
59+
const response = await generateEmbeddings({
60+
$,
61+
data: {
62+
model,
63+
input,
64+
truncate,
65+
options,
66+
keep_alive: keepAlive,
67+
},
68+
});
69+
$.export("$summary", "Successfully generated embeddings.");
70+
return response;
71+
},
72+
};

0 commit comments

Comments
 (0)