Skip to content

Commit

Permalink
fix: Fixed search tool to enable judgment logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Amery2010 committed Feb 6, 2025
1 parent 78fb38b commit fef3073
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions utils/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ export function getSafetySettings(level: string) {
})
}

function canUseSearchAsTool(model: string) {
if (model.startsWith('gemini-2.0-flash') || model.startsWith('gemini-2.0-pro')) {
if (model.includes('lite') || model.includes('thinking')) return false
return true
}
}

export default async function chat({
messages = [],
systemInstruction,
Expand Down Expand Up @@ -96,13 +103,11 @@ export default async function chat({
}
if (toolConfig) modelParams.toolConfig = toolConfig
}
if (model === 'gemini-2.0-flash-exp') {
if (canUseSearchAsTool(model)) {
const officialPlugins = [{ googleSearch: {} }]
if (!tools) {
modelParams.tools = officialPlugins
}
}
if (model.startsWith('gemini-2.0-flash-exp')) {
if (modelParams.safetySettings) {
const safetySettings: NewModelParams['safetySettings'] = []
modelParams.safetySettings.forEach((item) => {
Expand Down

0 comments on commit fef3073

Please sign in to comment.