-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.js
54 lines (49 loc) · 1.58 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
document.addEventListener("alpine:init", () => {
Alpine.store("app", {
selectedModel: null,
models: [],
saddle: new Saddle({ service: "ollama", model: null }),
isSettingsVisible: false,
historyContainer: document.querySelector("#history"),
responseField: document.querySelector("#response-field"),
inputField: document.querySelector("#input-field"),
history: [],
async initialize() {
this.models = await this.saddle.list()
this.selectedModel = this.models[0]
this.saddle = new Saddle({ service: "ollama", model: this.selectedModel })
this.inputField.addEventListener("keydown", event => {
if (event.keyCode === 13 && this.inputField.value.trim() !== "") {
if (event.shiftKey) {
} else {
this.handleSend()
}
}
})
},
scrollToBottom() {
this.historyContainer.scrollTop = this.historyContainer.scrollHeight
},
changeModel() {
console.log(this.selectedModel)
this.saddle = new Saddle({
service: "ollama",
model: this.selectedModel,
})
},
async handleSend() {
const input = this.inputField.value
this.inputField.value = ""
const message = { role: "user", content: input }
this.history.push(message)
const reply = { role: "system", content: "" }
this.history.push(reply)
this.saddle.streamer(input, response => {
this.history[this.history.length - 1].content = response
this.scrollToBottom()
})
},
})
window.app = Alpine.store("app")
app.initialize()
})