Skip to content

Commit

Permalink
giving up on free API for now
Browse files Browse the repository at this point in the history
  • Loading branch information
0xGingi committed Jun 20, 2024
1 parent 1db63ab commit 6f44eeb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"author": "Jing Hua <[email protected]>",
"description": "Play and chat smarter with BetterChatGPT - an amazing open-source web app with a better UI for exploring OpenAI's ChatGPT API!",
"scripts": {
"dev": "vite",
"dev": "vite --host",
"build": "tsc && vite build",
"preview": "vite preview",
"electron": "concurrently -k \"BROWSER=none yarn dev\" \"wait-on tcp:5173 && electron .\"",
Expand Down
9 changes: 5 additions & 4 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ export const getChatCompletion = async (
) => {
const headers: HeadersInit = {
'Content-Type': 'application/json',
'Accept': 'application/json',
...customHeaders,
};

const codestralApiKey = useStore.getState().codestralApiKey;

if ((endpoint === codestralAPIEndpoint || endpoint === officialAPIEndpoint || config.model === 'codestral-latest-free') && codestralApiKey) {
if (config.model === 'codestral-latest-free' && codestralApiKey) {
headers.Authorization = `Bearer ${codestralApiKey}`;
} else if (apiKey) {
headers.Authorization = `Bearer ${apiKey}`;
}

if (isAzureEndpoint(endpoint) && apiKey) {
headers['api-key'] = apiKey;

Expand Down Expand Up @@ -73,12 +74,12 @@ export const getChatCompletionStream = async (

const codestralApiKey = useStore.getState().codestralApiKey;

if ((endpoint === codestralAPIEndpoint || endpoint === officialAPIEndpoint || config.model === 'codestral-latest-free') && codestralApiKey) {
if (config.model === 'codestral-latest-free' && codestralApiKey) {
headers.Authorization = `Bearer ${codestralApiKey}`;
} else if (apiKey) {
headers.Authorization = `Bearer ${apiKey}`;
}

if (isAzureEndpoint(endpoint) && apiKey) {
headers['api-key'] = apiKey;

Expand Down
7 changes: 4 additions & 3 deletions src/constants/auth.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
export const officialAPIEndpoint = 'https://api.mistral.ai/v1/chat/completions';
export const codestralAPIEndpoint = '/codestral/chat/completions';
export const defaultAPIEndpoint =
import.meta.env.VITE_DEFAULT_API_ENDPOINT || '/v1/chat/completions';
export const codestralFullAPIEndpoint = 'https://codestral.mistral.ai/v1/chat/completions';
export const defaultAPIEndpoint = import.meta.env.VITE_DEFAULT_API_ENDPOINT || '/v1/chat/completions';
export const codestralAPIEndpoint = import.meta.env.VITE_CODESTRAL_API_ENDPOINT || '/codestral/v1/chat/completions';

export const availableEndpoints = [
defaultAPIEndpoint,
officialAPIEndpoint,
codestralAPIEndpoint,
codestralFullAPIEndpoint
];
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
server: {
proxy: {
'/v1': 'https://api.mistral.ai',
'/codestral': 'https://codestral.mistral.ai/v1'
'/codestral': 'https://codestral.mistral.ai'
}
},
plugins: [react(), wasm(), topLevelAwait()],
Expand Down

0 comments on commit 6f44eeb

Please sign in to comment.