Refactor plugin
This commit is contained in:
33
plugins/gemini.js
Normal file
33
plugins/gemini.js
Normal file
@@ -0,0 +1,33 @@
|
||||
module.exports = {
|
||||
afterTransformRequest(req, res) {
|
||||
if (Array.isArray(req.body.tools)) {
|
||||
// rewrite tools definition
|
||||
req.body.tools.forEach((tool) => {
|
||||
if (tool.function.name === "BatchTool") {
|
||||
// HACK: Gemini does not support objects with empty properties
|
||||
tool.function.parameters.properties.invocations.items.properties.input.type =
|
||||
"number";
|
||||
return;
|
||||
}
|
||||
Object.keys(tool.function.parameters.properties).forEach((key) => {
|
||||
const prop = tool.function.parameters.properties[key];
|
||||
if (
|
||||
prop.type === "string" &&
|
||||
!["enum", "date-time"].includes(prop.format)
|
||||
) {
|
||||
delete prop.format;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
if (req.body?.messages?.length) {
|
||||
req.body.messages.forEach((message) => {
|
||||
if (message.content === null) {
|
||||
if (message.tool_calls) {
|
||||
message.content = JSON.stringify(message.tool_calls);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -1,7 +1,12 @@
|
||||
module.exports = async function handle(req, res) {
|
||||
if (req?.body?.tools?.length) {
|
||||
req.body.tools = req.body.tools.filter(
|
||||
(tool) => !["NotebookRead", "NotebookEdit", "mcp__ide__executeCode"].includes(tool.name)
|
||||
);
|
||||
}
|
||||
module.exports = {
|
||||
beforeRouter(req, res) {
|
||||
if (req?.body?.tools?.length) {
|
||||
req.body.tools = req.body.tools.filter(
|
||||
(tool) =>
|
||||
!["NotebookRead", "NotebookEdit", "mcp__ide__executeCode"].includes(
|
||||
tool.name
|
||||
)
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
module.exports = async function handle(req, res) {
|
||||
if (req?.body?.tools?.length) {
|
||||
req.body.system.push({
|
||||
type: "text",
|
||||
text: `## **Important Instruction:** \nYou must use tools as frequently and accurately as possible to help the user solve their problem.\nPrioritize tool usage whenever it can enhance accuracy, efficiency, or the quality of the response.`
|
||||
})
|
||||
}
|
||||
module.exports = {
|
||||
afterTransformRequest(req, res) {
|
||||
if (req?.body?.tools?.length) {
|
||||
req.body.messages.push({
|
||||
role: "system",
|
||||
content: `## **Important Instruction:** \nYou must use tools as frequently and accurately as possible to help the user solve their problem.\nPrioritize tool usage whenever it can enhance accuracy, efficiency, or the quality of the response. `,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user