Skip to content

Commit 68bbf9b

Browse files
committed
Ollama: new action components
1 parent e5ffa1c commit 68bbf9b

File tree

14 files changed

+767
-7
lines changed

14 files changed

+767
-7
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: utils.parseOptions(options),
74+
stream,
75+
keep_alive: keepAlive,
76+
},
77+
});
78+
79+
$.export("$summary", "Successfully generated chat completion.");
80+
return response;
81+
},
82+
};
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import utils from "../../common/utils.mjs";
2+
import app from "../../ollama.app.mjs";
3+
4+
export default {
5+
key: "ollama-generate-completion",
6+
name: "Generate Completion",
7+
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).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
model: {
13+
propDefinition: [
14+
app,
15+
"model",
16+
],
17+
},
18+
prompt: {
19+
propDefinition: [
20+
app,
21+
"prompt",
22+
],
23+
},
24+
suffix: {
25+
propDefinition: [
26+
app,
27+
"suffix",
28+
],
29+
},
30+
images: {
31+
propDefinition: [
32+
app,
33+
"images",
34+
],
35+
},
36+
options: {
37+
propDefinition: [
38+
app,
39+
"options",
40+
],
41+
},
42+
stream: {
43+
propDefinition: [
44+
app,
45+
"stream",
46+
],
47+
},
48+
keepAlive: {
49+
propDefinition: [
50+
app,
51+
"keepAlive",
52+
],
53+
},
54+
},
55+
methods: {
56+
generateCompletion(args = {}) {
57+
return this.app.post({
58+
path: "/generate",
59+
...args,
60+
});
61+
},
62+
},
63+
async run({ $ }) {
64+
const {
65+
generateCompletion,
66+
model,
67+
prompt,
68+
suffix,
69+
images,
70+
options,
71+
stream,
72+
keepAlive,
73+
} = this;
74+
75+
const response = await generateCompletion({
76+
$,
77+
data: {
78+
model,
79+
prompt,
80+
suffix,
81+
images,
82+
options: utils.parseOptions(options),
83+
stream,
84+
keep_alive: keepAlive,
85+
},
86+
});
87+
$.export("$summary", "Successfully generated completion.");
88+
return response;
89+
},
90+
};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import utils from "../../common/utils.mjs";
2+
import app from "../../ollama.app.mjs";
3+
4+
export default {
5+
key: "ollama-generate-embeddings",
6+
name: "Generate Embeddings",
7+
description: "Generate embeddings from a model. [See the documentation](https://github.com/ollama/ollama/blob/main/docs/api.md#generate-embeddings).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
model: {
13+
propDefinition: [
14+
app,
15+
"model",
16+
],
17+
},
18+
input: {
19+
type: "string[]",
20+
label: "Input",
21+
description: "The list of texts to generate embeddings for.",
22+
},
23+
truncate: {
24+
type: "boolean",
25+
label: "Truncate",
26+
description: "Truncates the end of each input to fit within context length. Returns error if `false` and context length is exceeded. Defaults to `true`.",
27+
optional: true,
28+
},
29+
options: {
30+
propDefinition: [
31+
app,
32+
"options",
33+
],
34+
},
35+
keepAlive: {
36+
propDefinition: [
37+
app,
38+
"keepAlive",
39+
],
40+
},
41+
},
42+
methods: {
43+
generateEmbeddings(args = {}) {
44+
return this.app.post({
45+
path: "/embed",
46+
...args,
47+
});
48+
},
49+
},
50+
async run({ $ }) {
51+
const {
52+
generateEmbeddings,
53+
model,
54+
input,
55+
truncate,
56+
options,
57+
keepAlive,
58+
} = this;
59+
60+
const response = await generateEmbeddings({
61+
$,
62+
data: {
63+
model,
64+
input,
65+
truncate,
66+
options: utils.parseOptions(options),
67+
keep_alive: keepAlive,
68+
},
69+
});
70+
$.export("$summary", "Successfully generated embeddings.");
71+
return response;
72+
},
73+
};

0 commit comments

Comments
 (0)