forked from Shinonome/dots-hyprland
ai: gemini 2.5: update model codes, add flash lite
This commit is contained in:
@@ -40,6 +40,64 @@ Singleton {
|
|||||||
property list<var> promptFiles: [...defaultPrompts, ...userPrompts]
|
property list<var> promptFiles: [...defaultPrompts, ...userPrompts]
|
||||||
property list<var> savedChats: []
|
property list<var> savedChats: []
|
||||||
|
|
||||||
|
property var tools: {
|
||||||
|
"gemini": [{"functionDeclarations": [
|
||||||
|
{
|
||||||
|
"name": "switch_to_search_mode",
|
||||||
|
"description": "Search the web",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get_shell_config",
|
||||||
|
"description": "Get the desktop shell config file contents",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "set_shell_config",
|
||||||
|
"description": "Set a field in the desktop graphical shell config file. Must only be used after `get_shell_config`.",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"key": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The key to set, e.g. `bar.borderless`. MUST NOT BE GUESSED, use `get_shell_config` to see what keys are available before setting.",
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The value to set, e.g. `true`"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["key", "value"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]}],
|
||||||
|
"openai": [
|
||||||
|
{
|
||||||
|
"type": "function",
|
||||||
|
"name": "get_shell_config",
|
||||||
|
"description": "Get the current shell configuration.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "function",
|
||||||
|
"name": "set_shell_config",
|
||||||
|
"description": "Set a field in the desktop graphical shell config file. Must only be used after `get_shell_config`.",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"key": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The key to set, e.g. `bar.borderless`. MUST NOT BE GUESSED, use `get_shell_config` to see what keys are available before setting.",
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The value to set, e.g. `true`"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["key", "value"],
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
// Model properties:
|
// Model properties:
|
||||||
// - name: Name of the model
|
// - name: Name of the model
|
||||||
// - icon: Icon name of the model
|
// - icon: Icon name of the model
|
||||||
@@ -66,16 +124,14 @@ Singleton {
|
|||||||
"key_get_link": "https://aistudio.google.com/app/apikey",
|
"key_get_link": "https://aistudio.google.com/app/apikey",
|
||||||
"key_get_description": Translation.tr("**Pricing**: free. Data used for training.\n\n**Instructions**: Log into Google account, allow AI Studio to create Google Cloud project or whatever it asks, go back and click Get API key"),
|
"key_get_description": Translation.tr("**Pricing**: free. Data used for training.\n\n**Instructions**: Log into Google account, allow AI Studio to create Google Cloud project or whatever it asks, go back and click Get API key"),
|
||||||
"api_format": "gemini",
|
"api_format": "gemini",
|
||||||
"tools": [
|
"tools": [{
|
||||||
{
|
"google_search": {}
|
||||||
"google_search": {}
|
}]
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"gemini-2.0-flash-tools": {
|
"gemini-2.0-flash-tools": {
|
||||||
"name": "Gemini 2.0 Flash (Tools)",
|
"name": "Gemini 2.0 Flash (Tools)",
|
||||||
"icon": "google-gemini-symbolic",
|
"icon": "google-gemini-symbolic",
|
||||||
"description": Translation.tr("Experimental | Online | Google's model\nCan do a little more but doesn't search quickly"),
|
"description": Translation.tr("Experimental | Online | Google's model\nCan do a little more but takes an extra turn to perform search"),
|
||||||
"homepage": "https://aistudio.google.com",
|
"homepage": "https://aistudio.google.com",
|
||||||
"endpoint": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:streamGenerateContent",
|
"endpoint": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:streamGenerateContent",
|
||||||
"model": "gemini-2.0-flash",
|
"model": "gemini-2.0-flash",
|
||||||
@@ -84,101 +140,66 @@ Singleton {
|
|||||||
"key_get_link": "https://aistudio.google.com/app/apikey",
|
"key_get_link": "https://aistudio.google.com/app/apikey",
|
||||||
"key_get_description": Translation.tr("**Pricing**: free. Data used for training.\n\n**Instructions**: Log into Google account, allow AI Studio to create Google Cloud project or whatever it asks, go back and click Get API key"),
|
"key_get_description": Translation.tr("**Pricing**: free. Data used for training.\n\n**Instructions**: Log into Google account, allow AI Studio to create Google Cloud project or whatever it asks, go back and click Get API key"),
|
||||||
"api_format": "gemini",
|
"api_format": "gemini",
|
||||||
"tools": [
|
"tools": root.tools["gemini"],
|
||||||
{
|
|
||||||
"functionDeclarations": [
|
|
||||||
{
|
|
||||||
"name": "switch_to_search_mode",
|
|
||||||
"description": "Search the web",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "get_shell_config",
|
|
||||||
"description": "Get the desktop shell config file contents",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "set_shell_config",
|
|
||||||
"description": "Set a field in the desktop graphical shell config file. Must only be used after `get_shell_config`.",
|
|
||||||
"parameters": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"key": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The key to set, e.g. `bar.borderless`. MUST NOT BE GUESSED, use `get_shell_config` to see what keys are available before setting.",
|
|
||||||
},
|
|
||||||
"value": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The value to set, e.g. `true`"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": ["key", "value"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"gemini-2.5-flash-search": {
|
"gemini-2.5-flash-search": {
|
||||||
"name": "Gemini 2.5 Flash (Search)",
|
"name": "Gemini 2.5 Flash (Search)",
|
||||||
"icon": "google-gemini-symbolic",
|
"icon": "google-gemini-symbolic",
|
||||||
"description": Translation.tr("Online | Google's model\nGives up-to-date information with search."),
|
"description": Translation.tr("Online | Google's model\nGives up-to-date information with search."),
|
||||||
"homepage": "https://aistudio.google.com",
|
"homepage": "https://aistudio.google.com",
|
||||||
"endpoint": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-05-20:streamGenerateContent",
|
"endpoint": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent",
|
||||||
"model": "gemini-2.5-flash-preview-05-20",
|
"model": "gemini-2.5-flash",
|
||||||
"requires_key": true,
|
"requires_key": true,
|
||||||
"key_id": "gemini",
|
"key_id": "gemini",
|
||||||
"key_get_link": "https://aistudio.google.com/app/apikey",
|
"key_get_link": "https://aistudio.google.com/app/apikey",
|
||||||
"key_get_description": Translation.tr("**Pricing**: free. Data used for training.\n\n**Instructions**: Log into Google account, allow AI Studio to create Google Cloud project or whatever it asks, go back and click Get API key"),
|
"key_get_description": Translation.tr("**Pricing**: free. Data used for training.\n\n**Instructions**: Log into Google account, allow AI Studio to create Google Cloud project or whatever it asks, go back and click Get API key"),
|
||||||
"api_format": "gemini",
|
"api_format": "gemini",
|
||||||
"tools": [
|
"tools": [{
|
||||||
{
|
"google_search": {}
|
||||||
"google_search": ({})
|
}]
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"gemini-2.5-flash-tools": {
|
"gemini-2.5-flash-tools": {
|
||||||
"name": "Gemini 2.5 Flash (Tools)",
|
"name": "Gemini 2.5 Flash (Tools)",
|
||||||
"icon": "google-gemini-symbolic",
|
"icon": "google-gemini-symbolic",
|
||||||
"description": Translation.tr("Experimental | Online | Google's model\nCan do a little more but doesn't search quickly"),
|
"description": Translation.tr("Experimental | Online | Google's model\nCan do a little more but takes an extra turn to perform search"),
|
||||||
"homepage": "https://aistudio.google.com",
|
"homepage": "https://aistudio.google.com",
|
||||||
"endpoint": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-05-20:streamGenerateContent",
|
"endpoint": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent",
|
||||||
"model": "gemini-2.5-flash-preview-05-20",
|
"model": "gemini-2.5-flash",
|
||||||
"requires_key": true,
|
"requires_key": true,
|
||||||
"key_id": "gemini",
|
"key_id": "gemini",
|
||||||
"key_get_link": "https://aistudio.google.com/app/apikey",
|
"key_get_link": "https://aistudio.google.com/app/apikey",
|
||||||
"key_get_description": Translation.tr("**Pricing**: free. Data used for training.\n\n**Instructions**: Log into Google account, allow AI Studio to create Google Cloud project or whatever it asks, go back and click Get API key"),
|
"key_get_description": Translation.tr("**Pricing**: free. Data used for training.\n\n**Instructions**: Log into Google account, allow AI Studio to create Google Cloud project or whatever it asks, go back and click Get API key"),
|
||||||
"api_format": "gemini",
|
"api_format": "gemini",
|
||||||
"tools": [
|
"tools": root.tools["gemini"],
|
||||||
{
|
},
|
||||||
"functionDeclarations": [
|
"gemini-2.5-flash-lite": {
|
||||||
{
|
"name": "Gemini 2.5 Flash-Lite",
|
||||||
"name": "switch_to_search_mode",
|
"icon": "google-gemini-symbolic",
|
||||||
"description": "Search the web",
|
"description": Translation.tr("Experimental | Online | Google's model\nA Gemini 2.5 Flash model optimized for cost-efficiency and high throughput."),
|
||||||
},
|
"homepage": "https://aistudio.google.com",
|
||||||
{
|
"endpoint": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:streamGenerateContent",
|
||||||
"name": "get_shell_config",
|
"model": "gemini-2.5-flash-lite",
|
||||||
"description": "Get the desktop shell config file contents",
|
"requires_key": true,
|
||||||
},
|
"key_id": "gemini",
|
||||||
{
|
"key_get_link": "https://aistudio.google.com/app/apikey",
|
||||||
"name": "set_shell_config",
|
"key_get_description": Translation.tr("**Pricing**: free. Data used for training.\n\n**Instructions**: Log into Google account, allow AI Studio to create Google Cloud project or whatever it asks, go back and click Get API key"),
|
||||||
"description": "Set a field in the desktop graphical shell config file. Must only be used after `get_shell_config`.",
|
"api_format": "gemini",
|
||||||
"parameters": {
|
},
|
||||||
"type": "object",
|
"gemini-2.5-flash-lite-search": {
|
||||||
"properties": {
|
"name": "Gemini 2.5 Flash-Lite (Search)",
|
||||||
"key": {
|
"icon": "google-gemini-symbolic",
|
||||||
"type": "string",
|
"description": Translation.tr("Experimental | Online | Google's model\nA Gemini 2.5 Flash model optimized for cost-efficiency and high throughput."),
|
||||||
"description": "The key to set, e.g. `bar.borderless`. MUST NOT BE GUESSED, use `get_shell_config` to see what keys are available before setting.",
|
"homepage": "https://aistudio.google.com",
|
||||||
},
|
"endpoint": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:streamGenerateContent",
|
||||||
"value": {
|
"model": "gemini-2.5-flash-lite",
|
||||||
"type": "string",
|
"requires_key": true,
|
||||||
"description": "The value to set, e.g. `true`"
|
"key_id": "gemini",
|
||||||
}
|
"key_get_link": "https://aistudio.google.com/app/apikey",
|
||||||
},
|
"key_get_description": Translation.tr("**Pricing**: free. Data used for training.\n\n**Instructions**: Log into Google account, allow AI Studio to create Google Cloud project or whatever it asks, go back and click Get API key"),
|
||||||
"required": ["key", "value"]
|
"api_format": "gemini",
|
||||||
}
|
"tools": [{
|
||||||
},
|
"google_search": {}
|
||||||
]
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"openrouter-llama4-maverick": {
|
"openrouter-llama4-maverick": {
|
||||||
"name": "Llama 4 Maverick",
|
"name": "Llama 4 Maverick",
|
||||||
@@ -467,10 +488,14 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildGeminiRequestData(model, messages) {
|
function buildGeminiRequestData(model, messages) {
|
||||||
|
const tools = [
|
||||||
|
...(model.tools ?? root.tools[model.api_format]),
|
||||||
|
]
|
||||||
|
// console.log("Tools", JSON.stringify(tools, null, 2));
|
||||||
let baseData = {
|
let baseData = {
|
||||||
"contents": messages.filter(message => (message.role != Ai.interfaceRole)).map(message => {
|
"contents": messages.filter(message => (message.role != Ai.interfaceRole)).map(message => {
|
||||||
const geminiApiRoleName = (message.role === "assistant") ? "model" : message.role;
|
const geminiApiRoleName = (message.role === "assistant") ? "model" : message.role;
|
||||||
const usingSearch = model.tools[0].google_search != undefined
|
const usingSearch = tools[0].google_search != undefined
|
||||||
if (!usingSearch && message.functionCall != undefined && message.functionCall.length > 0) {
|
if (!usingSearch && message.functionCall != undefined && message.functionCall.length > 0) {
|
||||||
return {
|
return {
|
||||||
"role": geminiApiRoleName,
|
"role": geminiApiRoleName,
|
||||||
@@ -499,9 +524,7 @@ Singleton {
|
|||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
"tools": [
|
"tools": tools,
|
||||||
...model.tools,
|
|
||||||
],
|
|
||||||
"system_instruction": {
|
"system_instruction": {
|
||||||
"parts": [{ text: root.systemPrompt }]
|
"parts": [{ text: root.systemPrompt }]
|
||||||
},
|
},
|
||||||
@@ -780,12 +803,18 @@ Singleton {
|
|||||||
|
|
||||||
function handleGeminiFunctionCall(name, args) {
|
function handleGeminiFunctionCall(name, args) {
|
||||||
if (name === "switch_to_search_mode") {
|
if (name === "switch_to_search_mode") {
|
||||||
if (root.currentModelId === "gemini-2.5-flash-tools") {
|
const modelId = root.currentModelId;
|
||||||
root.setModel("gemini-2.5-flash-search", false);
|
if (modelId.endsWith("-tools")) {
|
||||||
root.postResponseHook = () => root.setModel("gemini-2.5-flash-tools", false);
|
const searchModelId = modelId.replace(/-tools$/, "-search");
|
||||||
} else if (root.currentModelId === "gemini-2.0-flash-tools") {
|
if (root.modelList.indexOf(searchModelId) !== -1) {
|
||||||
root.setModel("gemini-2.0-flash-search", false);
|
root.setModel(searchModelId, false);
|
||||||
root.postResponseHook = () => root.setModel("gemini-2.0-flash-tools", false);
|
root.postResponseHook = () => root.setModel(modelId, false);
|
||||||
|
} else {
|
||||||
|
root.addMessage(Translation.tr("No corresponding search model found for %1").arg(modelId), Ai.interfaceRole);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
root.addMessage(Translation.tr("Cannot switch to search mode from %1").arg(root.currentModelId), Ai.interfaceRole);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
addFunctionOutputMessage(name, Translation.tr("Switched to search mode. Continue with the user's request."))
|
addFunctionOutputMessage(name, Translation.tr("Switched to search mode. Continue with the user's request."))
|
||||||
requester.makeRequest();
|
requester.makeRequest();
|
||||||
|
|||||||
Reference in New Issue
Block a user