Spaces:
Runtime error
Runtime error
matt HOFFNER
commited on
Commit
Β·
ed45bdf
1
Parent(s):
73a1dae
works
Browse files- README.md +9 -3
- src/components/ChatWindow.jsx +7 -4
- src/components/Loader.jsx +0 -1
- src/components/MessageList.jsx +51 -0
README.md
CHANGED
|
@@ -7,6 +7,12 @@ app_port: 3000
|
|
| 7 |
|
| 8 |
# web-llm-embed
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# web-llm-embed
|
| 9 |
|
| 10 |
+
Where were going we don't need servers
|
| 11 |
+
|
| 12 |
+
## Credits
|
| 13 |
+
|
| 14 |
+
[react-llm](https://github.com/r2d4/react-llm)
|
| 15 |
+
[web-llm]()
|
| 16 |
+
[transformers.js]()
|
| 17 |
+
[Chat-Docs-Next]()
|
| 18 |
+
[hnswlib](https://github.com/nmslib/hnswlib)
|
src/components/ChatWindow.jsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import useLLM from "@react-llm/headless";
|
| 2 |
import Image from "next/image";
|
| 3 |
-
import {
|
|
|
|
| 4 |
|
| 5 |
import Loader from "./Loader";
|
| 6 |
|
|
@@ -9,9 +10,7 @@ function ChatWindow({
|
|
| 9 |
maxTokens,
|
| 10 |
}) {
|
| 11 |
const { loadingStatus, send, isGenerating, setOnMessage } = useLLM();
|
| 12 |
-
const [userInput, setUserInput] = useState("");
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
const handleChange = (event) => {
|
| 17 |
setUserInput(event.target.value);
|
|
@@ -54,6 +53,10 @@ function ChatWindow({
|
|
| 54 |
|
| 55 |
<div className="window-content w-full">
|
| 56 |
<div className="flex flex-col w-full">
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
{/* <Separator /> */}
|
| 58 |
<div className="h-4" />
|
| 59 |
{isReady && (
|
|
|
|
| 1 |
import useLLM from "@react-llm/headless";
|
| 2 |
import Image from "next/image";
|
| 3 |
+
import { useCallback, useEffect, useState } from "react";
|
| 4 |
+
import MessageList from './MessageList';
|
| 5 |
|
| 6 |
import Loader from "./Loader";
|
| 7 |
|
|
|
|
| 10 |
maxTokens,
|
| 11 |
}) {
|
| 12 |
const { loadingStatus, send, isGenerating, setOnMessage } = useLLM();
|
| 13 |
+
const [userInput, setUserInput] = useState("");
|
|
|
|
|
|
|
| 14 |
|
| 15 |
const handleChange = (event) => {
|
| 16 |
setUserInput(event.target.value);
|
|
|
|
| 53 |
|
| 54 |
<div className="window-content w-full">
|
| 55 |
<div className="flex flex-col w-full">
|
| 56 |
+
<MessageList
|
| 57 |
+
screenName={"screenName"}
|
| 58 |
+
assistantScreenName={"assistantScreenName"}
|
| 59 |
+
/>
|
| 60 |
{/* <Separator /> */}
|
| 61 |
<div className="h-4" />
|
| 62 |
{isReady && (
|
src/components/Loader.jsx
CHANGED
|
@@ -53,7 +53,6 @@ const Loader = () => {
|
|
| 53 |
<button
|
| 54 |
style={{ padding: "10px" }}
|
| 55 |
size="lg"
|
| 56 |
-
primary
|
| 57 |
onClick={() => init()}
|
| 58 |
>
|
| 59 |
Load Model
|
|
|
|
| 53 |
<button
|
| 54 |
style={{ padding: "10px" }}
|
| 55 |
size="lg"
|
|
|
|
| 56 |
onClick={() => init()}
|
| 57 |
>
|
| 58 |
Load Model
|
src/components/MessageList.jsx
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import useLLM from "@react-llm/headless";
|
| 2 |
+
import { useEffect, useRef } from "react";
|
| 3 |
+
|
| 4 |
+
function MessageList({
|
| 5 |
+
screenName = "endlessbox5",
|
| 6 |
+
assistantScreenName = "SmartestChild",
|
| 7 |
+
}) {
|
| 8 |
+
const scrollRef = useRef(null);
|
| 9 |
+
const { conversation, userRoleName } = useLLM();
|
| 10 |
+
const messages = conversation?.messages || [];
|
| 11 |
+
|
| 12 |
+
const scrollToBottom = () => {
|
| 13 |
+
if (scrollRef.current) {
|
| 14 |
+
scrollRef.current.scrollIntoView();
|
| 15 |
+
}
|
| 16 |
+
};
|
| 17 |
+
|
| 18 |
+
useEffect(() => {
|
| 19 |
+
scrollToBottom();
|
| 20 |
+
}, [conversation, messages.length]);
|
| 21 |
+
|
| 22 |
+
return (
|
| 23 |
+
<div style={{ height: "350px" }} className="w-full">
|
| 24 |
+
<div className="p-2 leading-6 w-full min-h-full">
|
| 25 |
+
{conversation?.messages.map((m) => (
|
| 26 |
+
<div key={m.id} style={{ display: "flex" }}>
|
| 27 |
+
<div
|
| 28 |
+
style={{
|
| 29 |
+
padding: "2px",
|
| 30 |
+
borderRadius: "5px",
|
| 31 |
+
}}
|
| 32 |
+
>
|
| 33 |
+
<span
|
| 34 |
+
style={{
|
| 35 |
+
fontWeight: "bold",
|
| 36 |
+
color: m.role === userRoleName ? "blue" : "red",
|
| 37 |
+
}}
|
| 38 |
+
>
|
| 39 |
+
{m.role === userRoleName ? screenName : assistantScreenName}
|
| 40 |
+
</span>
|
| 41 |
+
: {m.text}
|
| 42 |
+
</div>
|
| 43 |
+
</div>
|
| 44 |
+
))}
|
| 45 |
+
<div ref={scrollRef}></div>
|
| 46 |
+
</div>
|
| 47 |
+
</div>
|
| 48 |
+
);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
export default MessageList;
|