Add a filter (or setting?) to allow alt text generation when the site has basic authentication
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
classifai_openai_api_request_post_options フィルターから開始し、classifai_feature_descriptive_text_generator の alt-text リクエストパスを追跡します。既存のリクエストオプションと、提示された basic-auth の回避策を比較します。完了の条件は、basic-auth で認証されたサイトの画像を、プロバイダーが直接取得することなく処理できることです。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- PHP
- スター
- 714
- フォーク
- 68
- 平均マージ
- 4時間 32分
- マージ済み PR(30日)
- 23
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
10up/classifai のほかの issue
-
wpvc
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
wpvc
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
Register ClassifAI functionality with the Abilities API対応中かも @nhrrob が 10 日前に担当しました。 オープンhelp wanted
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
10up/classifai#1249 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
OpenAI usage tracking: Project ID setting is ignored対応中かも @dajiaohuang が 30 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
BYOK Openai modelsオープン
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
firefly-iii/firefly-iii#13259 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
[Sync EN] Document the getLastErrors() return value change in the PHP 8.2 migration guide (#6107)オープンsync-en
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
sync-en
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
Перевод устарел
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信