Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inference plugin: Add Gemini model adapter #191292

Merged
merged 19 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1557,18 +1557,18 @@ x-pack/test/security_solution_cypress/cypress/tasks/expandable_flyout @elastic/

## Generative AI owner connectors
# OpenAI
/x-pack/plugins/stack_connectors/public/connector_types/openai @elastic/security-generative-ai @elastic/obs-ai-assistant
/x-pack/plugins/stack_connectors/server/connector_types/openai @elastic/security-generative-ai @elastic/obs-ai-assistant
/x-pack/plugins/stack_connectors/common/openai @elastic/security-generative-ai @elastic/obs-ai-assistant
/x-pack/plugins/stack_connectors/public/connector_types/openai @elastic/security-generative-ai @elastic/obs-ai-assistant @elastic/appex-ai-infra
/x-pack/plugins/stack_connectors/server/connector_types/openai @elastic/security-generative-ai @elastic/obs-ai-assistant @elastic/appex-ai-infra
/x-pack/plugins/stack_connectors/common/openai @elastic/security-generative-ai @elastic/obs-ai-assistant @elastic/appex-ai-infra
# Bedrock
/x-pack/plugins/stack_connectors/public/connector_types/bedrock @elastic/security-generative-ai @elastic/obs-ai-assistant
/x-pack/plugins/stack_connectors/server/connector_types/bedrock @elastic/security-generative-ai @elastic/obs-ai-assistant
/x-pack/plugins/stack_connectors/common/bedrock @elastic/security-generative-ai @elastic/obs-ai-assistant
/x-pack/plugins/stack_connectors/public/connector_types/bedrock @elastic/security-generative-ai @elastic/obs-ai-assistant @elastic/appex-ai-infra
/x-pack/plugins/stack_connectors/server/connector_types/bedrock @elastic/security-generative-ai @elastic/obs-ai-assistant @elastic/appex-ai-infra
/x-pack/plugins/stack_connectors/common/bedrock @elastic/security-generative-ai @elastic/obs-ai-assistant @elastic/appex-ai-infra

# Gemini
/x-pack/plugins/stack_connectors/public/connector_types/gemini @elastic/security-generative-ai @elastic/obs-ai-assistant
/x-pack/plugins/stack_connectors/server/connector_types/gemini @elastic/security-generative-ai @elastic/obs-ai-assistant
/x-pack/plugins/stack_connectors/common/gemini @elastic/security-generative-ai @elastic/obs-ai-assistant
/x-pack/plugins/stack_connectors/public/connector_types/gemini @elastic/security-generative-ai @elastic/obs-ai-assistant @elastic/appex-ai-infra
/x-pack/plugins/stack_connectors/server/connector_types/gemini @elastic/security-generative-ai @elastic/obs-ai-assistant @elastic/appex-ai-infra
/x-pack/plugins/stack_connectors/common/gemini @elastic/security-generative-ai @elastic/obs-ai-assistant @elastic/appex-ai-infra

## Defend Workflows owner connectors
/x-pack/plugins/stack_connectors/public/connector_types/sentinelone @elastic/security-defend-workflows
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 4 additions & 26 deletions x-pack/plugins/inference/common/chat_complete/tool_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
* 2.0.
*/

import { Required, ValuesType, UnionToIntersection } from 'utility-types';
import { Required, ValuesType } from 'utility-types';

interface ToolSchemaFragmentBase {
description?: string;
}

interface ToolSchemaTypeObject extends ToolSchemaFragmentBase {
type: 'object';
properties: Record<string, ToolSchemaFragment>;
properties: Record<string, ToolSchemaType>;
required?: string[] | readonly string[];
}

Expand All @@ -35,28 +35,18 @@ interface ToolSchemaTypeNumber extends ToolSchemaFragmentBase {
enum?: string[] | readonly string[];
}

interface ToolSchemaAnyOf extends ToolSchemaFragmentBase {
anyOf: ToolSchemaType[];
}

interface ToolSchemaAllOf extends ToolSchemaFragmentBase {
allOf: ToolSchemaType[];
}
Comment on lines -38 to -44
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed with @dgieselaar: Gemini doesn't support type composition for tool definition, so we can't easily have it on the inference API. But given that the feature doesn't seem that useful, it feels like a very acceptable removal.


interface ToolSchemaTypeArray extends ToolSchemaFragmentBase {
type: 'array';
items: Exclude<ToolSchemaType, ToolSchemaTypeArray>;
}

type ToolSchemaType =
export type ToolSchemaType =
| ToolSchemaTypeObject
| ToolSchemaTypeString
| ToolSchemaTypeBoolean
| ToolSchemaTypeNumber
| ToolSchemaTypeArray;

type ToolSchemaFragment = ToolSchemaType | ToolSchemaAnyOf | ToolSchemaAllOf;

type FromToolSchemaObject<TToolSchemaObject extends ToolSchemaTypeObject> = Required<
{
[key in keyof TToolSchemaObject['properties']]?: FromToolSchema<
Expand All @@ -79,17 +69,9 @@ type FromToolSchemaString<TToolSchemaString extends ToolSchemaTypeString> =
? ValuesType<TToolSchemaString['enum']>
: string;

type FromToolSchemaAnyOf<TToolSchemaAnyOf extends ToolSchemaAnyOf> = FromToolSchema<
ValuesType<TToolSchemaAnyOf['anyOf']>
>;

type FromToolSchemaAllOf<TToolSchemaAllOf extends ToolSchemaAllOf> = UnionToIntersection<
FromToolSchema<ValuesType<TToolSchemaAllOf['allOf']>>
>;

export type ToolSchema = ToolSchemaTypeObject;

export type FromToolSchema<TToolSchema extends ToolSchemaFragment> =
export type FromToolSchema<TToolSchema extends ToolSchemaType> =
TToolSchema extends ToolSchemaTypeObject
? FromToolSchemaObject<TToolSchema>
: TToolSchema extends ToolSchemaTypeArray
Expand All @@ -100,8 +82,4 @@ export type FromToolSchema<TToolSchema extends ToolSchemaFragment> =
? number
: TToolSchema extends ToolSchemaTypeString
? FromToolSchemaString<TToolSchema>
: TToolSchema extends ToolSchemaAnyOf
? FromToolSchemaAnyOf<TToolSchema>
: TToolSchema extends ToolSchemaAllOf
? FromToolSchemaAllOf<TToolSchema>
: never;
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 processVertexStreamMock = jest.fn();

jest.doMock('./process_vertex_stream', () => {
const actual = jest.requireActual('./process_vertex_stream');
return {
...actual,
processVertexStream: processVertexStreamMock,
};
});
Loading