Skip to content

Commit

Permalink
default model
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaki-1052 committed Jul 28, 2024
1 parent 53831ef commit db57208
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
16 changes: 15 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,23 @@ QROQ_API_KEY=your_qroq_ai_key_here
OPENROUTER_API_KEY=your_openrouter_ai_key_here
CODESTRAL_API_KEY=your_codestral_ai_key_here

###

# Uncomment (remove the '#') from the following lines
# if you'd like to reuse an existing assistant or thread!
# to customize the below specified settings!

###

# Set a Default Model

# DEFAULT_MODEL=your_preferred_model

### EXAMPLE:
#DEFAULT_MODEL=claude-3-5-sonnet-20240620

DEFAULT_MODEL='gpt-4o'

# If you'd like to reuse an existing assistant or thread:

###

Expand Down
24 changes: 21 additions & 3 deletions public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ async function fetchConfig() {

fetchConfig();

let currentModelID;


async function fetchDefaultModel() {
try {
const response = await fetch('/model');

const data = await response.json();
if (data) {
currentModelID = data.model;
} else {
currentModelID = 'gpt-4o';
}
} catch (error) {
console.error('Error fetching default model:', error);
}
}

fetchDefaultModel();


// detects safari browser

Expand Down Expand Up @@ -471,7 +491,7 @@ fetchConfig();
// Default model functionality
function setDefaultModel() {
let selectedModelDiv = document.getElementById("selected-model");
let defaultModel = "gpt-4o";
let defaultModel = currentModelID;

// Check if a model has been selected, if not, set to default model ID and update display
if (selectedModelDiv.textContent.trim() === "Select a Model") {
Expand All @@ -480,8 +500,6 @@ fetchConfig();
}
}

let currentModelID = 'gpt-4o';

let selectedImage = null;

// Convert markdown to HTML using marked.js and sanitize it with DOMPurify
Expand Down
9 changes: 9 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2377,6 +2377,15 @@ app.get('/config', (req, res) => {
}
});

// Route to send the default model to the frontend
app.get('/model', (req, res) => {
const defaultModel = process.env.DEFAULT_MODEL;

if (defaultModel) {
res.json({ model: defaultModel });
}
});

app.use(cors({
origin: '*'
}));
Expand Down

0 comments on commit db57208

Please sign in to comment.