-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: client for communicate with API/LLM Servers
- Loading branch information
1 parent
d379df7
commit aa0f24c
Showing
4 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters