Add a filter (or setting?) to allow alt text generation when the site has basic authentication
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 32/100
Direzione di ricerca
Inizia dal filtro classifai_openai_api_request_post_options e traccia il percorso della richiesta di testo alternativo per classifai_feature_descriptive_text_generator. Confronta le opzioni di richiesta esistenti con la soluzione alternativa basic-auth fornita; il lavoro dovrebbe considerarsi completato quando le immagini provenienti da siti protetti da basic-auth possono essere elaborate senza richiedere al provider di recuperarle direttamente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- PHP
- Stelle
- 714
- Fork
- 68
- Merge medio
- 4h 32m
- PR unite (30g)
- 23
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di 10up/classifai
-
wpvc
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
wpvc
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
Register ClassifAI functionality with the Abilities APIForse già presa @nhrrob l’ha presa 10 giorni fa. Apertahelp wanted
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
10up/classifai#1249 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
OpenAI usage tracking: Project ID setting is ignoredForse già presa @dajiaohuang l’ha presa 30 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
BYOK Openai modelsAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di 10up/classifai
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
firefly-iii/firefly-iii#13259 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[Sync EN] Document the getLastErrors() return value change in the PHP 8.2 migration guide (#6107)Apertasync-en
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
sync-en
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Перевод устарел
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno