4bcf56e7 by Marwin Cañeta

#31531 - Apply tokenization logic on other LLMs

1 parent 0fe0aa08
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
6 "@testing-library/jest-dom": "^5.16.5", 6 "@testing-library/jest-dom": "^5.16.5",
7 "@testing-library/react": "^13.4.0", 7 "@testing-library/react": "^13.4.0",
8 "@testing-library/user-event": "^13.5.0", 8 "@testing-library/user-event": "^13.5.0",
9 "js-cookie": "^3.0.5",
9 "react": "^18.2.0", 10 "react": "^18.2.0",
10 "react-dom": "^18.2.0", 11 "react-dom": "^18.2.0",
11 "react-scripts": "5.0.1", 12 "react-scripts": "5.0.1",
......
...@@ -4,11 +4,13 @@ import './color_theme_1.css'; ...@@ -4,11 +4,13 @@ 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 Cookies from 'js-cookie'
7 8
8 function App() { 9 function App() {
9 10
10 useEffect(() => { 11 useEffect(() => {
11 getEngines(); 12 getEngines();
13 displayTogetherAiResponse()
12 }, []) 14 }, [])
13 15
14 const [chatInput, setChatInput] = useState(""); 16 const [chatInput, setChatInput] = useState("");
...@@ -30,6 +32,19 @@ function App() { ...@@ -30,6 +32,19 @@ function App() {
30 32
31 const [chatLogOpenSource, setChatLogOpenSource] = useState([]); 33 const [chatLogOpenSource, setChatLogOpenSource] = useState([]);
32 34
35 const displayTogetherAiResponse = () => {
36 const queryParams = new URLSearchParams(window.location.search)
37 const cookieName = 'P6XcW47o'
38 const exists = queryParams.has(cookieName)
39 const enable = queryParams.get(cookieName)
40
41 if (exists && (enable == '1' || enable == '0')) {
42 Cookies.set(cookieName, enable, {
43 expires: 1
44 })
45 }
46 }
47
33 function clearChat(){ 48 function clearChat(){
34 setChatLog([]); 49 setChatLog([]);
35 setChatLogTurbo(defaultChatLogTurbo); 50 setChatLogTurbo(defaultChatLogTurbo);
...@@ -115,6 +130,8 @@ function App() { ...@@ -115,6 +130,8 @@ function App() {
115 let intervalId = startInterval(); 130 let intervalId = startInterval();
116 131
117 try { 132 try {
133 const togetherAiResponse = Cookies.get('P6XcW47o') === '1'
134
118 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { 135 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", {
119 method: "POST", 136 method: "POST",
120 headers: { 137 headers: {
...@@ -123,12 +140,19 @@ function App() { ...@@ -123,12 +140,19 @@ function App() {
123 body: JSON.stringify({ 140 body: JSON.stringify({
124 message: messages, 141 message: messages,
125 currentModel, 142 currentModel,
126 temperature 143 temperature,
144 P6XcW47o: togetherAiResponse
127 }) 145 })
128 }); 146 });
129 const data = await response.json(); 147 const data = await response.json();
130 const parsedData = data.message ? data.message.trim() : ""; 148 const parsedData = data.message ? data.message.trim() : "";
131 149
150 if (togetherAiResponse) {
151 if (currentModel !== 'gpt-3.5-turbo') {
152 console.log(data)
153 }
154 }
155
132 if(data.status === 'invalid'){ 156 if(data.status === 'invalid'){
133 if(data.limited) { 157 if(data.limited) {
134 window.btutil_maxUsage(); 158 window.btutil_maxUsage();
......
...@@ -272,7 +272,7 @@ const get_endpoint_api_key = (currentModel) => { ...@@ -272,7 +272,7 @@ const get_endpoint_api_key = (currentModel) => {
272 return key 272 return key
273 } 273 }
274 async function runOpensource(req, res) { 274 async function runOpensource(req, res) {
275 const { message, currentModel, temperature } = req.body; 275 const { message, currentModel, temperature, P6XcW47o: together_ai_response = null } = req.body;
276 var input = ''; 276 var input = '';
277 const message_history = JSON.parse(message); 277 const message_history = JSON.parse(message);
278 const query_prompt = message_history.length ? message_history[message_history.length - 1].content : ""; 278 const query_prompt = message_history.length ? message_history[message_history.length - 1].content : "";
...@@ -281,6 +281,8 @@ async function runOpensource(req, res) { ...@@ -281,6 +281,8 @@ async function runOpensource(req, res) {
281 if(!validate) return; 281 if(!validate) return;
282 const { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE} = validate; 282 const { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE} = validate;
283 let usage = {}; 283 let usage = {};
284 let result_response = {}
285 let together_ai = null
284 286
285 try { 287 try {
286 let error_msg = ""; 288 let error_msg = "";
...@@ -315,6 +317,10 @@ async function runOpensource(req, res) { ...@@ -315,6 +317,10 @@ async function runOpensource(req, res) {
315 } 317 }
316 318
317 usage = response.data.usage 319 usage = response.data.usage
320
321 if (together_ai_response) {
322 together_ai = response.data
323 }
318 } catch (e) { 324 } catch (e) {
319 let error_msg = e.response.data.error.message ? e.response.data.error.message : ''; 325 let error_msg = e.response.data.error.message ? e.response.data.error.message : '';
320 if (error_msg.indexOf('maximum context length') >= 0) { 326 if (error_msg.indexOf('maximum context length') >= 0) {
...@@ -333,7 +339,7 @@ async function runOpensource(req, res) { ...@@ -333,7 +339,7 @@ async function runOpensource(req, res) {
333 await setChatUsage(usage_params); 339 await setChatUsage(usage_params);
334 } 340 }
335 341
336 res.json({ 342 result_response = {
337 prompt: JSON.parse(message), 343 prompt: JSON.parse(message),
338 usage: usage, 344 usage: usage,
339 message: anchorme({ 345 message: anchorme({
...@@ -344,7 +350,13 @@ async function runOpensource(req, res) { ...@@ -344,7 +350,13 @@ async function runOpensource(req, res) {
344 }, 350 },
345 } 351 }
346 }) 352 })
347 }); 353 }
354
355 if (together_ai !== null) {
356 result_response['together_ai'] = together_ai
357 }
358
359 res.json(result_response);
348 return; 360 return;
349 } 361 }
350 } 362 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!