mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[inference] fix tool definition for rainbow-sprinkles
(#208823)
## Summary Port the tool definition hack that was done for bedrock to be used for `rainbow-sprinkles` too.
This commit is contained in:
parent
0c18b44621
commit
32175454c1
1 changed files with 21 additions and 1 deletions
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { InferenceEndpointProvider, ToolOptions } from '@kbn/inference-common';
|
||||
import { InferenceEndpointProvider, MessageRole, ToolOptions } from '@kbn/inference-common';
|
||||
import { fixSchemaArrayProperties } from '../../bedrock/convert_tools';
|
||||
import type { CreateOpenAIRequestOptions } from '../types';
|
||||
import { getProvider, getElasticModelProvider } from '../utils';
|
||||
|
@ -40,5 +40,25 @@ const applyBedrockTransforms = (
|
|||
}, {} as Required<ToolOptions>['tools']);
|
||||
}
|
||||
|
||||
const hasToolUse = options.messages.some(
|
||||
(message) =>
|
||||
message.role === MessageRole.Tool ||
|
||||
(message.role === MessageRole.Assistant && message.toolCalls?.length)
|
||||
);
|
||||
|
||||
// bedrock does not accept tool calls in conversation history
|
||||
// if no tools are present in the request.
|
||||
if (hasToolUse && Object.keys(options.tools ?? {}).length === 0) {
|
||||
options.tools = {
|
||||
doNotCallThisTool: {
|
||||
description: 'Do not call this tool, it is strictly forbidden',
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return options;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue