Skip to content

Instantly share code, notes, and snippets.

@Choumingzhao
Last active September 18, 2024 02:11
Show Gist options
  • Save Choumingzhao/dcc88a5d6a0adaaf1c26fcb747494ef4 to your computer and use it in GitHub Desktop.
Save Choumingzhao/dcc88a5d6a0adaaf1c26fcb747494ef4 to your computer and use it in GitHub Desktop.
UserScript to Force using GPT4o-mini in ChatGPT.
// ==UserScript==
// @name Force GPT-4o-mini
// @namespace altbdoor
// @match https://chatgpt.com/*
// @grant GM.setValue
// @grant GM.getValue
// @version 1.9
// @author altbdoor(original) and Choumingzhao(current edit)
// @run-at document-start
// @updateURL https://github.com/altbdoor/userscripts/raw/master/force-gpt3.user.js
// @downloadURL https://github.com/altbdoor/userscripts/raw/master/force-gpt3.user.js
// ==/UserScript==
// https://blog.logrocket.com/intercepting-javascript-fetch-api-requests-responses/
const originalFetch = unsafeWindow.fetch;
unsafeWindow.fetch = async (url, config) => {
const gptModel = await GM.getValue(
'gptModel',
'gpt-4o-mini',
);
if (
gptModel !== 'auto' &&
url.includes('/backend-api/conversation') &&
config.method === 'POST'
) {
try {
const body = JSON.parse(config.body);
config.body = JSON.stringify({
...body,
model: gptModel,
});
} catch (error) {
console.error('[force-gpt-4o-mini] Error parsing JSON body:', error);
}
}
const response = await originalFetch(url, config);
return response;
};
document.addEventListener('DOMContentLoaded', async () => {
// add style
const style = document.createElement('style');
style.innerHTML = `
.toggleContainer {
position: absolute; right: 12rem; top: 0.5rem;
}
.toggleContainer select {
border-radius: 9999px;
}
`;
document.head.append(style);
// add dropdown
const toggleContainer = document.createElement('div');
toggleContainer.classList.add('toggleContainer');
toggleContainer.innerHTML = `
<select>
<option value="auto">Auto</option>
<option value="gpt-4o-mini">GPT 4o Mini</option>
</select>
`;
document.body.appendChild(toggleContainer);
const select = toggleContainer.querySelector('select');
select.onchange = (evt) => {
GM.setValue('gptModel', evt.target.value);
console.log(`[force-gpt4-mini] changing model to ${evt.target.value}`);
};
const selectVal = await GM.getValue(
'gptModel',
'gpt-4o-mini',
);
select.value = selectVal;
});

OpenAI enforces using the GPT4o by default and it is slow as hell. Even if you change first response to GPT4o-mini, the next response is still GPt4o sometime. This feature is annoying and won't stop until your GPT4o quota is exausted.

Following userscript originally by altbdoor is for GPT3.5. One day after GPT4o-mini release, it just does't work and I made few changes with the help of ChatGPT and it works great now. Feel free to improve it.

Problems:

  1. Not looking good in dark mode. The original script is hard-coded to work on bright theme mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment