ai: separate model and tool selection

This commit is contained in:
end-4
2025-07-27 22:33:25 +07:00
parent d3392000af
commit 3ac44d211f
10 changed files with 192 additions and 232 deletions
@@ -12,7 +12,6 @@ import QtQuick;
* - key_get_link: Link to get an API key
* - key_get_description: Description of pricing and how to get an API key
* - api_format: The API format of the model. Can be "openai" or "gemini". Default is "openai".
* - tools: List of tools that the model can use.
* - extraParams: Extra parameters to be passed to the model. This is a JSON object.
*/
@@ -2,7 +2,7 @@ import QtQuick
QtObject {
function buildEndpoint(model: AiModel): string { throw new Error("Not implemented") }
function buildRequestData(model: AiModel, messages, systemPrompt: string, temperature: real) { throw new Error("Not implemented") }
function buildRequestData(model: AiModel, messages, systemPrompt: string, temperature: real, tools: list<var>) { throw new Error("Not implemented") }
function buildAuthorizationHeader(apiKeyEnvVarName: string): string { throw new Error("Not implemented") }
function parseResponseLine(line: string, message: AiMessageData) { throw new Error("Not implemented") }
function onRequestFinished(message: AiMessageData): var { return {} } // Default: no special handling
@@ -9,13 +9,12 @@ ApiStrategy {
return result;
}
function buildRequestData(model: AiModel, messages, systemPrompt: string, temperature: real) {
const tools = model.tools ?? [];
function buildRequestData(model: AiModel, messages, systemPrompt: string, temperature: real, tools: list<var>) {
let baseData = {
"contents": messages.map(message => {
const geminiApiRoleName = (message.role === "assistant") ? "model" : message.role;
const usingSearch = tools[0].google_search != undefined
if (!usingSearch && message.functionCall != undefined && message.functionCall.length > 0) {
const usingSearch = tools[0]?.google_search !== undefined
if (!usingSearch && message.functionCall != undefined && message.functionName.length > 0) {
return {
"role": geminiApiRoleName,
"parts": [{
@@ -25,7 +24,7 @@ ApiStrategy {
}]
}
}
if (!usingSearch && message.functionResponse != undefined && message.functionResponse.length > 0) {
if (!usingSearch && message.functionResponse != undefined && message.functionName.length > 0) {
return {
"role": geminiApiRoleName,
"parts": [{
@@ -8,7 +8,7 @@ ApiStrategy {
return model.endpoint;
}
function buildRequestData(model: AiModel, messages, systemPrompt: string, temperature: real) {
function buildRequestData(model: AiModel, messages, systemPrompt: string, temperature: real, tools: list<var>) {
let baseData = {
"model": model.model,
"messages": [