0a4a261d by Ryan

Merge branch '26903_chatgpt_output_error' into 'master'

26903 chatgpt output error

See merge request !12
2 parents 3f4efe8d ed824fdc
1 node_modules 1 node_modules
2 .env
...\ 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
...\ No newline at end of file ...\ No newline at end of file
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
2 2
3 # dependencies 3 # dependencies
4 /node_modules 4 /node_modules
5 node_modules
6 /.pnp 5 /.pnp
7 .pnp.js 6 .pnp.js
8 7
...@@ -14,6 +13,7 @@ node_modules ...@@ -14,6 +13,7 @@ node_modules
14 13
15 # misc 14 # misc
16 .DS_Store 15 .DS_Store
16 .env
17 .env.local 17 .env.local
18 .env.development.local 18 .env.development.local
19 .env.test.local 19 .env.test.local
......
1 # ChatGPT Client
1 # Getting Started with Create React App 2 # Getting Started with Create React App
2
3 This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 3 This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 4
5 ## Installation
6
7 npm install on the /client directory.
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
5 ## Available Scripts 18 ## Available Scripts
6 19
7 In the project directory, you can run: 20 In the /client directory, you can run:
8 21
9 ### `npm start` 22 ### `npm start`
10 23
......
1 REACT_APP_SERVER_URL=
...\ No newline at end of file ...\ No newline at end of file
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
8 "@testing-library/user-event": "^13.5.0", 8 "@testing-library/user-event": "^13.5.0",
9 "react": "^18.2.0", 9 "react": "^18.2.0",
10 "react-dom": "^18.2.0", 10 "react-dom": "^18.2.0",
11 "react-openai-api": "^1.0.2",
12 "react-scripts": "5.0.1", 11 "react-scripts": "5.0.1",
13 "web-vitals": "^2.1.4" 12 "web-vitals": "^2.1.4"
14 }, 13 },
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
9 .sidemenu { 9 .sidemenu {
10 width:260px; 10 width:260px;
11 padding:10px; 11 padding:10px;
12 background-color: #202123; 12 background-color:#202123;
13 } 13 }
14 /* under 640px do this */ 14 /* under 640px do this */
15 @media (max-width: 640px) { 15 @media (max-width: 640px) {
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
34 padding-right:12px; 34 padding-right:12px;
35 } 35 }
36 36
37
38 .chatbox { 37 .chatbox {
39 flex:1; 38 flex:1;
40 background-color:#343541; 39 background-color:#343541;
...@@ -59,17 +58,16 @@ ...@@ -59,17 +58,16 @@
59 position:absolute; 58 position:absolute;
60 bottom:0; 59 bottom:0;
61 left:0;right:0; 60 left:0;right:0;
62 background: rgb(57 57 57);
63 } 61 }
64 .chat-input-textarea { 62 .chat-input-textarea {
65 background-color: #40414f; 63 background-color:#40414f;
66 width: 90%; 64 width:90%;
67 padding: 12px; 65 padding:12px;
68 border-radius: 5px; 66 border-radius:5px;
69 color: #ffffff; 67 color:white;
70 font-size: 1.25em; 68 font-size:1.25em;
71 border: none; 69 border:none;
72 outline: none; 70 outline:none;
73 box-shadow: 0 0 8px 0 rgba(0,0,0,0.25); 71 box-shadow: 0 0 8px 0 rgba(0,0,0,0.25);
74 } 72 }
75 73
...@@ -96,21 +94,20 @@ ...@@ -96,21 +94,20 @@
96 } 94 }
97 95
98 .chat-message.chatgpt { 96 .chat-message.chatgpt {
99 background-color:#ffffff; 97 background-color:#444654;
100 } 98 }
101 .chat-message-center { 99 .chat-message-center {
102 max-width:640px; 100 max-width:640px;
103 margin-left:auto; 101 margin-left:auto;
104 margin-right:auto; 102 margin-right:auto;
105 display:flex; 103 display:flex;
106 padding: 12px 24px; 104 padding:12px;
107 } 105 padding-left: 24px;
106 padding-right: 24px;
108 107
109 section::-webkit-scrollbar {
110 display: none;
111 } 108 }
112 .avatar { 109 .avatar {
113 background:#ffffff; 110 background:white;
114 border-radius:50%; 111 border-radius:50%;
115 width: 40px; 112 width: 40px;
116 height: 40px; 113 height: 40px;
...@@ -121,8 +118,6 @@ section::-webkit-scrollbar { ...@@ -121,8 +118,6 @@ section::-webkit-scrollbar {
121 font-size:14px; 118 font-size:14px;
122 color:#444654; 119 color:#444654;
123 } 120 }
124
125
126 .avatar.chatgpt { 121 .avatar.chatgpt {
127 background:#0da37f; 122 background:#0da37f;
128 border-radius:50%; 123 border-radius:50%;
...@@ -132,11 +127,8 @@ section::-webkit-scrollbar { ...@@ -132,11 +127,8 @@ section::-webkit-scrollbar {
132 color:white; 127 color:white;
133 } 128 }
134 .message { 129 .message {
135 padding: 7px 20px; 130 padding-left: 40px;
136 } 131 padding-right: 40px;
137
138 .chat-message.false {
139 background: #eef2ff;
140 } 132 }
141 133
142 @keyframes App-logo-spin { 134 @keyframes App-logo-spin {
...@@ -150,18 +142,18 @@ section::-webkit-scrollbar { ...@@ -150,18 +142,18 @@ section::-webkit-scrollbar {
150 142
151 .select-models { 143 .select-models {
152 border: 1px solid white; 144 border: 1px solid white;
153 padding: 12px; 145 padding:12px;
154 border-radius:5px; 146 border-radius:5px;
155 color: white; 147 color:white;
156 background: transparent; 148 background:transparent;
157 outline:none; 149 outline:none;
158 cursor:pointer; 150 cursor:pointer;
159 max-width:100%; 151 max-width:100%;
160 min-width:100%; 152 min-width:100%;
161 } 153 }
162 .select-models option { 154 .select-models option {
163 background: black; 155 background:black;
164 color: #ffffff; 156 color:white;
165 } 157 }
166 158
167 .button-picker { 159 .button-picker {
......
...@@ -4,7 +4,6 @@ import './color_theme_1.css'; ...@@ -4,7 +4,6 @@ import './color_theme_1.css';
4 import { useState, useEffect } from 'react'; 4 import { useState, useEffect } from 'react';
5 import SideMenu from './SideMenu' 5 import SideMenu from './SideMenu'
6 import ChatBox from './ChatBox' 6 import ChatBox from './ChatBox'
7 import OpenAIAPI from "react-openai-api";
8 7
9 function App() { 8 function App() {
10 9
...@@ -14,7 +13,7 @@ function App() { ...@@ -14,7 +13,7 @@ function App() {
14 13
15 const [chatInput, setChatInput] = useState(""); 14 const [chatInput, setChatInput] = useState("");
16 const [models, setModels] = useState([]); 15 const [models, setModels] = useState([]);
17 const [temperature, setTemperature] = useState(0.5); 16 const [temperature, setTemperature] = useState(0.7);
18 const [currentModel, setCurrentModel] = useState("text-davinci-003"); 17 const [currentModel, setCurrentModel] = useState("text-davinci-003");
19 const [chatLog, setChatLog] = useState([{ 18 const [chatLog, setChatLog] = useState([{
20 user: "gpt", 19 user: "gpt",
...@@ -27,10 +26,10 @@ function App() { ...@@ -27,10 +26,10 @@ function App() {
27 } 26 }
28 27
29 function getEngines(){ 28 function getEngines(){
30 fetch("http://localhost:3080/models") 29 fetch(process.env.REACT_APP_SERVER_URL + "/models")
31 .then(res => res.json()) 30 .then(res => res.json())
32 .then(data => { 31 .then(data => {
33 console.log(data.models.data) 32 // console.log(data.models.data)
34 // set models in order alpahbetically 33 // set models in order alpahbetically
35 data.models.data.sort((a, b) => { 34 data.models.data.sort((a, b) => {
36 if(a.id < b.id) { return -1; } 35 if(a.id < b.id) { return -1; }
...@@ -43,94 +42,76 @@ function App() { ...@@ -43,94 +42,76 @@ function App() {
43 42
44 async function handleSubmit(e){ 43 async function handleSubmit(e){
45 e.preventDefault(); 44 e.preventDefault();
46 let chatLogNew = [...chatLog, { user: "me", message: `${chatInput}`} ] 45 // console.log(chatInput)
46 const userInput = ['what', 'why', 'when', 'where' , 'which', 'did', 'do', 'how', 'can', 'are', 'who', 'hey'];
47 const userInputRegex = new RegExp(`\\b(${userInput.join('|')})\\b`, 'gi');
48 const inputMatches = chatInput.match(userInputRegex);
49
50 const userPunctuation = ['.', '?', '!', ':', ';', ','];
51 const userPunctuationRegex = new RegExp(`${userPunctuation.join('')}$`, 'gi');
52 const punctuationMatches = chatInput.match(userPunctuationRegex);
53
54 // console.log(punctuationMatches)
55 var userModifiedInput = chatInput
56
57 if (!punctuationMatches) {
58 if (!inputMatches) {
59 userModifiedInput = chatInput + ".";
60 // console.log("not a question!")
61 } else {
62 userModifiedInput = chatInput + "?";
63 // console.log("its a question!")
64 }
65 }
66
67 let chatLogNew = [...chatLog, { user: "me", message: `${userModifiedInput}`} ]
47 setChatInput(""); 68 setChatInput("");
48 setChatLog(chatLogNew) 69 setChatLog(chatLogNew)
70
49 // fetch response to the api combining the chat log array of messages and seinding it as a message to localhost:3000 as a post 71 // fetch response to the api combining the chat log array of messages and seinding it as a message to localhost:3000 as a post
50 const messages = chatLogNew.map((message) => message.message).join("\n") 72 const messages = chatLogNew.map((message) => message.message).join("\n")
51 73
52 74 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", {
53 // const response = await fetch("http://localhost:3080/", { 75 method: "POST",
54 // method: "POST", 76 headers: {
55 // headers: { 77 "Content-Type": "application/json"
56 // "Content-Type": "application/json" 78 },
57 // }, 79 body: JSON.stringify({
58 // body: JSON.stringify({ 80 message: messages,
59 // message: messages, 81 currentModel,
60 // currentModel, 82 })
61 // }) 83 });
62 // }); 84 const data = await response.json();
63 // const data = await response.json(); 85 const parsedData = data.message.trim();
64 // setChatLog([...chatLogNew, { user: "gpt", message: `${data.message}`} ]) 86 // console.log(parsedData)
65 // var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0]; 87 const programmingKeywords = ['code', 'application', 'controller', 'rails' , 'PHP', 'java', 'javascript', 'script', 'console', 'python', 'programming', 'table'];
66 // scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight; 88
67 89 const regex = new RegExp(`\\b(${programmingKeywords.join('|')})\\b`, 'gi');
68 var oHttp = new XMLHttpRequest(); 90 // console.log(regex)
69 oHttp.open("POST", "https://api.openai.com/v1/completions"); 91 const matches = parsedData.match(regex);
70 oHttp.setRequestHeader("Accept", "application/json"); 92 // console.log(matches);
71 oHttp.setRequestHeader("Content-Type", "application/json"); 93 if (!matches) {
72 oHttp.setRequestHeader("Authorization", "Bearer " + "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") 94 var replaceTags = (parsedData.replace(/(?:\r\n|\r|\n)/g, '<br>').replace(/\./g, '. '))
73 95 // console.log("not programming!")
74 oHttp.onreadystatechange = function () { 96 } else {
75 if (oHttp.readyState === 4) { 97 replaceTags = (parsedData.replace(':',':<code>').replace('<?','&#60;?').replace('?>','?&#62;').replace(/\n/g, '<br>'))
76 var s = '' 98 // console.log("programming!")
77 var oJson = {} 99 //.replace('<?','&#60;' + '?').replace('?>','?'+'&#62;')
78 if (s != "") s += "\n";
79 try {
80 oJson = JSON.parse(oHttp.responseText);
81 } catch (ex) {
82 s += "Error: " + ex.message
83 }
84 if (oJson.error && oJson.error.message) {
85 s += "Error: " + oJson.error.message;
86 } else if (oJson.choices && oJson.choices[0].text) {
87 s = oJson.choices[0].text;
88 var a = s.split("?\n");
89 if (a.length == 2) {
90 s = a[1];
91 }
92 // if (selLang.value != "en-US") {
93 // var a = s.split("?\n");
94 // if (a.length == 2) {
95 // s = a[1];
96 // }
97 // }
98 if (s == "") s = "No response";
99 console.log('ssssssssssssssssssssss',s);
100 var replaceBR= (s.replace(/(?:\r\n|\r|\n)/g, "<br>")).replace(/\r?\n|\r/, "");
101
102 setChatLog([...chatLogNew, { user: "gpt", message: `${replaceBR}`} ]);
103 }
104 }
105 };
106
107 var sModel = currentModel;// "text-davinci-003";
108 var iMaxTokens = 100;
109 var sUserId = "1";
110 var dTemperature =temperature;
111
112 var data = {
113 model: sModel,
114 prompt: messages,
115 max_tokens: iMaxTokens,
116 //user: sUserId,
117 temperature: dTemperature,
118 // frequency_penalty: 0.0, //Number between -2.0 and 2.0 Positive value decrease the model's likelihood to repeat the same line verbatim.
119 //presence_penalty: 0.0, //Number between -2.0 and 2.0. Positive values increase the model's likelihood to talk about new topics.
120 //stop: ["#", ";"] //Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
121 } 100 }
101 setChatLog([...chatLogNew, { user: "gpt", message: `${replaceTags}`} ])
122 102
123 oHttp.send(JSON.stringify(data));; 103 // setChatLog([...chatLogNew, { user: "gpt", message: `<div>${parsedData}</div>`} ])
124 104 var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0];
105 scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight;
125 } 106 }
126 107
127 function handleTemp(temp) { 108 function handleTemp(temp) {
128 if(temp > 1){ 109 if(temp > 1){
129 // setTemperature(1) 110 setTemperature(1)
130 } else if (temp < 0){ 111 } else if (temp < 0){
131 // setTemperature(0) 112 setTemperature(0)
132 } else { 113 } else {
133 // setTemperature(temp) 114 setTemperature(temp)
134 } 115 }
135 116
136 } 117 }
......
1 import OpenAISVGLogo from './OpenAISVGLogo' 1 // import OpenAISVGLogo from './OpenAISVGLogo'
2 2
3 // Primary Chat Window 3 // Primary Chat Window
4 const ChatBox = ({chatLog, setChatInput, handleSubmit, chatInput}) => 4 const ChatBox = ({chatLog, setChatInput, handleSubmit, chatInput}) =>
...@@ -26,7 +26,7 @@ const ChatMessage = ({ message }) => { ...@@ -26,7 +26,7 @@ const ChatMessage = ({ message }) => {
26 <div className={`chat-message ${message.user === "gpt" && "chatgpt"}`}> 26 <div className={`chat-message ${message.user === "gpt" && "chatgpt"}`}>
27 <div className="chat-message-center"> 27 <div className="chat-message-center">
28 <div className={`avatar ${message.user === "gpt" && "chatgpt"}`}> 28 <div className={`avatar ${message.user === "gpt" && "chatgpt"}`}>
29 {message.user === "gpt" ? <img className="ai-logo" src="../assets/images/bot.png" width="30px"/> : <img className="ai-logo" src="../assets/images/user.svg" />} 29 {message.user === "gpt" ? <img className="ai-logo" alt="Ai-pro bot" src="../assets/images/bot.png" width="30px"/> : <img className="ai-logo" alt="Ai-pro user" src="../assets/images/user.svg" />}
30 </div> 30 </div>
31 {/* <div className="message"> 31 {/* <div className="message">
32 {message.message} 32 {message.message}
......
1 const SideMenu = ({ clearChat, currentModel, setCurrentModel, models, setTemperature, temperature }) => 1 const SideMenu = ({ clearChat, currentModel, setCurrentModel, models, setTemperature, temperature }) =>
2 <aside className="sidemenu"> 2 <aside className="sidemenu">
3 <div className="ai-logo-container"> 3 <div className="ai-logo-container">
4 <img className="ai-logo" src="../assets/images/AIPRO-WHITE.png" height="50px"/> 4 <img className="ai-logo" alt="Ai-pro logo" src="../assets/images/AIPRO-WHITE.png" height="50px"/>
5 </div> 5 </div>
6 <div className="side-menu-button" onClick={clearChat}> 6 <div className="side-menu-button" onClick={clearChat}>
7 <span>+</span> 7 <span>+</span>
...@@ -57,7 +57,7 @@ const SideMenu = ({ clearChat, currentModel, setCurrentModel, models, setTempera ...@@ -57,7 +57,7 @@ const SideMenu = ({ clearChat, currentModel, setCurrentModel, models, setTempera
57 The temperature parameter controls the randomness of the model. 0 is the most logical, 1 is the most creative. 57 The temperature parameter controls the randomness of the model. 0 is the most logical, 1 is the most creative.
58 </span> 58 </span>
59 </div> 59 </div>
60 </aside> 60 </aside>
61 61
62 const Button = ({ onClick, text }) => 62 const Button = ({ onClick, text }) =>
63 <div 63 <div
......
...@@ -35,13 +35,19 @@ span.info { ...@@ -35,13 +35,19 @@ span.info {
35 color: #101827 !important; 35 color: #101827 !important;
36 font-size: 16px !important; 36 font-size: 16px !important;
37 box-shadow: 0px 7px 6px -6px black !important; 37 box-shadow: 0px 7px 6px -6px black !important;
38 height: 45px;
38 } 39 }
39 40
40 .chat-message.chatgpt { 41 .chat-message.chatgpt {
41 background-color:#ffffff !important; 42 background: #feffff; /* Old browsers */
43 background: -moz-linear-gradient(45deg, #feffff 0%, #ddf1f9 55%, #eff7f5 98%); /* FF3.6-15 */
44 background: -webkit-linear-gradient(45deg, #feffff 0%,#ddf1f9 55%,#eff7f5 98%); /* Chrome10-25,Safari5.1-6 */
45 background: linear-gradient(45deg, #feffff 0%,#ddf1f9 55%,#eff7f5 98%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
46 filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#feffff', endColorstr='#eff7f5',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
42 } 47 }
43 .chat-message-center { 48 .chat-message-center {
44 padding: 20px 10px !important; 49 padding: 20px 10vw !important;
50 max-width: none;
45 } 51 }
46 52
47 .avatar { 53 .avatar {
...@@ -56,6 +62,34 @@ span.info { ...@@ -56,6 +62,34 @@ span.info {
56 border-radius:5px !important; 62 border-radius:5px !important;
57 box-shadow: 0px 5px 5px -3px black !important; 63 box-shadow: 0px 5px 5px -3px black !important;
58 } 64 }
65
66 .chat-log::-webkit-scrollbar{
67 /*display: none;*/
68 }
69
70 /* Let's get this party started */
71 .chat-log::-webkit-scrollbar {
72 width: 8px;
73 }
74
75 /* Track */
76 .chat-log::-webkit-scrollbar-track {
77 /*-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);*/
78 -webkit-border-radius: 0px;
79 border-radius: 0px;
80 }
81
82 /* Handle */
83 .chat-log::-webkit-scrollbar-thumb {
84 -webkit-border-radius: 10px;
85 border-radius: 10px;
86 background: #cccccc;
87 -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
88 }
89 .chat-log::-webkit-scrollbar-thumb:window-inactive {
90 background: #eeeeee;
91 }
92
59 .message { 93 .message {
60 padding: 7px 20px !important; 94 padding: 7px 20px !important;
61 line-height: 25px; 95 line-height: 25px;
...@@ -99,3 +133,49 @@ span.info { ...@@ -99,3 +133,49 @@ span.info {
99 text-align: center; 133 text-align: center;
100 padding: 10px 0; 134 padding: 10px 0;
101 } 135 }
136
137 .message code {
138 background: #303030;
139 width: 100%;
140 color: #fff;
141 padding: 15px 20px;
142 border-radius: 10px;
143 font-family: monospace, sans-serif;
144 font-size: 12px;
145 display: block;
146 margin: 15px 5px;
147 }
148
149 code br:nth-child(-n+2) {
150 display: none;
151 }
152
153 @media (min-width: 1280px) {
154 .message {
155 font-size: 18px;
156 }
157 }
158
159 @media (max-width: 1279px) {
160 .message {
161 font-size: 16px;
162 }
163 }
164
165 @media (max-width: 991px) {
166 .message {
167 font-size: 14px;
168 }
169 .chat-message-center {
170 padding: 20px 5vw !important;
171 }
172 }
173
174 @media (max-width: 414px) {
175 .message {
176 font-size: 14px;
177 }
178 .chat-message-center {
179 padding: 20px 5vw !important;
180 }
181 }
...\ No newline at end of file ...\ No newline at end of file
......
1 OPENAI_API_ORG=
2 OPENAI_API_KEY=
...\ No newline at end of file ...\ No newline at end of file
...@@ -2,11 +2,13 @@ const { Configuration, OpenAIApi } = require("openai"); ...@@ -2,11 +2,13 @@ const { Configuration, OpenAIApi } = require("openai");
2 const express = require('express') 2 const express = require('express')
3 const bodyParser = require('body-parser') 3 const bodyParser = require('body-parser')
4 const cors = require('cors') 4 const cors = require('cors')
5 require('dotenv').config()
5 6
6 // Open AI Configuration 7 // Open AI Configuration
8 // console.log(process.env.OPENAI_API_ORG)
7 const configuration = new Configuration({ 9 const configuration = new Configuration({
8 organization: "org-2OIAoj4fSwE4RCzgvglUM55T", 10 organization: process.env.OPENAI_API_ORG,
9 apiKey: "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", 11 apiKey: process.env.OPENAI_API_KEY,
10 }); 12 });
11 const openai = new OpenAIApi(configuration); 13 const openai = new OpenAIApi(configuration);
12 14
...@@ -22,14 +24,15 @@ app.use(require('morgan')('dev')) ...@@ -22,14 +24,15 @@ app.use(require('morgan')('dev'))
22 // Routing 24 // Routing
23 25
24 // Primary Open AI Route 26 // Primary Open AI Route
25 app.post('/', async (req, res) => { 27 app.post('/api', async (req, res) => {
26 const { message, currentModel, temperature } = req.body; 28 const { message, currentModel, temperature } = req.body;
27 const response = await openai.createCompletion({ 29 const response = await openai.createCompletion({
28 model: `${currentModel}`,// "text-davinci-003", 30 model: `${currentModel}`,// "text-davinci-003",
29 prompt: `${message}`, 31 prompt: `${message}`,
30 max_tokens: 100, 32 max_tokens: 2500,
31 temperature, 33 temperature,
32 }); 34 });
35
33 res.json({ 36 res.json({
34 message: response.data.choices[0].text, 37 message: response.data.choices[0].text,
35 }) 38 })
......
...@@ -142,6 +142,11 @@ ...@@ -142,6 +142,11 @@
142 "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", 142 "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
143 "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==" 143 "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg=="
144 }, 144 },
145 "dotenv": {
146 "version": "16.0.3",
147 "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
148 "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ=="
149 },
145 "ee-first": { 150 "ee-first": {
146 "version": "1.1.1", 151 "version": "1.1.1",
147 "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", 152 "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
11 "dependencies": { 11 "dependencies": {
12 "body-parser": "^1.20.1", 12 "body-parser": "^1.20.1",
13 "cors": "^2.8.5", 13 "cors": "^2.8.5",
14 "dotenv": "^16.0.3",
14 "express": "^4.18.2", 15 "express": "^4.18.2",
15 "morgan": "^1.10.0", 16 "morgan": "^1.10.0",
16 "openai": "^3.1.0" 17 "openai": "^3.1.0"
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!