ChatGPTNextWeb / ChatGPT-Next-Web

A cross-platform ChatGPT/Gemini UI (Web / PWA / Linux / Win / MacOS). 一键拥有你自己的跨平台 ChatGPT/Gemini 应用。
https://app.nextchat.dev/
MIT License
77.21k stars 59.44k forks source link

google ai models. #5337

Open 0wwafa opened 3 months ago

0wwafa commented 3 months ago

Instead of having them fixed, get them dynamycally:

            // Thanks to Zibri for this routine.

            async function getPreferredModel(apiKey) {
                try {
                    const response = await fetch('https://generativelanguage.googleapis.com/v1beta/models', {
                        headers: {
                              'content-type': 'application/json; charset=UTF-8',
                            'x-goog-api-key': apiKey,
                        },
                    });

                    if (!response.ok) {
                        throw new Error(`Failed to fetch models: ${response.status} ${response.statusText}`);
                    }

                    const data = await response.json();
                    const modelNames = data.models.map(model => model.name.split('/')[1]);

                    // 1. Find last "pro" and "exp" model
                    let latestModel = modelNames.filter(name => name.includes("pro") && name.includes("exp")).pop();

                    // 2. If not found, find the last "pro" model
                    if (!latestModel) {
                        latestModel = modelNames.filter(name => name.includes("pro")).pop();
                    }

                    return [latestModel, modelNames];

                } catch (error) {
                    console.error(`Error fetching and processing model names:`, error);
                    return null;
                    // Return null if no matching model or error
                }
            }

This returns the latest pro-exp model AND the full list of models.

["gemini-1.5-pro-exp-0827",["chat-bison-001","text-bison-001","embedding-gecko-001","gemini-1.0-pro-latest","gemini-1.0-pro","gemini-pro","gemini-1.0-pro-001","gemini-1.0-pro-vision-latest","gemini-pro-vision","gemini-1.5-pro-latest","gemini-1.5-pro-001","gemini-1.5-pro","gemini-1.5-pro-exp-0801","gemini-1.5-pro-exp-0827","gemini-1.5-flash-latest","gemini-1.5-flash-001","gemini-1.5-flash-001-tuning","gemini-1.5-flash","gemini-1.5-flash-exp-0827","gemini-1.5-flash-8b-exp-0827","embedding-001","text-embedding-004","aqa"]]

nextchat-manager[bot] commented 3 months ago

Please follow the issue template to update title and description of your issue.

0wwafa commented 3 months ago

Also, please add:

HARM_CATEGORY_CIVIC_INTEGRITY

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


Also, please add:

HARM_CATEGORY_CIVIC_INTEGRITY

0wwafa commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.

Also, please add:

HARM_CATEGORY_CIVIC_INTEGRITY

by the way, where, in settings do I set the harm category?

0wwafa commented 3 months ago

also: in the fetch request use:

                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/json',
                            'Cache-Control': 'no-store',
                            'x-goog-api-key': apiKey
                        },

and remove key= from the query.