-
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.
[ai][assistant] Create package for logos and other static information
- Loading branch information
1 parent
b433119
commit 0d2dfc1
Showing
37 changed files
with
587 additions
and
32 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
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,46 @@ | ||
# @kbn/ai-service-providers | ||
|
||
This package contains static information about AI service providers that can be used in Kibana: | ||
|
||
- IDs | ||
- Names | ||
- Logos | ||
- Connector types | ||
- Supported solutions | ||
|
||
## Logos | ||
|
||
Logos for each Service Provider are stored in the `logos` directory of the package. They can be imported directly for static imports: | ||
|
||
```ts | ||
import GeminiLogoSVG from '@kbn/ai-service-providers/logos/gemini.svg'; | ||
import GeminiLogoComponent from '@kbn/ai-service-providers/logos/gemini'; | ||
``` | ||
|
||
They can also be loaded asynchronously, in one of three formats: | ||
|
||
```tsx | ||
// Returns a lazily-loaded logo as a React component, already wrapped in a Suspense boundary. | ||
const Gemini = getReactComponentLogo('gemini'); | ||
|
||
return ( | ||
<div><Logo /></div> | ||
); | ||
|
||
// Returns a base64-encoded logo as a string. | ||
const gemini = await getBase64Logo('gemini'); | ||
|
||
return <EuiIcon type={gemini} />; | ||
|
||
// Returns a logo as a URL to a static asset. | ||
// This means the logo *will not* respond to dark mode changes. | ||
const gemini = await getUrlLogo('gemini'); | ||
|
||
return <EuiIcon type={gemini} />; | ||
``` | ||
|
||
## Note | ||
|
||
This package is an extraction of information from `@kbn/stack-connectors-plugin` relevant to `@kbn/ai-assistant`. It is intended to be used by the AI Assistant to display a list of available AI service providers to the user. | ||
|
||
We can move more or all of this information from `@kbn/stack-connectors-plugin` to this package, if others agree that a centralized location for this information is prudent. |
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,24 @@ | ||
/* | ||
* 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 { ServiceProviderID } from './id'; | ||
|
||
// There are more service providers and connector types in @kbn/stack-connectors-plugin, | ||
// but until we know which other logos or properties we'd like to migrate, we're only | ||
// including those currently in use by the AI Assistant. | ||
export const SERVICE_PROVIDER_CONNECTOR_IDS: Record<ServiceProviderID, string> = { | ||
bedrock: '.bedrock', | ||
openai: '.gen-ai', | ||
gemini: '.gemini', | ||
}; | ||
|
||
/** | ||
* Returns true if the given string is a supported connector type, false otherwise. | ||
* @param id The connector type ID to check. | ||
*/ | ||
export const isSupportedConnectorId = (id: string) => | ||
Object.values(SERVICE_PROVIDER_CONNECTOR_IDS).includes(id); |
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,36 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Available AI Service Provider IDs. | ||
*/ | ||
export type ServiceProviderID = (typeof SERVICE_PROVIDER_IDS)[number]; | ||
|
||
// There are more service providers in @kbn/stack-connectors-plugin, but until | ||
// we know which other logos or properties we'd like to migrate, we're only | ||
// including those currently in use by the AI Assistant. | ||
|
||
/** | ||
* Available AI Service Provider IDs. | ||
*/ | ||
export const SERVICE_PROVIDER_IDS = [ | ||
// 'alibabacloud-ai-search', | ||
'bedrock', | ||
// 'anthropic', | ||
// 'azureopenai', | ||
// 'azureaistudio', | ||
// 'cohere', | ||
// 'elasticsearch', | ||
// 'elser', | ||
'gemini', | ||
// 'googleaistudio', | ||
// 'googlevertexai', | ||
// 'hugging_face', | ||
// 'mistral', | ||
'openai', | ||
// 'watsonxai', | ||
] as const; |
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,74 @@ | ||
/* | ||
* 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 { type ServiceProviderID, SERVICE_PROVIDER_IDS } from './id'; | ||
export { getReactComponentLogo, getBase64Logo, getUrlLogo } from './logo'; | ||
export type { ProviderSolution } from './solutions'; | ||
|
||
import { SERVICE_PROVIDER_CONNECTOR_IDS } from './connector_id'; | ||
import { type ServiceProviderID, SERVICE_PROVIDER_IDS } from './id'; | ||
import { SERVICE_PROVIDER_NAMES } from './name'; | ||
import { type ProviderSolution, SERVICE_PROVIDER_SOLUTIONS } from './solutions'; | ||
|
||
/** | ||
* An AI Service Provider available to used in Kibana. | ||
*/ | ||
export interface ServiceProvider { | ||
/** The ID of the provider. */ | ||
id: ServiceProviderID; | ||
/** A display name for the provider. */ | ||
name: string; | ||
/** Solutions in which the provider can be used. */ | ||
solutions: readonly ProviderSolution[]; | ||
/** The connector type ID of the provider. */ | ||
connectorId: string; | ||
} | ||
|
||
/** | ||
* A static map of all AI Service Providers available for use in Kibana. | ||
*/ | ||
export const SERVICE_PROVIDERS = SERVICE_PROVIDER_IDS.reduce((acc, id) => { | ||
acc[id] = { | ||
id, | ||
name: SERVICE_PROVIDER_NAMES[id], | ||
solutions: SERVICE_PROVIDER_SOLUTIONS[id], | ||
connectorId: SERVICE_PROVIDER_CONNECTOR_IDS[id], | ||
}; | ||
|
||
return acc; | ||
}, {} as Record<ServiceProviderID, ServiceProvider>); | ||
|
||
export const { | ||
/** Amazon Bedrock */ | ||
bedrock, | ||
/** Google Gemini */ | ||
gemini, | ||
/** Open AI */ | ||
openai, | ||
} = SERVICE_PROVIDERS; | ||
|
||
/** | ||
* Return all Service Provider IDs. | ||
*/ | ||
export const getServiceProviderIds = () => SERVICE_PROVIDER_IDS; | ||
|
||
/** | ||
* Return all Service Providers, mapped by ID. | ||
*/ | ||
export const getServiceProviders = () => SERVICE_PROVIDERS; | ||
|
||
/** | ||
* Return a Service Provider by ID. | ||
* @param id The ID of the Service Provider. | ||
*/ | ||
export const getServiceProvider = (id: ServiceProviderID) => SERVICE_PROVIDERS[id]; | ||
|
||
/** | ||
* Returns true if the given string is a supported connector type, false otherwise. | ||
* @param id The connector type ID to check. | ||
*/ | ||
export { isSupportedConnectorId } from './connector_id'; |
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,12 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../../..', | ||
roots: ['<rootDir>/x-pack/packages/ai/service_providers'], | ||
}; |
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,6 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/ai-service-providers", | ||
"owner": "@elastic/appex-ai-infra", | ||
"visibility": "shared" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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 { dynamic } from '@kbn/shared-ux-utility'; | ||
import { ServiceProviderID } from '../id'; | ||
|
||
const LOGO_REACT = { | ||
bedrock: dynamic(() => import('./bedrock')), | ||
gemini: dynamic(() => import('./gemini')), | ||
openai: dynamic(() => import('./open_ai')), | ||
} as const; | ||
|
||
const toBase64 = (data: string) => `data:image/svg+xml;base64,${btoa(data)}`; | ||
|
||
const LOGO_BASE_64 = { | ||
bedrock: async () => { | ||
const svg = await import('!!raw-loader!./bedrock.svg'); | ||
return toBase64(svg.default); | ||
}, | ||
gemini: async () => { | ||
const svg = await import('!!raw-loader!./gemini.svg'); | ||
return toBase64(svg.default); | ||
}, | ||
openai: async () => { | ||
const svg = await import('!!raw-loader!./open_ai.svg'); | ||
return toBase64(svg.default); | ||
}, | ||
}; | ||
|
||
const LOGO_URL = { | ||
bedrock: async () => { | ||
const svg = await import('./bedrock.svg'); | ||
return toBase64(svg.default); | ||
}, | ||
gemini: async () => { | ||
const svg = await import('./gemini.svg'); | ||
return toBase64(svg.default); | ||
}, | ||
openai: async () => { | ||
const svg = await import('./open_ai.svg'); | ||
return toBase64(svg.default); | ||
}, | ||
}; | ||
|
||
/** | ||
* Get a lazy-loaded React component, wrapped in a `Suspense` boundary, for the logo of a service provider. | ||
* @param id The ID of the service provider. | ||
*/ | ||
export const getReactComponentLogo = (id: ServiceProviderID) => LOGO_REACT[id]; | ||
|
||
/** | ||
* Get the base64-encoded SVG of the logo of a service provider. | ||
* @param id The ID of the service provider. | ||
*/ | ||
export const getBase64Logo = async (id: ServiceProviderID) => LOGO_BASE_64[id](); | ||
|
||
/** | ||
* Get the URL of the logo of a service provider. | ||
* @param id The ID of the service provider. | ||
*/ | ||
export const getUrlLogo = async (id: ServiceProviderID) => LOGO_URL[id](); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.