Skip to content

Commit

Permalink
refactor: Upgraded default model to Gemini 2.0 Flash
Browse files Browse the repository at this point in the history
  • Loading branch information
Amery2010 committed Feb 6, 2025
1 parent 5c4a5d1 commit 78fb38b
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions components/Setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ResponsiveDialog from '@/components/ResponsiveDialog'
import i18n from '@/utils/i18n'
import { fetchModels } from '@/utils/models'
import locales from '@/constant/locales'
import { Model } from '@/constant/model'
import { Model, DefaultModel } from '@/constant/model'
import { GEMINI_API_BASE_URL, ASSISTANT_INDEX_URL } from '@/constant/urls'
import { useSettingStore, useEnvStore } from '@/store/setting'
import { useModelStore } from '@/store/model'
Expand Down Expand Up @@ -79,7 +79,7 @@ function Setting({ open, hiddenTalkPanel, onClose }: SettingProps) {
}

let modelList: string[] = []
let defaultModel = 'gemini-1.5-flash-latest'
let defaultModel = DefaultModel
const defaultModelList: string[] = keys(Model)
const userModels: string[] = MODEL_LIST ? MODEL_LIST.split(',') : []

Expand Down
3 changes: 3 additions & 0 deletions constant/model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const Model: Record<string, string> = {
'gemini-2.0-flash': 'Gemini 2.0 Flash',
'gemini-1.5-pro': 'Gemini 1.5 Pro',
'gemini-1.5-pro-latest': 'Gemini 1.5 Pro Latest',
'gemini-1.5-flash': 'Gemini 1.5 Flash',
Expand All @@ -16,3 +17,5 @@ export const Model: Record<string, string> = {
export const OldVisionModel = ['gemini-pro-vision', 'gemini-1.0-pro-vision-latest']

export const OldTextModel = ['gemini-1.0-pro', 'gemini-1.0-pro-latest', 'gemini-pro']

export const DefaultModel = 'gemini-2.0-flash'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gemini-next-chat",
"version": "1.7.0",
"version": "1.7.1",
"private": true,
"author": "Amery2010 <[email protected]>",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gemini-next-chat"
version = "1.7.0"
version = "1.7.1"
description = "Your private Gemini application."
authors = ["Amery2010<[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"productName": "gemini-next-chat",
"mainBinaryName": "gemini-next-chat",
"version": "1.7.0",
"version": "1.7.1",
"identifier": "com.u14.app",
"plugins": {},
"app": {
Expand Down
3 changes: 2 additions & 1 deletion store/setting.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { create } from 'zustand'
import { persist, type StorageValue } from 'zustand/middleware'
import storage from '@/utils/Storage'
import { DefaultModel } from '@/constant/model'
import { omitBy, isFunction, isNull } from 'lodash-es'

type DefaultSetting = Omit<Setting, 'isProtected' | 'talkMode' | 'sidebarState'>
Expand All @@ -22,7 +23,7 @@ const defaultSetting: DefaultSetting = {
password: '',
apiKey: '',
apiProxy: '',
model: 'gemini-1.5-flash-latest',
model: DefaultModel,
sttLang: '',
ttsLang: '',
ttsVoice: '',
Expand Down
5 changes: 3 additions & 2 deletions utils/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
addEmojis,
} from '@/utils/prompt'
import { getRandomKey } from '@/utils/common'
import { DefaultModel } from '@/constant/model'
import { GEMINI_API_BASE_URL } from '@/constant/urls'

type Props = {
Expand All @@ -22,7 +23,7 @@ type Props = {

export default async function artifact(props: Props) {
const {
model = 'gemini-1.5-flash-latest',
model = DefaultModel,
apiKey,
baseUrl = GEMINI_API_BASE_URL,
systemInstruction,
Expand Down Expand Up @@ -59,7 +60,7 @@ export default async function artifact(props: Props) {
}

const modelParams: ModelParams = {
model: model.includes('-thinking') ? 'gemini-1.5-flash-latest' : model,
model: model.includes('-thinking') ? 'gemini-2.0-flash' : model,
}

const geminiModel = genAI.getGenerativeModel(modelParams, { baseUrl })
Expand Down
4 changes: 2 additions & 2 deletions utils/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GoogleGenerativeAI, HarmCategory, HarmBlockThreshold } from '@google/ge
import type { InlineDataPart, ModelParams, Tool, ToolConfig, Part, SafetySetting } from '@google/generative-ai'
import { getVisionPrompt, getFunctionCallPrompt } from '@/utils/prompt'
import { hasUploadFiles, getRandomKey } from '@/utils/common'
import { OldVisionModel } from '@/constant/model'
import { OldVisionModel, DefaultModel } from '@/constant/model'
import { isUndefined } from 'lodash-es'

export type RequestProps = {
Expand Down Expand Up @@ -61,7 +61,7 @@ export default async function chat({
systemInstruction,
tools,
toolConfig,
model = 'gemini-1.5-flash-latest',
model = DefaultModel,
apiKey,
baseUrl,
generationConfig,
Expand Down
3 changes: 2 additions & 1 deletion utils/optimizePrompt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GoogleGenerativeAI } from '@google/generative-ai'
import { DefaultModel } from '@/constant/model'
import { getRandomKey } from '@/utils/common'

export type RequestProps = {
Expand Down Expand Up @@ -57,7 +58,7 @@ The final prompt you output should adhere to the following structure below. Do n
export default async function optimizePrompt(props: RequestProps) {
const { apiKey, baseUrl, content } = props
const genAI = new GoogleGenerativeAI(getRandomKey(apiKey))
const geminiModel = genAI.getGenerativeModel({ model: 'gemini-1.5-flash-latest', systemInstruction }, { baseUrl })
const geminiModel = genAI.getGenerativeModel({ model: DefaultModel, systemInstruction }, { baseUrl })
const { stream } = await geminiModel.generateContentStream([content])
return new ReadableStream({
async start(controller) {
Expand Down
3 changes: 2 additions & 1 deletion utils/summaryTitle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GoogleGenerativeAI } from '@google/generative-ai'
import { DefaultModel } from '@/constant/model'
import { getRandomKey } from '@/utils/common'
import { getSummaryTitlePrompt } from '@/utils/prompt'

Expand All @@ -20,7 +21,7 @@ The content in the \`<conversation></conversation>\` tag is the conversation, th
export default async function summaryTitle(props: RequestProps) {
const { apiKey, baseUrl, lang, systemRole, messages } = props
const genAI = new GoogleGenerativeAI(getRandomKey(apiKey))
const geminiModel = genAI.getGenerativeModel({ model: 'gemini-1.5-flash-latest', systemInstruction }, { baseUrl })
const geminiModel = genAI.getGenerativeModel({ model: DefaultModel, systemInstruction }, { baseUrl })
const { stream } = await geminiModel.generateContentStream([getSummaryTitlePrompt(lang, messages, systemRole)])
return new ReadableStream({
async start(controller) {
Expand Down

0 comments on commit 78fb38b

Please sign in to comment.