mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	Function calling for Groq
This commit is contained in:
		| @@ -1739,7 +1739,7 @@ | ||||
|                                             </span> | ||||
|                                         </div> | ||||
|                                     </div> | ||||
|                                     <div class="range-block" data-source="openai,cohere,mistralai,custom,claude,openrouter"> | ||||
|                                     <div class="range-block" data-source="openai,cohere,mistralai,custom,claude,openrouter,groq"> | ||||
|                                         <label for="openai_function_calling" class="checkbox_label flexWrap widthFreeExpand"> | ||||
|                                             <input id="openai_function_calling" type="checkbox" /> | ||||
|                                             <span data-i18n="Enable function calling">Enable function calling</span> | ||||
|   | ||||
| @@ -1968,7 +1968,14 @@ async function registerFunctionTools(type, data) { | ||||
| } | ||||
|  | ||||
| async function checkFunctionToolCalls(data) { | ||||
|     if ([chat_completion_sources.OPENAI, chat_completion_sources.CUSTOM, chat_completion_sources.MISTRALAI, chat_completion_sources.OPENROUTER].includes(oai_settings.chat_completion_source)) { | ||||
|     const oaiCompat = [ | ||||
|         chat_completion_sources.OPENAI, | ||||
|         chat_completion_sources.CUSTOM, | ||||
|         chat_completion_sources.MISTRALAI, | ||||
|         chat_completion_sources.OPENROUTER, | ||||
|         chat_completion_sources.GROQ, | ||||
|     ]; | ||||
|     if (oaiCompat.includes(oai_settings.chat_completion_source)) { | ||||
|         if (!Array.isArray(data?.choices)) { | ||||
|             return; | ||||
|         } | ||||
| @@ -2045,6 +2052,7 @@ export function isFunctionCallingSupported() { | ||||
|         chat_completion_sources.MISTRALAI, | ||||
|         chat_completion_sources.CLAUDE, | ||||
|         chat_completion_sources.OPENROUTER, | ||||
|         chat_completion_sources.GROQ, | ||||
|     ]; | ||||
|     return supportedSources.includes(oai_settings.chat_completion_source); | ||||
| } | ||||
|   | ||||
| @@ -915,6 +915,18 @@ router.post('/generate', jsonParser, function (request, response) { | ||||
|         apiKey = readSecret(request.user.directories, SECRET_KEYS.GROQ); | ||||
|         headers = {}; | ||||
|         bodyParams = {}; | ||||
|  | ||||
|         // 'required' tool choice is not supported by Groq | ||||
|         if (request.body.tool_choice === 'required') { | ||||
|             if (Array.isArray(request.body.tools) && request.body.tools.length > 0) { | ||||
|                 request.body.tool_choice = request.body.tools.length > 1 | ||||
|                     ? 'auto' : | ||||
|                     { type: 'function', function: { name: request.body.tools[0]?.function?.name } }; | ||||
|  | ||||
|             } else { | ||||
|                 request.body.tool_choice = 'none'; | ||||
|             } | ||||
|         } | ||||
|     } else { | ||||
|         console.log('This chat completion source is not supported yet.'); | ||||
|         return response.status(400).send({ error: true }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user