matt HOFFNER commited on
Commit
b801bb1
β€’
1 Parent(s): 81a0b2a
package-lock.json CHANGED
@@ -22,6 +22,7 @@
22
  "next": "13.4.2",
23
  "react": "18.2.0",
24
  "react-dom": "18.2.0",
 
25
  "react95": "^4.0.0",
26
  "typescript": "5.0.4",
27
  "uuid": "^9.0.0"
@@ -1750,6 +1751,14 @@
1750
  "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
1751
  "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
1752
  },
 
 
 
 
 
 
 
 
1753
  "node_modules/autoprefixer": {
1754
  "version": "10.4.14",
1755
  "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.14.tgz",
@@ -3099,6 +3108,17 @@
3099
  "node": "^10.12.0 || >=12.0.0"
3100
  }
3101
  },
 
 
 
 
 
 
 
 
 
 
 
3102
  "node_modules/filelist": {
3103
  "version": "1.0.4",
3104
  "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz",
@@ -5383,6 +5403,22 @@
5383
  "react": "^18.2.0"
5384
  }
5385
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5386
  "node_modules/react-is": {
5387
  "version": "16.13.1",
5388
  "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
 
22
  "next": "13.4.2",
23
  "react": "18.2.0",
24
  "react-dom": "18.2.0",
25
+ "react-dropzone": "^14.2.3",
26
  "react95": "^4.0.0",
27
  "typescript": "5.0.4",
28
  "uuid": "^9.0.0"
 
1751
  "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
1752
  "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
1753
  },
1754
+ "node_modules/attr-accept": {
1755
+ "version": "2.2.2",
1756
+ "resolved": "https://registry.npmjs.org/attr-accept/-/attr-accept-2.2.2.tgz",
1757
+ "integrity": "sha512-7prDjvt9HmqiZ0cl5CRjtS84sEyhsHP2coDkaZKRKVfCDo9s7iw7ChVmar78Gu9pC4SoR/28wFu/G5JJhTnqEg==",
1758
+ "engines": {
1759
+ "node": ">=4"
1760
+ }
1761
+ },
1762
  "node_modules/autoprefixer": {
1763
  "version": "10.4.14",
1764
  "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.14.tgz",
 
3108
  "node": "^10.12.0 || >=12.0.0"
3109
  }
3110
  },
3111
+ "node_modules/file-selector": {
3112
+ "version": "0.6.0",
3113
+ "resolved": "https://registry.npmjs.org/file-selector/-/file-selector-0.6.0.tgz",
3114
+ "integrity": "sha512-QlZ5yJC0VxHxQQsQhXvBaC7VRJ2uaxTf+Tfpu4Z/OcVQJVpZO+DGU0rkoVW5ce2SccxugvpBJoMvUs59iILYdw==",
3115
+ "dependencies": {
3116
+ "tslib": "^2.4.0"
3117
+ },
3118
+ "engines": {
3119
+ "node": ">= 12"
3120
+ }
3121
+ },
3122
  "node_modules/filelist": {
3123
  "version": "1.0.4",
3124
  "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz",
 
5403
  "react": "^18.2.0"
5404
  }
5405
  },
5406
+ "node_modules/react-dropzone": {
5407
+ "version": "14.2.3",
5408
+ "resolved": "https://registry.npmjs.org/react-dropzone/-/react-dropzone-14.2.3.tgz",
5409
+ "integrity": "sha512-O3om8I+PkFKbxCukfIR3QAGftYXDZfOE2N1mr/7qebQJHs7U+/RSL/9xomJNpRg9kM5h9soQSdf0Gc7OHF5Fug==",
5410
+ "dependencies": {
5411
+ "attr-accept": "^2.2.2",
5412
+ "file-selector": "^0.6.0",
5413
+ "prop-types": "^15.8.1"
5414
+ },
5415
+ "engines": {
5416
+ "node": ">= 10.13"
5417
+ },
5418
+ "peerDependencies": {
5419
+ "react": ">= 16.8 || 18.0.0"
5420
+ }
5421
+ },
5422
  "node_modules/react-is": {
5423
  "version": "16.13.1",
5424
  "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
package.json CHANGED
@@ -22,6 +22,7 @@
22
  "next": "13.4.2",
23
  "react": "18.2.0",
24
  "react-dom": "18.2.0",
 
25
  "react95": "^4.0.0",
26
  "typescript": "5.0.4",
27
  "uuid": "^9.0.0"
 
22
  "next": "13.4.2",
23
  "react": "18.2.0",
24
  "react-dom": "18.2.0",
25
+ "react-dropzone": "^14.2.3",
26
  "react95": "^4.0.0",
27
  "typescript": "5.0.4",
28
  "uuid": "^9.0.0"
src/components/ChatWindow.jsx CHANGED
@@ -2,7 +2,7 @@ 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
 
8
  function ChatWindow({
@@ -64,6 +64,7 @@ function ChatWindow({
64
  <form onSubmit={handleSubmit}>
65
  <div className="flex">
66
  <input
 
67
  value={userInput}
68
  placeholder="Say something..."
69
  onChange={handleChange}
@@ -75,8 +76,10 @@ function ChatWindow({
75
  <span>is typing...</span>
76
  )}
77
  </div>
 
78
  <div className="flex justify-start m-2">
79
  <div>
 
80
  <button
81
  onClick={handleSubmit}
82
  className="submit"
@@ -95,6 +98,9 @@ function ChatWindow({
95
  height="40"
96
  />
97
  </button>
 
 
 
98
  <div
99
  className="w-full h-1 mt-2"
100
  style={{
@@ -105,6 +111,7 @@ function ChatWindow({
105
  marginTop: "2px",
106
  }}
107
  ></div>
 
108
  </div>
109
  </div>
110
  </div>
 
2
  import Image from "next/image";
3
  import { useCallback, useEffect, useState } from "react";
4
  import MessageList from './MessageList';
5
+ import {FileLoader} from './FileLoader';
6
  import Loader from "./Loader";
7
 
8
  function ChatWindow({
 
64
  <form onSubmit={handleSubmit}>
65
  <div className="flex">
66
  <input
67
+ style={{ width: '95%', padding: '10px'}}
68
  value={userInput}
69
  placeholder="Say something..."
70
  onChange={handleChange}
 
76
  <span>is typing...</span>
77
  )}
78
  </div>
79
+
80
  <div className="flex justify-start m-2">
81
  <div>
82
+ <div>
83
  <button
84
  onClick={handleSubmit}
85
  className="submit"
 
98
  height="40"
99
  />
100
  </button>
101
+ <FileLoader />
102
+ </div>
103
+
104
  <div
105
  className="w-full h-1 mt-2"
106
  style={{
 
111
  marginTop: "2px",
112
  }}
113
  ></div>
114
+
115
  </div>
116
  </div>
117
  </div>
src/components/FileEmbedder.tsx ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useCallback, useState } from 'react';
2
+ import { useDropzone } from 'react-dropzone';
3
+ interface FileEmbedderProps {
4
+ handleEmbed: (acceptedFiles: File[]) => void;
5
+ }
6
+
7
+ export const FileEmbedder: React.FC<FileEmbedderProps> = ({ handleEmbed }) => {
8
+ const [isDragActive, setIsDragActive] = useState(false);
9
+
10
+ const onDrop = useCallback(
11
+ (acceptedFiles: File[]) => {
12
+ handleEmbed(acceptedFiles);
13
+ setIsDragActive(false);
14
+ },
15
+ [handleEmbed],
16
+ );
17
+
18
+ const { acceptedFiles, getRootProps, getInputProps, isDragReject } =
19
+ useDropzone({
20
+ onDrop,
21
+ accept: {
22
+ 'application/pdf': ['.pdf'],
23
+ 'text/plain': ['.txt', '.md'],
24
+ },
25
+ onDragEnter: () => setIsDragActive(true),
26
+ onDragLeave: () => setIsDragActive(false),
27
+ });
28
+
29
+ const acceptedFileItems = acceptedFiles.map((file: any) => (
30
+ <li key={file.name}>
31
+ {file.name} - {file.size} bytes
32
+ </li>
33
+ ));
34
+
35
+ return (
36
+ <>
37
+ <div
38
+ {...getRootProps()}
39
+ className={`border-2 border-dashed border-gray-300 p-6 rounded-md cursor-pointer ${
40
+ isDragActive ? 'active' : ''
41
+ } ${isDragReject ? 'reject' : ''}`}
42
+ >
43
+ <input {...getInputProps()} />
44
+ {isDragActive ? (
45
+ <p>Drop the files here...</p>
46
+ ) : (
47
+ <p><u>Click or drag and drop files here (PDF, MD, TXT)</u></p>
48
+ )}
49
+ </div>
50
+ <aside>
51
+ <ul>{acceptedFileItems}</ul>
52
+ </aside>
53
+ </>
54
+ );
55
+ };
src/components/FileLoader.tsx ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from 'react';
2
+ import { MouseEventHandler, ReactElement } from 'react';
3
+
4
+ import { FileEmbedder } from './FileEmbedder';
5
+
6
+ export const FileLoader = () => {
7
+ const [files, setFiles] = useState<File[]>()
8
+ const handleEmbed = (files: File[]) => {
9
+ setFiles(files)
10
+ console.log(files);
11
+ };
12
+
13
+ const handleClick: MouseEventHandler<HTMLButtonElement> = (e) => {
14
+ console.log(e);
15
+ };
16
+
17
+ return (
18
+ <>
19
+ <FileEmbedder handleEmbed={handleEmbed} />
20
+ <button
21
+ onClick={() => {
22
+ console.log('sure');
23
+ }}
24
+ >
25
+ <div>Embed</div>
26
+ </button>
27
+ </>
28
+ );
29
+ };
src/components/MessageList.jsx CHANGED
@@ -21,7 +21,7 @@ function MessageList({
21
  }, [conversation, messages.length]);
22
 
23
  return (
24
- <ScrollView style={{ height: "350px" }} className="w-full">
25
  <div className="p-2 leading-6 w-full min-h-full">
26
  {conversation?.messages.map((m) => (
27
  <div key={m.id} style={{ display: "flex" }}>
 
21
  }, [conversation, messages.length]);
22
 
23
  return (
24
+ <ScrollView style={{ height: "65vh" }} className="w-full">
25
  <div className="p-2 leading-6 w-full min-h-full">
26
  {conversation?.messages.map((m) => (
27
  <div key={m.id} style={{ display: "flex" }}>