Add a filter (or setting?) to allow alt text generation when the site has basic authentication
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 32/100
Línea de trabajo
Comienza en el filtro classifai_openai_api_request_post_options y sigue la ruta de la solicitud de texto alternativo para classifai_feature_descriptive_text_generator. Compara las opciones de solicitud existentes con la solución alternativa de basic-auth proporcionada; el trabajo debería considerarse terminado cuando se puedan procesar imágenes de sitios protegidos con basic-auth sin requerir que el proveedor las obtenga directamente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Is your enhancement related to a problem? Please describe.
Right now alt text generation fails when basic authentication is enabled because OpenAI (or whichever provider) can't access the image directly.
This code works specifically for my use-case, but I'm wondering if there is a way to more easily handle this while we're working on protected staging sites.
/**
* Handle basic auth for Classifai alt text generation via OpenAI.
*
* @param array $options The options.
* @param string $url The URL.
* @param string $feature The feature.
*
* @return array
*/
add_filter( 'classifai_openai_api_request_post_options', function( array $options, string $url, string $feature ): array {
// Bail if not our feature.
if ( 'classifai_feature_descriptive_text_generator' !== $feature ) {
return $options;
}
// Bail if no body.
if ( ! isset( $options['body'] ) ) {
return $options;
}
// Bail if no messages.
$body = json_decode( $options['body'], true );
if ( ! $body || empty( $body['messages'] ) ) {
return $options;
}
// Set the username and password.
$un = 'someun';
$pw = 'somepw';
// Encode the credentials.
$creds = base64_encode( $un . ':' . $pw );
// Loop through the messages.
foreach ( $body['messages'] as &$message ) {
// Bail if not an array.
if ( ! is_array( $message['content'] ) ) {
continue;
}
// Loop through the items.
foreach ( $message['content'] as &$item ) {
// Bail if not an image.
if ( empty( $item['type'] ) || 'image_url' !== $item['type'] ) {
continue;
}
// Fetch the image manually.
$resp = wp_remote_get( $item['image_url']['url'], [
'headers' => [ 'Authorization' => 'Basic ' . $creds ],
] );
// Bail if error.
if ( is_wp_error( $resp ) ) {
continue;
}
// Get the raw body.
$raw = wp_remote_retrieve_body( $resp );
// Encode the body.
$b64 = base64_encode( $raw );
// Figure out the MIME type (fallback to jpeg).
$info = @getimagesizefromstring( $raw );
$mime = $info ? $info['mime'] : 'image/jpeg';
// Replace with a Data URI.
$item = [
'type' => 'image_url',
'image_url' => [
'url' => "data:{$mime};base64,{$b64}",
'detail' => $item['image_url']['detail'] ?? 'auto',
],
];
}
}
// Encode the body.
$options['body'] = wp_json_encode( $body );
return $options;
}, 10, 3 );
Designs
No response
Describe alternatives you've considered
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
- Lenguaje dominante
- PHP
- Estrellas
- 714
- Forks
- 68
- Merge medio
- 4 h 32 min
- PR fusionados (30 d)
- 23
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de 10up/classifai
-
wpvc
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
wpvc
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día
-
Register ClassifAI functionality with the Abilities APIPosiblemente ocupada @nhrrob la tomó hace 10 días. Abiertohelp wanted
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
10up/classifai#1249 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
OpenAI usage tracking: Project ID setting is ignoredPosiblemente ocupada @dajiaohuang la tomó hace 30 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
-
BYOK Openai modelsAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
Todos los issues de 10up/classifai
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
firefly-iii/firefly-iii#13259 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
[Sync EN] Document the getLastErrors() return value change in the PHP 8.2 migration guide (#6107)Abiertosync-en
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
sync-en
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Перевод устарел
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día