fix
Showing
8 changed files
with
142 additions
and
40 deletions
| 1 | # ChatGPT AI-Pro Installation | ||
| 2 | |||
| 3 | ## Setting up local development | ||
| 4 | |||
| 5 | ### Set up ENV Variables | ||
| 6 | 1. Set up environment variable `.env` file in root and inside */client* folder. In root, duplicate the `env-template` file and rename it to `.env`. Inside the */client* folder, create `.env` file | ||
| 7 | 2. In the root `.env` file, define the needed OpenAI environment variables in your application. | ||
| 8 | |||
| 9 | * Sign up here [https://beta.openai.com/signup](https://beta.openai.com/signup). You can use your Google or Microsoft account to sign up if you don't want to create using an email/password combination. You may need a valid mobile number to verify your account. | ||
| 10 | * Now, visit your OpenAI key page [https://beta.openai.com/account/api-keys](https://beta.openai.com/account/api-keys) | ||
| 11 | * Create a new key by clicking the "Create new secret key" button. | ||
| 12 | |||
| 13 | 3. You can Values should be a string, enclosed with ``""`` Example : | ||
| 14 | |||
| 15 | ``` | ||
| 16 | OPENAI_API_KEY=“sk-xxxxxxx” | ||
| 17 | OPENAI_API_ORG=“org-xxxxxxxx” | ||
| 18 | ``` | ||
| 19 | |||
| 20 | 4. In the `.env` file of the client, define the SERVER_URL environment variable in your application. | ||
| 21 | 5. Name the variable starting with **REACT_APP_** and Value must **not** enclosed with commas `""` Example : | ||
| 22 | |||
| 23 | ``` | ||
| 24 | REACT_APP_SERVER_URL=http://localhost:3080/ | ||
| 25 | ``` | ||
| 26 | |||
| 27 | ### NPM Install and Run Application | ||
| 28 | **Note:** Prepare 2 Terminals. | ||
| 29 | 1. On the first terminal, run `npm install` on **root**. After that run `node index.js` | ||
| 30 | 2. On the second terminal, run `npm install` inside the **/client**. Then run `npm run start` | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | # ChatGPT Server | ||
| 2 | |||
| 3 | ## Installation | ||
| 4 | |||
| 5 | npm install on the root directory. | ||
| 6 | |||
| 7 | ## Create ENV Variables | ||
| 8 | |||
| 9 | Create an .env file in the root directory of your application. | ||
| 10 | Duplicate the env-template and rename to .env | ||
| 11 | In the .env file, define the environment variables you want to use in your application. ex. | ||
| 12 | |||
| 13 | `API_KEY="sk-xxxxxxxx"` | ||
| 14 | `API_ORG="org-xxxxxxx"` | ||
| 15 | |||
| 16 | ## Run server | ||
| 17 | |||
| 18 | Run server on the root directory | ||
| 19 | |||
| 20 | `node index.js` | ||
| 21 | |||
| 22 | ### Additional Configuration | ||
| 23 | |||
| 24 | After running server, proceed to /client README.md for instructions | ... | ... |
| ... | @@ -6,6 +6,15 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo | ... | @@ -6,6 +6,15 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo |
| 6 | 6 | ||
| 7 | npm install on the /client directory. | 7 | npm install on the /client directory. |
| 8 | 8 | ||
| 9 | |||
| 10 | ## Create ENV Variables | ||
| 11 | |||
| 12 | Create an .env file in the /client directory of your application. | ||
| 13 | Duplicate the env-template and rename to .env | ||
| 14 | In the .env file, define the environment variables you want to use in your application. ex. | ||
| 15 | |||
| 16 | REACT_APP_SERVER_URL=http://xxxxxx/ | ||
| 17 | |||
| 9 | ## Available Scripts | 18 | ## Available Scripts |
| 10 | 19 | ||
| 11 | In the /client directory, you can run: | 20 | In the /client directory, you can run: | ... | ... |
client/env-template
0 → 100644
| 1 | REACT_APP_SERVER_URL= | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -26,10 +26,10 @@ function App() { | ... | @@ -26,10 +26,10 @@ function App() { |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | function getEngines(){ | 28 | function getEngines(){ |
| 29 | fetch(process.env.SERVER_URL + "models") | 29 | fetch(process.env.REACT_APP_SERVER_URL + "/models") |
| 30 | .then(res => res.json()) | 30 | .then(res => res.json()) |
| 31 | .then(data => { | 31 | .then(data => { |
| 32 | console.log(data.models.data) | 32 | // console.log(data.models.data) |
| 33 | // set models in order alpahbetically | 33 | // set models in order alpahbetically |
| 34 | data.models.data.sort((a, b) => { | 34 | data.models.data.sort((a, b) => { |
| 35 | if(a.id < b.id) { return -1; } | 35 | if(a.id < b.id) { return -1; } |
| ... | @@ -48,7 +48,7 @@ function App() { | ... | @@ -48,7 +48,7 @@ function App() { |
| 48 | // fetch response to the api combining the chat log array of messages and seinding it as a message to localhost:3000 as a post | 48 | // fetch response to the api combining the chat log array of messages and seinding it as a message to localhost:3000 as a post |
| 49 | const messages = chatLogNew.map((message) => message.message).join("\n") | 49 | const messages = chatLogNew.map((message) => message.message).join("\n") |
| 50 | 50 | ||
| 51 | const response = await fetch(process.env.SERVER_URL + "api", { | 51 | const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { |
| 52 | method: "POST", | 52 | method: "POST", |
| 53 | headers: { | 53 | headers: { |
| 54 | "Content-Type": "application/json" | 54 | "Content-Type": "application/json" |
| ... | @@ -59,7 +59,25 @@ function App() { | ... | @@ -59,7 +59,25 @@ function App() { |
| 59 | }) | 59 | }) |
| 60 | }); | 60 | }); |
| 61 | const data = await response.json(); | 61 | const data = await response.json(); |
| 62 | setChatLog([...chatLogNew, { user: "gpt", message: `${data.message}`} ]) | 62 | const parsedData = data.message.trim(); |
| 63 | console.log(parsedData) | ||
| 64 | const programmingKeywords = ['code', 'application', 'controller', 'rails' , 'PHP', 'java', 'javascript', 'script', 'console', 'python', 'programming', 'table']; | ||
| 65 | |||
| 66 | const regex = new RegExp(`\\b(${programmingKeywords.join('|')})\\b`, 'gi'); | ||
| 67 | // console.log(regex) | ||
| 68 | const matches = parsedData.match(regex); | ||
| 69 | // console.log(matches); | ||
| 70 | if (!matches) { | ||
| 71 | var replaceTags = (parsedData.replace(/(?:\r\n|\r|\n)/g, '<br>').replace(/\./g, '. ')) | ||
| 72 | // console.log("not programming!") | ||
| 73 | } else { | ||
| 74 | replaceTags = (parsedData.replace(':',':<code>').replace('<?','<?').replace('?>','?>').replace(/\n/g, '<br>')) | ||
| 75 | // console.log("programming!") | ||
| 76 | //.replace('<?','<' + '?').replace('?>','?'+'>') | ||
| 77 | } | ||
| 78 | setChatLog([...chatLogNew, { user: "gpt", message: `${replaceTags}`} ]) | ||
| 79 | |||
| 80 | // setChatLog([...chatLogNew, { user: "gpt", message: `<div>${parsedData}</div>`} ]) | ||
| 63 | var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0]; | 81 | var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0]; |
| 64 | scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight; | 82 | scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight; |
| 65 | } | 83 | } | ... | ... |
| ... | @@ -38,10 +38,15 @@ span.info { | ... | @@ -38,10 +38,15 @@ span.info { |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | .chat-message.chatgpt { | 40 | .chat-message.chatgpt { |
| 41 | background-color:#ffffff !important; | 41 | background: #feffff; /* Old browsers */ |
| 42 | background: -moz-linear-gradient(45deg, #feffff 0%, #ddf1f9 55%, #eff7f5 98%); /* FF3.6-15 */ | ||
| 43 | background: -webkit-linear-gradient(45deg, #feffff 0%,#ddf1f9 55%,#eff7f5 98%); /* Chrome10-25,Safari5.1-6 */ | ||
| 44 | background: linear-gradient(45deg, #feffff 0%,#ddf1f9 55%,#eff7f5 98%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */ | ||
| 45 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#feffff', endColorstr='#eff7f5',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */ | ||
| 42 | } | 46 | } |
| 43 | .chat-message-center { | 47 | .chat-message-center { |
| 44 | padding: 20px 10px !important; | 48 | padding: 20px 10vw !important; |
| 49 | max-width: none; | ||
| 45 | } | 50 | } |
| 46 | 51 | ||
| 47 | .avatar { | 52 | .avatar { |
| ... | @@ -56,6 +61,34 @@ span.info { | ... | @@ -56,6 +61,34 @@ span.info { |
| 56 | border-radius:5px !important; | 61 | border-radius:5px !important; |
| 57 | box-shadow: 0px 5px 5px -3px black !important; | 62 | box-shadow: 0px 5px 5px -3px black !important; |
| 58 | } | 63 | } |
| 64 | |||
| 65 | .chat-log::-webkit-scrollbar{ | ||
| 66 | /*display: none;*/ | ||
| 67 | } | ||
| 68 | |||
| 69 | /* Let's get this party started */ | ||
| 70 | .chat-log::-webkit-scrollbar { | ||
| 71 | width: 8px; | ||
| 72 | } | ||
| 73 | |||
| 74 | /* Track */ | ||
| 75 | .chat-log::-webkit-scrollbar-track { | ||
| 76 | /*-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);*/ | ||
| 77 | -webkit-border-radius: 0px; | ||
| 78 | border-radius: 0px; | ||
| 79 | } | ||
| 80 | |||
| 81 | /* Handle */ | ||
| 82 | .chat-log::-webkit-scrollbar-thumb { | ||
| 83 | -webkit-border-radius: 10px; | ||
| 84 | border-radius: 10px; | ||
| 85 | background: #cccccc; | ||
| 86 | -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); | ||
| 87 | } | ||
| 88 | .chat-log::-webkit-scrollbar-thumb:window-inactive { | ||
| 89 | background: #eeeeee; | ||
| 90 | } | ||
| 91 | |||
| 59 | .message { | 92 | .message { |
| 60 | padding: 7px 20px !important; | 93 | padding: 7px 20px !important; |
| 61 | line-height: 25px; | 94 | line-height: 25px; |
| ... | @@ -98,4 +131,50 @@ span.info { | ... | @@ -98,4 +131,50 @@ span.info { |
| 98 | .ai-logo-container { | 131 | .ai-logo-container { |
| 99 | text-align: center; | 132 | text-align: center; |
| 100 | padding: 10px 0; | 133 | padding: 10px 0; |
| 134 | } | ||
| 135 | |||
| 136 | .message code { | ||
| 137 | background: #303030; | ||
| 138 | width: 100%; | ||
| 139 | color: #fff; | ||
| 140 | padding: 15px 20px; | ||
| 141 | border-radius: 10px; | ||
| 142 | font-family: monospace, sans-serif; | ||
| 143 | font-size: 12px; | ||
| 144 | display: block; | ||
| 145 | margin: 15px 5px; | ||
| 146 | } | ||
| 147 | |||
| 148 | code br:nth-child(-n+2) { | ||
| 149 | display: none; | ||
| 150 | } | ||
| 151 | |||
| 152 | @media (min-width: 1280px) { | ||
| 153 | .message { | ||
| 154 | font-size: 18px; | ||
| 155 | } | ||
| 156 | } | ||
| 157 | |||
| 158 | @media (max-width: 1279px) { | ||
| 159 | .message { | ||
| 160 | font-size: 16px; | ||
| 161 | } | ||
| 162 | } | ||
| 163 | |||
| 164 | @media (max-width: 991px) { | ||
| 165 | .message { | ||
| 166 | font-size: 14px; | ||
| 167 | } | ||
| 168 | .chat-message-center { | ||
| 169 | padding: 20px 5vw !important; | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | @media (max-width: 414px) { | ||
| 174 | .message { | ||
| 175 | font-size: 14px; | ||
| 176 | } | ||
| 177 | .chat-message-center { | ||
| 178 | padding: 20px 5vw !important; | ||
| 179 | } | ||
| 101 | } | 180 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -5,7 +5,7 @@ const cors = require('cors') | ... | @@ -5,7 +5,7 @@ const cors = require('cors') |
| 5 | require('dotenv').config() | 5 | require('dotenv').config() |
| 6 | 6 | ||
| 7 | // Open AI Configuration | 7 | // Open AI Configuration |
| 8 | console.log(process.env.OPENAI_API_ORG) | 8 | // console.log(process.env.OPENAI_API_ORG) |
| 9 | const configuration = new Configuration({ | 9 | const configuration = new Configuration({ |
| 10 | organization: process.env.OPENAI_API_ORG, | 10 | organization: process.env.OPENAI_API_ORG, |
| 11 | apiKey: process.env.OPENAI_API_KEY, | 11 | apiKey: process.env.OPENAI_API_KEY, |
| ... | @@ -32,6 +32,7 @@ app.post('/api', async (req, res) => { | ... | @@ -32,6 +32,7 @@ app.post('/api', async (req, res) => { |
| 32 | max_tokens: 2500, | 32 | max_tokens: 2500, |
| 33 | temperature, | 33 | temperature, |
| 34 | }); | 34 | }); |
| 35 | |||
| 35 | res.json({ | 36 | res.json({ |
| 36 | message: response.data.choices[0].text, | 37 | message: response.data.choices[0].text, |
| 37 | }) | 38 | }) | ... | ... |
-
Please register or sign in to post a comment