Skip to content
Snippets Groups Projects
Commit 9c87a378 authored by Scott Euser's avatar Scott Euser
Browse files

Issue #3417202 by scott_euser: Add new embeddings models

parent c5d8d54d
No related branches found
No related tags found
1 merge request!75Make the list of embeddings available via openai api instead of hardcoded
...@@ -124,3 +124,10 @@ function openai_embeddings_update_10003() { ...@@ -124,3 +124,10 @@ function openai_embeddings_update_10003() {
$config->save(); $config->save();
} }
} }
/**
* Clear cache of models list given change to filters in #3417202.
*/
function openai_embeddings_update_10004() {
\Drupal::cache()->invalidate('openai_models');
}
...@@ -36,6 +36,13 @@ class SettingsForm extends ConfigFormBase { ...@@ -36,6 +36,13 @@ class SettingsForm extends ConfigFormBase {
*/ */
protected $pluginManager; protected $pluginManager;
/**
* The Open AI API client.
*
* @var \Drupal\openai\OpenAIApi
*/
protected $api;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -60,6 +67,7 @@ class SettingsForm extends ConfigFormBase { ...@@ -60,6 +67,7 @@ class SettingsForm extends ConfigFormBase {
$instance->entityTypeManager = $container->get('entity_type.manager'); $instance->entityTypeManager = $container->get('entity_type.manager');
$instance->entityTypeBundleInfo = $container->get('entity_type.bundle.info'); $instance->entityTypeBundleInfo = $container->get('entity_type.bundle.info');
$instance->pluginManager = $container->get('plugin.manager.vector_client'); $instance->pluginManager = $container->get('plugin.manager.vector_client');
$instance->api = $container->get('openai.api');
return $instance; return $instance;
} }
...@@ -116,13 +124,14 @@ class SettingsForm extends ConfigFormBase { ...@@ -116,13 +124,14 @@ class SettingsForm extends ConfigFormBase {
'#description' => $this->t('Enter a comma delimited list of words to exclude from generating embedding values for.'), '#description' => $this->t('Enter a comma delimited list of words to exclude from generating embedding values for.'),
]; ];
$models = $this->api->filterModels(['text-embedding-']);
$selected_model = $this->config('openai_embeddings.settings')->get('model');
$form['model'] = [ $form['model'] = [
'#type' => 'select', '#type' => 'select',
'#title' => $this->t('Model to use'), '#title' => $this->t('Model to use'),
'#options' => [ '#options' => $models,
'text-embedding-ada-002' => $this->t('text-embedding-ada-002'), '#required' => TRUE,
], '#default_value' => $models[$selected_model] ?: '',
'#default_value' => $this->config('openai_embeddings.settings')->get('model'),
'#description' => $this->t('Select which model to use to analyze text. See the <a href=":link">model overview</a> for details about each model.', [':link' => 'https://platform.openai.com/docs/guides/embeddings/embedding-models']), '#description' => $this->t('Select which model to use to analyze text. See the <a href=":link">model overview</a> for details about each model.', [':link' => 'https://platform.openai.com/docs/guides/embeddings/embedding-models']),
]; ];
......
...@@ -95,7 +95,7 @@ class OpenAIApi implements ContainerInjectionInterface { ...@@ -95,7 +95,7 @@ class OpenAIApi implements ContainerInjectionInterface {
} }
// Skip unused. hidden, or deprecated models. // Skip unused. hidden, or deprecated models.
if (preg_match('/(search|similarity|edit|1p|instruct|embed)/i', $model['id'])) { if (preg_match('/(search|similarity|edit|1p|instruct)/i', $model['id'])) {
continue; continue;
} }
...@@ -136,16 +136,6 @@ class OpenAIApi implements ContainerInjectionInterface { ...@@ -136,16 +136,6 @@ class OpenAIApi implements ContainerInjectionInterface {
return $models; return $models;
} }
/**
* Get the latest embedding model.
*
* @return string
* The embedding model in OpenAI.
*/
public function embeddingModel(): string {
return 'text-embedding-ada-002';
}
/** /**
* Return a ready to use answer from the completion endpoint. * Return a ready to use answer from the completion endpoint.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment