Skip to content

Commit

Permalink
feat: client for communicate with API/LLM Servers
Browse files Browse the repository at this point in the history
  • Loading branch information
PleahMaCaka committed Oct 26, 2023
1 parent d379df7 commit aa0f24c
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@tiptap/starter-kit": "^2.1.12",
"@types/cookie": "^0.5.3",
"autoprefixer": "^10.4.16",
"booga.js": "^0.2.1",
"marked": "^9.1.2",
"postcss": "^8.4.31",
"postcss-import": "^15.1.0",
Expand Down
72 changes: 72 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions src/lib/client/Client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { stateStore } from "$lib/stores/StateStore"
import { Author } from "$lib/types/Chat"
import { Client as LLM } from "booga.js"

export class Client {

constructor() {
stateStore.subscribe((state) => {
this._url = state.url.model
})
}

private _url: string = ""

public llm = new LLM({
uri: this._url
})

public async appendHistory(author: Author, msg: string) {
stateStore.update((state) => {
return {
...state,
history: [
...state.history,
{
author: author,
message: msg
}
]
}
})
}


public async send(msg: string, char: string = "Commander") {
await this.appendHistory(Author.User, msg)

await this.llm.chat(msg, {
character: char
}).then(res => {
this.appendHistory(Author.Assistant, res.output)
})
}

}

export const client = new Client()
8 changes: 6 additions & 2 deletions src/lib/components/share/ChatInput.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { client } from "$lib/client/Client"
import { stateStore } from "$lib/stores/StateStore"
import Icon from "@iconify/svelte"
import { onMount } from "svelte"
Expand All @@ -10,14 +11,17 @@
onMount(() => {
textarea.focus()
})
const submitText = async () => {
if (text.length === 0) return
if (text.trim() === "") return
$stateStore.input = text
console.log("Text Submitted:", text)
$stateStore.input = text
text = ""
await client.send($stateStore.input)
}
const handleKeyDown = (event: KeyboardEvent) => {
Expand Down

0 comments on commit aa0f24c

Please sign in to comment.