pull latest
Showing
6 changed files
with
182 additions
and
16 deletions
| ... | @@ -210,6 +210,62 @@ | ... | @@ -210,6 +210,62 @@ |
| 210 | background:#066d55; | 210 | background:#066d55; |
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | .suggested { | ||
| 214 | display: block; | ||
| 215 | z-index: 99999999; | ||
| 216 | color: #000; | ||
| 217 | position: absolute; | ||
| 218 | text-align: center; | ||
| 219 | padding: 25px; | ||
| 220 | |||
| 221 | top: 0; | ||
| 222 | right: 0; | ||
| 223 | bottom: 89px; | ||
| 224 | left: 0; | ||
| 225 | overflow-y: scroll; | ||
| 226 | } | ||
| 227 | |||
| 228 | .suggestedcol { | ||
| 229 | width: 30%; | ||
| 230 | display: inline-block; | ||
| 231 | margin: 0; | ||
| 232 | text-align: center; | ||
| 233 | vertical-align: top; | ||
| 234 | } | ||
| 235 | |||
| 236 | .suggestedcol ul { | ||
| 237 | list-style: none; | ||
| 238 | padding: 0 25px; | ||
| 239 | } | ||
| 240 | |||
| 241 | .suggestedrow.title { | ||
| 242 | padding: 4vw 20px; | ||
| 243 | } | ||
| 244 | |||
| 245 | .suggestedcol ul li { | ||
| 246 | background: #5c6aa529; | ||
| 247 | padding: 10px; | ||
| 248 | border-radius: 5px; | ||
| 249 | margin: 0 0 10px; | ||
| 250 | } | ||
| 251 | |||
| 252 | ul.suggested-options { | ||
| 253 | cursor: pointer; | ||
| 254 | overflow-x: hidden; | ||
| 255 | height: 200px; | ||
| 256 | padding-right: 5px !important; | ||
| 257 | } | ||
| 258 | |||
| 259 | |||
| 260 | @media (max-width: 991px) { | ||
| 261 | .suggestedcol { | ||
| 262 | width: 100%; | ||
| 263 | } | ||
| 264 | .suggestedrow.title { | ||
| 265 | padding: 10px 10px 0 10px; | ||
| 266 | } | ||
| 267 | } | ||
| 268 | |||
| 213 | .message .error_msg { | 269 | .message .error_msg { |
| 214 | background: rgb(18 0 255 / 20%); | 270 | background: rgb(18 0 255 / 20%); |
| 215 | padding: 10px; | 271 | padding: 10px; | ... | ... |
| ... | @@ -23,6 +23,8 @@ function App() { | ... | @@ -23,6 +23,8 @@ function App() { |
| 23 | // clear chats | 23 | // clear chats |
| 24 | function clearChat(){ | 24 | function clearChat(){ |
| 25 | setChatLog([]); | 25 | setChatLog([]); |
| 26 | setChatInput(""); | ||
| 27 | setStartedInteraction(false); | ||
| 26 | } | 28 | } |
| 27 | 29 | ||
| 28 | function getEngines(){ | 30 | function getEngines(){ |
| ... | @@ -43,7 +45,7 @@ function App() { | ... | @@ -43,7 +45,7 @@ function App() { |
| 43 | async function handleSubmit(e){ | 45 | async function handleSubmit(e){ |
| 44 | e.preventDefault(); | 46 | e.preventDefault(); |
| 45 | // console.log(chatInput) | 47 | // console.log(chatInput) |
| 46 | const userInput = ['what', 'why', 'when', 'where' , 'which', 'did', 'do', 'how', 'can', 'are', 'who', 'hey']; | 48 | const userInput = ['what', 'why', 'when', 'where' , 'which', 'did', 'do', 'how', 'can', 'are', 'who']; |
| 47 | const userInputRegex = new RegExp(`\\b(${userInput.join('|')})\\b`, 'gi'); | 49 | const userInputRegex = new RegExp(`\\b(${userInput.join('|')})\\b`, 'gi'); |
| 48 | const inputMatches = chatInput.match(userInputRegex); | 50 | const inputMatches = chatInput.match(userInputRegex); |
| 49 | 51 | ||
| ... | @@ -113,7 +115,7 @@ function App() { | ... | @@ -113,7 +115,7 @@ function App() { |
| 113 | } | 115 | } |
| 114 | 116 | ||
| 115 | } | 117 | } |
| 116 | 118 | const [startedInteraction, setStartedInteraction] = useState(false); | |
| 117 | return ( | 119 | return ( |
| 118 | <div className="App"> | 120 | <div className="App"> |
| 119 | <SideMenu | 121 | <SideMenu |
| ... | @@ -124,10 +126,13 @@ function App() { | ... | @@ -124,10 +126,13 @@ function App() { |
| 124 | temperature={temperature} | 126 | temperature={temperature} |
| 125 | clearChat={clearChat} | 127 | clearChat={clearChat} |
| 126 | /> | 128 | /> |
| 129 | |||
| 127 | <ChatBox | 130 | <ChatBox |
| 128 | chatInput={chatInput} | 131 | chatInput={chatInput} |
| 129 | chatLog={chatLog} | 132 | chatLog={chatLog} |
| 130 | setChatInput={setChatInput} | 133 | setChatInput={setChatInput} |
| 134 | startedInteraction={startedInteraction} | ||
| 135 | setStartedInteraction={setStartedInteraction} | ||
| 131 | handleSubmit={handleSubmit} /> | 136 | handleSubmit={handleSubmit} /> |
| 132 | </div> | 137 | </div> |
| 133 | ); | 138 | ); | ... | ... |
| 1 | // import OpenAISVGLogo from './OpenAISVGLogo' | 1 | import React, { useState } from "react"; |
| 2 | import SuggestedOptions from './suggestedOptions' | ||
| 2 | 3 | ||
| 3 | // Primary Chat Window | 4 | const ChatBox = ({chatLog, setChatInput, handleSubmit, chatInput, startedInteraction, setStartedInteraction}) => { |
| 4 | const ChatBox = ({chatLog, setChatInput, handleSubmit, chatInput}) => | 5 | |
| 6 | return ( | ||
| 5 | <section className="chatbox"> | 7 | <section className="chatbox"> |
| 8 | {!startedInteraction ? ( | ||
| 9 | <SuggestedOptions setChatInput={setChatInput}/> | ||
| 10 | ) : ( | ||
| 11 | <> | ||
| 6 | <div className="chat-log"> | 12 | <div className="chat-log"> |
| 7 | {chatLog.map((message, index) => ( | 13 | {chatLog.map((message, index) => ( |
| 8 | <ChatMessage key={index} message={message} /> | 14 | <ChatMessage key={index} message={message} /> |
| 9 | ))} | 15 | ))} |
| 10 | </div> | 16 | </div> |
| 17 | |||
| 18 | </> | ||
| 19 | )} | ||
| 11 | <div className="chat-input-holder"> | 20 | <div className="chat-input-holder"> |
| 12 | <form className="form" onSubmit={handleSubmit}> | 21 | <form className="form" onSubmit={handleSubmit }> |
| 13 | <input | 22 | <input |
| 14 | rows="1" | 23 | rows="1" |
| 15 | value={chatInput} | 24 | value={chatInput} |
| 16 | onChange={(e)=> setChatInput(e.target.value)} | 25 | onChange={(e)=> { |
| 17 | className="chat-input-textarea" ></input> | 26 | setChatInput(e.target.value); |
| 18 | <button className="submit" type="submit">Submit</button> | 27 | }} |
| 28 | className="chat-input-textarea" > | ||
| 29 | </input> | ||
| 30 | <button className="submit" type="submit" onClick={(e)=> { | ||
| 31 | setStartedInteraction(true); | ||
| 32 | }}>Submit</button> | ||
| 19 | </form> | 33 | </form> |
| 20 | </div> | 34 | </div> |
| 21 | </section> | 35 | </section> |
| 36 | ) | ||
| 37 | } | ||
| 22 | 38 | ||
| 23 | // Individual Chat Message | ||
| 24 | const ChatMessage = ({ message }) => { | 39 | const ChatMessage = ({ message }) => { |
| 25 | return ( | 40 | return ( |
| 26 | <div className={`chat-message ${message.user === "gpt" && "chatgpt"}`}> | 41 | <div className={`chat-message ${message.user === "gpt" && "chatgpt"}`}> | ... | ... |
| ... | @@ -172,6 +172,37 @@ span.info { | ... | @@ -172,6 +172,37 @@ span.info { |
| 172 | margin: 15px 5px; | 172 | margin: 15px 5px; |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | .suggested::-webkit-scrollbar { | ||
| 176 | display: none; | ||
| 177 | } | ||
| 178 | |||
| 179 | ul.suggested-options::-webkit-scrollbar{ | ||
| 180 | /*display: none;*/ | ||
| 181 | } | ||
| 182 | |||
| 183 | /* Let's get this party started */ | ||
| 184 | ul.suggested-options::-webkit-scrollbar { | ||
| 185 | width: 8px; | ||
| 186 | } | ||
| 187 | |||
| 188 | /* Track */ | ||
| 189 | ul.suggested-options::-webkit-scrollbar-track { | ||
| 190 | -webkit-border-radius: 0px; | ||
| 191 | border-radius: 0px; | ||
| 192 | } | ||
| 193 | |||
| 194 | /* Handle */ | ||
| 195 | ul.suggested-options::-webkit-scrollbar-thumb { | ||
| 196 | -webkit-border-radius: 10px; | ||
| 197 | border-radius: 10px; | ||
| 198 | background: #48b0e9; | ||
| 199 | } | ||
| 200 | ul.suggested-options::-webkit-scrollbar-thumb:window-inactive { | ||
| 201 | background: #4291bd; | ||
| 202 | } | ||
| 203 | |||
| 204 | |||
| 205 | |||
| 175 | code br:nth-child(-n+2) { | 206 | code br:nth-child(-n+2) { |
| 176 | display: none; | 207 | display: none; |
| 177 | } | 208 | } | ... | ... |
client/src/suggestedOptions.js
0 → 100644
| 1 | const SuggestedOptions = ({ setChatInput }) => { | ||
| 2 | const examples = [ | ||
| 3 | "Write an email requesting a 3-day vacation leave to my manager.", | ||
| 4 | "Compose a song about nationalism and love for the country.", | ||
| 5 | "Give me 3 easy-to-cook food recipes that I can prepare for a date night at home.", | ||
| 6 | "Give me 5 of the best dog shampoos and conditioners I can find on Amazon.", | ||
| 7 | "Write a business pitch for a food truck that serves European-Asian food fusion called EAT Express.", | ||
| 8 | "Write a Youtube script about how to file taxes as a social media influencer in the US.", | ||
| 9 | "Write a resume for an architect with 3 years of experience with green technology and sustainability.", | ||
| 10 | "Give me 7 motivational quotes for start-up businesses to be used in social media posts.", | ||
| 11 | "Write an article outline about the comparison of DC and Marvel movies.", | ||
| 12 | "Give me a one-week itinerary for a trip to Hawaii.", | ||
| 13 | "Write a short children's story about a dolphin that wanted to fly.", | ||
| 14 | "Explain the difference between a samurai and a ninja.", | ||
| 15 | "Explain how to create a blue button in html that turns to yellow on mouse hover." | ||
| 16 | ]; | ||
| 17 | const handleExampleClick = (example) => { | ||
| 18 | setChatInput(example); | ||
| 19 | }; | ||
| 20 | |||
| 21 | return ( | ||
| 22 | <div className="suggested"> | ||
| 23 | <div className="suggestedrow title"> | ||
| 24 | <h1>Welcome to AI-PRO</h1> | ||
| 25 | <p>This chatbot is capable of answering questions and generating text based on the input you provide.</p> | ||
| 26 | </div> | ||
| 27 | <div className="suggestedcol rack1"> | ||
| 28 | <h2>Examples</h2> | ||
| 29 | <ul className="suggested-options"> | ||
| 30 | {examples.map((example, index) => ( | ||
| 31 | <li key={index} | ||
| 32 | onClick={() => handleExampleClick(example)}> | ||
| 33 | {example} | ||
| 34 | </li> | ||
| 35 | ))} | ||
| 36 | </ul> | ||
| 37 | </div> | ||
| 38 | <div className="suggestedcol rack2"> | ||
| 39 | <h2>Capabilities</h2> | ||
| 40 | <ul> | ||
| 41 | <li>Remembers the user's earlier statement in the ongoing discussion.</li> | ||
| 42 | <li>Allows the user to add more information or correct errors.</li> | ||
| 43 | <li>Trained to deny requests that are not appropriate.</li> | ||
| 44 | </ul> | ||
| 45 | </div> | ||
| 46 | <div className="suggestedcol rack3"> | ||
| 47 | <h2>Limitations</h2> | ||
| 48 | <ul> | ||
| 49 | <li>May sometimes give wrong or incorrect information.</li> | ||
| 50 | <li>May at times produce harmful instructions or biased content.</li> | ||
| 51 | <li>Limited knowledge of what's been happening in the world since 2021.</li> | ||
| 52 | </ul> | ||
| 53 | </div> | ||
| 54 | </div> | ||
| 55 | ); | ||
| 56 | |||
| 57 | }; | ||
| 58 | |||
| 59 | export default SuggestedOptions; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -34,10 +34,13 @@ app.use(rateLimiter) | ... | @@ -34,10 +34,13 @@ app.use(rateLimiter) |
| 34 | app.post('/api', async (req, res) => { | 34 | app.post('/api', async (req, res) => { |
| 35 | const { message, currentModel, temperature } = req.body; | 35 | const { message, currentModel, temperature } = req.body; |
| 36 | 36 | ||
| 37 | let query_prompt = `${message}`; | 37 | let greetingPrompt = 'Hello, how can I assist you?' |
| 38 | 38 | const greetings = ['hi', 'hello', 'hey'] | |
| 39 | if (greetings.some((greeting) => message.toLowerCase().includes(greeting))) { | ||
| 40 | greetingPrompt = 'Hello, how can I help you today?' | ||
| 41 | } | ||
| 42 | let query_prompt = `${greetingPrompt}\n${message}`; | ||
| 39 | str_length = req.body.message.split(' ').length; | 43 | str_length = req.body.message.split(' ').length; |
| 40 | |||
| 41 | if (str_length>=800){ | 44 | if (str_length>=800){ |
| 42 | arr_body = req.body.message.split("\n"); | 45 | arr_body = req.body.message.split("\n"); |
| 43 | if (arr_body.length>=4){ | 46 | if (arr_body.length>=4){ |
| ... | @@ -48,7 +51,6 @@ app.post('/api', async (req, res) => { | ... | @@ -48,7 +51,6 @@ app.post('/api', async (req, res) => { |
| 48 | query_prompt = arr_body.join("\n") | 51 | query_prompt = arr_body.join("\n") |
| 49 | } | 52 | } |
| 50 | } | 53 | } |
| 51 | |||
| 52 | try { | 54 | try { |
| 53 | const response = await openai.createCompletion({ | 55 | const response = await openai.createCompletion({ |
| 54 | model: `${currentModel}`,// "text-davinci-003", | 56 | model: `${currentModel}`,// "text-davinci-003", |
| ... | @@ -56,11 +58,9 @@ app.post('/api', async (req, res) => { | ... | @@ -56,11 +58,9 @@ app.post('/api', async (req, res) => { |
| 56 | max_tokens: 3000, | 58 | max_tokens: 3000, |
| 57 | temperature, | 59 | temperature, |
| 58 | }); | 60 | }); |
| 59 | |||
| 60 | res.json({ | 61 | res.json({ |
| 61 | message: response.data.choices[0].text, | 62 | message: response.data.choices[0].text, |
| 62 | }) | 63 | }) |
| 63 | |||
| 64 | } catch (e) { | 64 | } catch (e) { |
| 65 | let error_msg = e.response.data.error.message ? e.response.data.error.message : ''; | 65 | let error_msg = e.response.data.error.message ? e.response.data.error.message : ''; |
| 66 | if (error_msg.indexOf('maximum context length')>=0){ | 66 | if (error_msg.indexOf('maximum context length')>=0){ | ... | ... |
-
Please register or sign in to post a comment