Skip to content

Commit a0e7b8c

Browse files
committed
feat: add Ollama Tools section with HTML, CSS, and JavaScript components for tool functionality
1 parent bdd31dd commit a0e7b8c

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

app/home/home.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ <h2>Home</h2>
33
<ul>
44
<li><a href="/form">Form</a></li>
55
<li><a href="/ollama">Ollama</a></li>
6+
<li><a href="/ollama-tools">Ollama Tools</a></li>
67
<li><a href="/kanban">Kanban</a></li>
78
<li><a href="/canvas">Canvas</a></li>
89
<li><a href="/dynamic-layout">Dynamic Layout</a></li>

app/ollama-tools/ollama-tools.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:host {
2+
display: grid;
3+
width: 100%;
4+
height: 100%;
5+
overflow: hidden;
6+
}

app/ollama-tools/ollama-tools.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h2>Ollama Tool Calling</h2>
2+
<div class="container"></div>
3+
<button data-action="callFunction">Call Function</button>

app/ollama-tools/ollama-tools.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import {OllamaModule} from "./../../src/modules/ollama.js";
2+
3+
const tools = [
4+
{
5+
"type": "function",
6+
"function": {
7+
"name": "example_function",
8+
"description": "This is an example function",
9+
"parameters": [
10+
{
11+
"type": "object",
12+
"properties": {
13+
"option": {
14+
"type": "string",
15+
"description": "The value to return",
16+
"enum": ["option1", "option2"]
17+
}
18+
}
19+
}
20+
],
21+
}
22+
}
23+
]
24+
25+
export default class OllamaToolsView extends HTMLElement {
26+
static tag = "ollama-tools-view";
27+
28+
#onClickHandler = this.#onClick.bind(this);
29+
30+
constructor() {
31+
super();
32+
this.attachShadow({ mode: "open" });
33+
}
34+
35+
async connectedCallback() {
36+
this.shadowRoot.innerHTML = await api.call("component", "load_html", {
37+
url: import.meta.url,
38+
});
39+
40+
this.addEventListener("click", this.#onClickHandler);
41+
}
42+
43+
async disconnectedCallback() {
44+
this.removeEventListener("click", this.#onClickHandler);
45+
}
46+
47+
#onClick(event) {
48+
const target = event.composedPath()[0];
49+
if (target.dataset.action != null) {
50+
this[target.dataset.action].call(this, event);
51+
}
52+
}
53+
54+
callFunction(event) {
55+
alert("click")
56+
}
57+
}
58+
59+
customElements.define(OllamaToolsView.tag, OllamaToolsView);

src/modules/ollama.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const GENERATE_OPTIONAL_ARGS = Object.freeze([
2121
"raw",
2222
"keep_alive",
2323
]);
24+
2425
const CHAT_OPTIONAL_ARGS = Object.freeze([
2526
"tools",
2627
"role",

0 commit comments

Comments
 (0)