refactor(GeminiProvider): remove unused tool filtering logic and update tools assignment
This commit is contained in:
parent
53892fa5e6
commit
75eb6680d8
@ -27,7 +27,6 @@ import OpenAI from 'openai'
|
||||
|
||||
import { CompletionsParams } from '.'
|
||||
import BaseProvider from './BaseProvider'
|
||||
import { filterInvalidTools } from './geminiToolUtils'
|
||||
import {
|
||||
callMCPTool,
|
||||
filterMCPTools,
|
||||
@ -183,6 +182,7 @@ export default class GeminiProvider extends BaseProvider {
|
||||
model: model.id,
|
||||
systemInstruction: assistant.prompt,
|
||||
safetySettings: this.getSafetySettings(model.id),
|
||||
tools: tools,
|
||||
generationConfig: {
|
||||
maxOutputTokens: maxTokens,
|
||||
temperature: assistant?.settings?.temperature,
|
||||
@ -192,10 +192,6 @@ export default class GeminiProvider extends BaseProvider {
|
||||
},
|
||||
this.requestOptions
|
||||
)
|
||||
const filteredTools = filterInvalidTools(geminiModel.tools)
|
||||
if (!isEmpty(filteredTools)) {
|
||||
geminiModel.tools = filteredTools
|
||||
}
|
||||
|
||||
const chat = geminiModel.startChat({ history })
|
||||
const messageContents = await this.getMessageContents(userLastMessage!)
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
import { CodeExecutionTool, FunctionDeclarationsTool, GoogleSearchRetrievalTool, Tool } from '@google/generative-ai'
|
||||
import { isEmpty } from 'lodash'
|
||||
|
||||
export function filterInvalidTools(tools: Tool[] | undefined) {
|
||||
return tools?.filter((e) => !isToolInvalid(e)) ?? []
|
||||
}
|
||||
|
||||
function isToolInvalid(tool: Tool | undefined) {
|
||||
if (tool == undefined) return true
|
||||
if (isCodeExecutionTool(tool)) {
|
||||
return isEmpty(tool.codeExecution)
|
||||
} else if (isGoogleSearchRetrievalTool(tool)) {
|
||||
return isEmpty(tool.googleSearchRetrieval)
|
||||
} else if (isFunctionDeclarationsTool(tool)) {
|
||||
return isEmpty(tool.functionDeclarations)
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
function isCodeExecutionTool(tool: Tool): tool is CodeExecutionTool {
|
||||
return (tool as CodeExecutionTool).codeExecution !== undefined
|
||||
}
|
||||
|
||||
function isGoogleSearchRetrievalTool(tool: Tool): tool is GoogleSearchRetrievalTool {
|
||||
return (tool as GoogleSearchRetrievalTool).googleSearchRetrieval !== undefined
|
||||
}
|
||||
|
||||
function isFunctionDeclarationsTool(tool: Tool): tool is FunctionDeclarationsTool {
|
||||
return (tool as FunctionDeclarationsTool).functionDeclarations !== undefined
|
||||
}
|
||||
@ -88,7 +88,8 @@ export function anthropicToolUseToMcpTool(mcpTools: MCPTool[] | undefined, toolU
|
||||
}
|
||||
|
||||
export function mcpToolsToGeminiTools(mcpTools: MCPTool[] | undefined): geminiToool[] {
|
||||
if (!mcpTools) {
|
||||
if (!mcpTools || mcpTools.length === 0) {
|
||||
// No tools available
|
||||
return []
|
||||
}
|
||||
const functions: FunctionDeclaration[] = []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user