mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Remove tool calling for Cohere v1
This commit is contained in:
@ -461,19 +461,6 @@ export class ToolManager {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
if ([chat_completion_sources.COHERE].includes(oai_settings.chat_completion_source)) {
|
|
||||||
if (!Array.isArray(data?.tool_calls)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const toolCall of data.tool_calls) {
|
|
||||||
const args = { name: toolCall.name, arguments: JSON.stringify(toolCall.parameters) };
|
|
||||||
console.log('Function tool call:', toolCall);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ const fetch = require('node-fetch').default;
|
|||||||
const { jsonParser } = require('../../express-common');
|
const { jsonParser } = require('../../express-common');
|
||||||
const { CHAT_COMPLETION_SOURCES, GEMINI_SAFETY, BISON_SAFETY, OPENROUTER_HEADERS } = require('../../constants');
|
const { CHAT_COMPLETION_SOURCES, GEMINI_SAFETY, BISON_SAFETY, OPENROUTER_HEADERS } = require('../../constants');
|
||||||
const { forwardFetchResponse, getConfigValue, tryParse, uuidv4, mergeObjectWithYaml, excludeKeysByYaml, color } = require('../../util');
|
const { forwardFetchResponse, getConfigValue, tryParse, uuidv4, mergeObjectWithYaml, excludeKeysByYaml, color } = require('../../util');
|
||||||
const { convertClaudeMessages, convertGooglePrompt, convertTextCompletionPrompt, convertCohereMessages, convertMistralMessages, convertCohereTools, convertAI21Messages } = require('../../prompt-converters');
|
const { convertClaudeMessages, convertGooglePrompt, convertTextCompletionPrompt, convertCohereMessages, convertMistralMessages, convertAI21Messages } = require('../../prompt-converters');
|
||||||
const CohereStream = require('../../cohere-stream');
|
const CohereStream = require('../../cohere-stream');
|
||||||
|
|
||||||
const { readSecret, SECRET_KEYS } = require('../secrets');
|
const { readSecret, SECRET_KEYS } = require('../secrets');
|
||||||
@ -555,14 +555,6 @@ async function sendCohereRequest(request, response) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if (Array.isArray(request.body.tools) && request.body.tools.length > 0) {
|
|
||||||
tools.push(...convertCohereTools(request.body.tools));
|
|
||||||
// Can't have both connectors and tools in the same request
|
|
||||||
connectors.splice(0, connectors.length);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// https://docs.cohere.com/reference/chat
|
// https://docs.cohere.com/reference/chat
|
||||||
const requestBody = {
|
const requestBody = {
|
||||||
stream: Boolean(request.body.stream),
|
stream: Boolean(request.body.stream),
|
||||||
|
@ -522,76 +522,6 @@ function convertTextCompletionPrompt(messages) {
|
|||||||
return messageStrings.join('\n') + '\nassistant:';
|
return messageStrings.join('\n') + '\nassistant:';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert OpenAI Chat Completion tools to the format used by Cohere.
|
|
||||||
* @param {object[]} tools OpenAI Chat Completion tool definitions
|
|
||||||
*/
|
|
||||||
function convertCohereTools(tools) {
|
|
||||||
if (!Array.isArray(tools) || tools.length === 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const jsonSchemaToPythonTypes = {
|
|
||||||
'string': 'str',
|
|
||||||
'number': 'float',
|
|
||||||
'integer': 'int',
|
|
||||||
'boolean': 'bool',
|
|
||||||
'array': 'list',
|
|
||||||
'object': 'dict',
|
|
||||||
};
|
|
||||||
|
|
||||||
const cohereTools = [];
|
|
||||||
|
|
||||||
for (const tool of tools) {
|
|
||||||
if (tool?.type !== 'function') {
|
|
||||||
console.log(`Unsupported tool type: ${tool.type}`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const name = tool?.function?.name;
|
|
||||||
const description = tool?.function?.description;
|
|
||||||
const properties = tool?.function?.parameters?.properties;
|
|
||||||
const required = tool?.function?.parameters?.required;
|
|
||||||
const parameters = {};
|
|
||||||
|
|
||||||
if (!name) {
|
|
||||||
console.log('Tool name is missing');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!description) {
|
|
||||||
console.log('Tool description is missing');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!properties || typeof properties !== 'object') {
|
|
||||||
console.log(`No properties found for tool: ${tool?.function?.name}`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const property in properties) {
|
|
||||||
const parameterDefinition = properties[property];
|
|
||||||
const description = parameterDefinition.description || (parameterDefinition.enum ? JSON.stringify(parameterDefinition.enum) : '');
|
|
||||||
const type = jsonSchemaToPythonTypes[parameterDefinition.type] || 'str';
|
|
||||||
const isRequired = Array.isArray(required) && required.includes(property);
|
|
||||||
parameters[property] = {
|
|
||||||
description: description,
|
|
||||||
type: type,
|
|
||||||
required: isRequired,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const cohereTool = {
|
|
||||||
name: tool.function.name,
|
|
||||||
description: tool.function.description,
|
|
||||||
parameter_definitions: parameters,
|
|
||||||
};
|
|
||||||
|
|
||||||
cohereTools.push(cohereTool);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cohereTools;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
convertClaudePrompt,
|
convertClaudePrompt,
|
||||||
convertClaudeMessages,
|
convertClaudeMessages,
|
||||||
@ -599,6 +529,5 @@ module.exports = {
|
|||||||
convertTextCompletionPrompt,
|
convertTextCompletionPrompt,
|
||||||
convertCohereMessages,
|
convertCohereMessages,
|
||||||
convertMistralMessages,
|
convertMistralMessages,
|
||||||
convertCohereTools,
|
|
||||||
convertAI21Messages,
|
convertAI21Messages,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user