-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[inference] add support for
auto
function calling mode (#208144)
## Summary Fix #208143 Add a new value for the `functionCalling` parameter, `auto`, which is the new default. When `functionCalling=auto`, the system will detect if the underlying model/provider supports native function calling, and otherwise automatically fallback to simulated function calling.
- Loading branch information
1 parent
86666bf
commit c22b982
Showing
13 changed files
with
221 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
.../shared/inference/server/chat_complete/adapters/inference/inference_adapter.test.mocks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const isNativeFunctionCallingSupportedMock = jest.fn(); | ||
|
||
jest.doMock('../../utils/function_calling_support', () => { | ||
const actual = jest.requireActual('../../utils/function_calling_support'); | ||
return { | ||
...actual, | ||
isNativeFunctionCallingSupported: isNativeFunctionCallingSupportedMock, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...lugins/shared/inference/server/chat_complete/adapters/openai/openai_adapter.test.mocks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const isNativeFunctionCallingSupportedMock = jest.fn(); | ||
|
||
jest.doMock('../../utils/function_calling_support', () => { | ||
const actual = jest.requireActual('../../utils/function_calling_support'); | ||
return { | ||
...actual, | ||
isNativeFunctionCallingSupported: isNativeFunctionCallingSupportedMock, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...form/plugins/shared/inference/server/chat_complete/utils/function_calling_support.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { OpenAiProviderType } from '../adapters/openai/types'; | ||
import { InferenceConnector, InferenceConnectorType } from '@kbn/inference-common'; | ||
import { isNativeFunctionCallingSupported } from './function_calling_support'; | ||
|
||
const createConnector = ( | ||
parts: Partial<InferenceConnector> & Pick<InferenceConnector, 'type'> | ||
): InferenceConnector => { | ||
return { | ||
connectorId: 'connector-id', | ||
name: 'my connector', | ||
config: {}, | ||
...parts, | ||
}; | ||
}; | ||
|
||
describe('isNativeFunctionCallingSupported', () => { | ||
it('returns true for gemini connector', () => { | ||
const connector = createConnector({ type: InferenceConnectorType.Gemini }); | ||
expect(isNativeFunctionCallingSupported(connector)).toBe(true); | ||
}); | ||
|
||
it('returns true for bedrock connector', () => { | ||
const connector = createConnector({ type: InferenceConnectorType.Bedrock }); | ||
expect(isNativeFunctionCallingSupported(connector)).toBe(true); | ||
}); | ||
|
||
it('returns true for inference connector', () => { | ||
const connector = createConnector({ type: InferenceConnectorType.Inference }); | ||
expect(isNativeFunctionCallingSupported(connector)).toBe(true); | ||
}); | ||
|
||
describe('openAI connector', () => { | ||
it('returns true for "OpenAI" provider', () => { | ||
const connector = createConnector({ | ||
type: InferenceConnectorType.OpenAI, | ||
config: { apiProvider: OpenAiProviderType.OpenAi }, | ||
}); | ||
expect(isNativeFunctionCallingSupported(connector)).toBe(true); | ||
}); | ||
|
||
it('returns true for "Azure" provider', () => { | ||
const connector = createConnector({ | ||
type: InferenceConnectorType.OpenAI, | ||
config: { apiProvider: OpenAiProviderType.AzureAi }, | ||
}); | ||
expect(isNativeFunctionCallingSupported(connector)).toBe(true); | ||
}); | ||
|
||
it('returns false for "Other" provider', () => { | ||
const connector = createConnector({ | ||
type: InferenceConnectorType.OpenAI, | ||
config: { apiProvider: OpenAiProviderType.Other }, | ||
}); | ||
expect(isNativeFunctionCallingSupported(connector)).toBe(false); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.