Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lit-ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
60 changes: 60 additions & 0 deletions lit-ui/elements/ngui-chat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { LitElement, html } from 'lit';
import { customElement } from 'lit/decorators.js';

import { PfTextInput } from '@patternfly/elements/pf-text-input/pf-text-input.js';

@customElement('ngui-chat')
export class NguiChat extends LitElement {
#chatUrl = 'http://localhost:8000/runs/'
#sessionId = crypto.randomUUID();
render() {
return html`
<form @submit="${this.#onSubmit}">
<pf-text-input name="input"
value="tell me about toy story"
@keyup="${this.#onKeyup}"></pf-text-input>
</form>
`;
}

#onKeyup(event: KeyboardEvent) {
if (event.key === 'Enter')
(event.target as HTMLElement).closest('form')?.requestSubmit()
}

async #onSubmit(event: Event) {
event.preventDefault();

if (event.target instanceof HTMLFormElement) {
const form = event.target
const input = form.elements.namedItem('input') as PfTextInput;

this.#sessionId ??= crypto.randomUUID();
const response = await fetch(this.#chatUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json', },
body: JSON.stringify({
agent_name:"movies",
session_id: this.#sessionId,
session:{
id: this.#sessionId,
history:[], // todo: append history
state: "bananas",
},
mode:"sync",
input:[{
role:"user",
parts:[{
name:"<string>",
content: input.value,
}],
}],
})
})
.then(response => response.json())
.catch(err => console.error(err));

console.log(response);
}
}
}
14 changes: 14 additions & 0 deletions lit-ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>NextGenUI - Portable</title>
<script type="module">
import "./elements/ngui-chat.ts";
</script>
</head>
<body>
<ngui-chat></ngui-chat>
</body>
</html>
Loading