Skip to content

Commit

Permalink
Merge pull request #46 from appatalks/appatalks_eva_playground
Browse files Browse the repository at this point in the history
gpt-4-turbo added
  • Loading branch information
appatalks authored Mar 10, 2024
2 parents 2f04c52 + 2021ff4 commit f5b2227
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 80 deletions.
Binary file modified core/img/eEgg-leaf.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions core/js/chatgpt-turbo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Javascript
// For OpenAI API

// gpt-3.5-turbo + gpt-4 API Call
// gpt-3.5-turbo + gpt-4-turbo API Call
function trboSend() {

// Remove occurrences of the specific syntax from the txtMsg element
Expand Down Expand Up @@ -164,8 +164,8 @@ function trboSend() {
// payload parameters
var sModel = selModel.value;
var iMaxTokens = 1420;
if (sModel === "gpt-4-32k") {
iMaxTokens = 28420;
if (sModel === "gpt-4-turbo-preview") {
iMaxTokens = 4096;
} else if (sModel === "gpt-3.5-turbo-16k") {
iMaxTokens = 12420;
}
Expand All @@ -179,7 +179,7 @@ function trboSend() {
if (!localStorage.getItem("messages")) {
// If it does not exist, create an array with the initial messages
const iMessages = [
{ role: 'system', content: 'You are Eva. You have access to previous chats and responses. You have access to real-time news, information and media. You will keep conversation to a minimum and answer to the best of your abilities. You have access to APIs that display and describe images and pictures. An image of an object can be shown with an \"[Image of ]\" tag.' },
{ role: 'system', content: 'You are Eva. You have access to previous chats and responses. You have access to real-time news, information and media. You will keep conversation to a minimum and answer to the best of your abilities. When you are asked to show an image, instead describe the image with [Image of <Description>].' },
{ role: 'user', content: selPers.value + " " + dateContents },
];

Expand Down
83 changes: 9 additions & 74 deletions core/js/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Javascript for Options
//
// // Sections
// Variables
// API Access[OpenAI, AWS, Google Custom Search]

// Global Variables
var lastResponse = "";
Expand Down Expand Up @@ -48,7 +45,7 @@ function updateButton() {
var selModel = document.getElementById("selModel");
var btnSend = document.getElementById("btnSend");

if (selModel.value == "gpt-3.5-turbo" || selModel.value == "gpt-3.5-turbo-16k" || selModel.value == "gpt-4" || selModel.value == "gpt-4-32k") {
if (selModel.value == "gpt-3.5-turbo" || selModel.value == "gpt-3.5-turbo-16k" || selModel.value == "gpt-4-turbo-preview") {
btnSend.onclick = function() {
clearText();
trboSend();
Expand All @@ -71,14 +68,20 @@ function updateButton() {
}
}


function sendData() {
// Logic required for initial message
var selModel = document.getElementById("selModel");
if (selModel.value == "gpt-3.5-turbo" || selModel.value == "gpt-4" || selModel.value == "gpt-4-32k") {

if (selModel.value == "gpt-3.5-turbo" || selModel.value == "gpt-3.5-turbo-16k" || selModel.value == "gpt-4-turbo-preview") {
clearText();
trboSend();
} else if (selModel.value == "palm") {
clearText();
palmSend();
} else if (selModel.value == "gemini") {
clearText();
geminiSend();
} else {
clearText();
Send();
Expand Down Expand Up @@ -416,7 +419,7 @@ if (speechParams.Engine === "bark") {
});

//audioElement.play();
// Check if the old audio file exists and delete it
// Check if the old audio file exists and delete it
const checkRequest = new XMLHttpRequest();
checkRequest.open('HEAD', 'https://192.168.86.30/audio/bark_audio.wav', true);
checkRequest.onreadystatechange = function() {
Expand Down Expand Up @@ -535,71 +538,3 @@ function startSpeechRecognition() {
micButton.classList.remove('pulsate');
};
}

// Get Account Usage Information
// Billing
async function getOpenaiBillUsage(apiKey, start_date, end_date) {
var oKey = OPENAI_API_KEY;

const headers = {
'Authorization': `Bearer ${oKey}`,
'Content-Type': 'application/json',
};

if (!start_date) {
const today = new Date();
const year = today.getFullYear();
const month = today.getMonth();
start_date = new Date(year, month, 1).toISOString().slice(0, 10);
}

if (!end_date) {
const today = new Date();
today.setDate(today.getDate() + 1);
end_date = today.toISOString().slice(0, 10);
}

// Get the current usage
const usageResponse = await fetch(
`https://api.openai.com/dashboard/billing/usage?start_date=${start_date}&end_date=${end_date}`,
{
headers,
}
);
if (usageResponse.status === 200) {
const usageData = await usageResponse.json();
const totalUsage = usageData.total_usage;
const formattedUsage = (totalUsage / 100 + 0.01).toFixed(2);
document.getElementById("txtOutput").innerHTML = `\n\n\n Month's Current Spend: $${formattedUsage}`;
} else {
throw new Error(`Failed to retrieve OpenAI usage data: ${await usageResponse.text()}`);
}

// Get the hard limit
const subscriptionResponse = await fetch(
`https://api.openai.com/dashboard/billing/subscription`,
{
headers,
}
);
if (subscriptionResponse.status === 200) {
const subscriptionData = await subscriptionResponse.json();
const hardLimitUsd = parseFloat(subscriptionData.hard_limit_usd);
const formattedHardLimit = hardLimitUsd.toFixed(2);
document.getElementById("txtOutput").innerHTML += ` / $${formattedHardLimit}`;
} else {
throw new Error(`Failed to retrieve OpenAI subscription data: ${await subscriptionResponse.text()}`);
}
}

// Token Usage // Disabled
async function getOpenaiUsage(apiKey, start_date, end_date) {
// Place Holder
}

// Tie the API together
function getOpenaiUsageNested() {
getOpenaiBillUsage();
// getOpenaiUsage(); Not very useful information to show here. maybe "current_usage_usd": 0.0
// Placer
}
3 changes: 1 addition & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@
<option value="gpt-3.5-turbo" title="Default">gpt-3.5-turbo</option>
<option value="dall-e-3" title="Image Generation">DALL-E-3</option>
<option value="gpt-3.5-turbo-16k" title="gpt-3.5-turbo-16k">gpt-3.5-turbo-16k</option>
<option value="gpt-4" title="GPT 4">gpt-4</option>
<option value="gpt-4-turbo-preview" title="GPT-4-Turbo">gpt-4-turbo-preview</option>
<option value="gemini" title="Google Gemini">gemini</option>
<option value="palm" title="Legacy Google PaLM ie Bard">palm</option>
<option value="gpt-4-32k" title="Advanced model with larger memory size. * Highest API Cost *">gpt-4-32k</option>
</select>

<select id="selPers" onchange="ChangeLang(this)">
Expand Down

0 comments on commit f5b2227

Please sign in to comment.