| 1 |
<?php |
| 2 |
/** |
| 3 |
* OpenAI Provider Settings |
| 4 |
* |
| 5 |
* @package BotWriter |
| 6 |
*/ |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Get OpenAI provider info |
| 14 |
*/ |
| 15 |
function botwriter_get_openai_info() { |
| 16 |
return [ |
| 17 |
'name' => 'OpenAI', |
| 18 |
'description' => __('The creators of ChatGPT. Industry leader in AI with the most advanced models for text generation.', 'botwriter'), |
| 19 |
'website' => 'https://openai.com', |
| 20 |
'api_url' => 'https://platform.openai.com/api-keys', |
| 21 |
'docs_url' => 'https://platform.openai.com/docs', |
| 22 |
'pricing_url' => 'https://openai.com/api/pricing/', |
| 23 |
'free_credits' => __('$5 free credits for new accounts (limited time offers may vary)', 'botwriter'), |
| 24 |
'pricing_summary' => [ |
| 25 |
'gpt-5.5' => '$5.00/1M input, $30.00/1M output', |
| 26 |
'gpt-5.4' => '$2.50/1M input, $15.00/1M output', |
| 27 |
'gpt-5.4-mini' => '$0.75/1M input, $4.50/1M output', |
| 28 |
'gpt-5.4-nano' => '$0.20/1M input, $1.25/1M output', |
| 29 |
], |
| 30 |
'features' => [ |
| 31 |
__('Industry-leading models for complex tasks', 'botwriter'), |
| 32 |
__('Excellent for coding and creative writing', 'botwriter'), |
| 33 |
__('Image generation with DALL-E (same API key)', 'botwriter'), |
| 34 |
__('Extensive documentation and community', 'botwriter'), |
| 35 |
], |
| 36 |
'pros' => [ |
| 37 |
__('Best overall quality', 'botwriter'), |
| 38 |
__('Most features and tools', 'botwriter'), |
| 39 |
__('Great documentation', 'botwriter'), |
| 40 |
], |
| 41 |
'cons' => [ |
| 42 |
__('Higher cost than alternatives', 'botwriter'), |
| 43 |
__('Rate limits on free tier', 'botwriter'), |
| 44 |
], |
| 45 |
]; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Render OpenAI settings tab content |
| 50 |
*/ |
| 51 |
function botwriter_render_openai_settings($settings, $is_active) { |
| 52 |
$info = botwriter_get_openai_info(); |
| 53 |
?> |
| 54 |
<div class="provider-config-section"> |
| 55 |
<div class="provider-config-card"> |
| 56 |
<h4><?php esc_html_e('API Configuration', 'botwriter'); ?></h4> |
| 57 |
<div class="form-row"> |
| 58 |
<label><?php esc_html_e('API Key:', 'botwriter'); ?></label> |
| 59 |
<div class="api-key-wrapper"> |
| 60 |
<input type="password" name="botwriter_openai_api_key" class="form-control api-key-input" |
| 61 |
value="<?php echo esc_attr(botwriter_decrypt_api_key(get_option('botwriter_openai_api_key'))); ?>" |
| 62 |
placeholder="sk-..."> |
| 63 |
<button type="button" class="button toggle-api-key"><?php esc_html_e('Show', 'botwriter'); ?></button> |
| 64 |
<button type="button" class="button button-secondary test-api-key" data-provider="openai"> |
| 65 |
<span class="dashicons dashicons-yes-alt"></span> <?php esc_html_e('Test API Key & Update Models', 'botwriter'); ?> |
| 66 |
</button> |
| 67 |
<span class="test-api-result"></span> |
| 68 |
</div> |
| 69 |
<p class="description"><?php esc_html_e('Your OpenAI API key starts with "sk-"', 'botwriter'); ?></p> |
| 70 |
<?php botwriter_api_key_transmission_notice(); ?> |
| 71 |
</div> |
| 72 |
<div class="form-row"> |
| 73 |
<label><?php esc_html_e('Model:', 'botwriter'); ?></label> |
| 74 |
<div class="model-select-wrapper"> |
| 75 |
<?php botwriter_render_model_select('openai', 'botwriter_openai_model', $settings['botwriter_openai_model']); ?> |
| 76 |
<button type="button" class="button button-secondary test-model" data-provider="openai"> |
| 77 |
<span class="dashicons dashicons-controls-play"></span> <?php esc_html_e('Test Model', 'botwriter'); ?> |
| 78 |
</button> |
| 79 |
<span class="test-model-result"></span> |
| 80 |
</div> |
| 81 |
</div> |
| 82 |
</div> |
| 83 |
|
| 84 |
<div class="provider-info-card"> |
| 85 |
<h4><span class="dashicons dashicons-info-outline"></span> <?php esc_html_e('How to Get Your API Key', 'botwriter'); ?></h4> |
| 86 |
<ol class="setup-steps"> |
| 87 |
<li><?php esc_html_e('Go to', 'botwriter'); ?> <a href="https://platform.openai.com/signup" target="_blank">platform.openai.com</a> <?php esc_html_e('and create an account', 'botwriter'); ?></li> |
| 88 |
<li><?php esc_html_e('Navigate to', 'botwriter'); ?> <a href="https://platform.openai.com/api-keys" target="_blank"><?php esc_html_e('API Keys', 'botwriter'); ?></a></li> |
| 89 |
<li><?php esc_html_e('Click "Create new secret key"', 'botwriter'); ?></li> |
| 90 |
<li><?php esc_html_e('Copy the key (it starts with "sk-") and paste it above', 'botwriter'); ?></li> |
| 91 |
<li><?php esc_html_e('Add billing information in', 'botwriter'); ?> <a href="https://platform.openai.com/account/billing" target="_blank"><?php esc_html_e('Billing settings', 'botwriter'); ?></a></li> |
| 92 |
</ol> |
| 93 |
</div> |
| 94 |
|
| 95 |
<div class="provider-pricing-card"> |
| 96 |
<h4><span class="dashicons dashicons-money-alt"></span> <?php esc_html_e('Pricing Overview', 'botwriter'); ?></h4> |
| 97 |
|
| 98 |
<div class="pricing-highlight"> |
| 99 |
<span class="free-credits-badge"><?php esc_html_e('Free Credits', 'botwriter'); ?></span> |
| 100 |
<p><?php echo esc_html($info['free_credits']); ?></p> |
| 101 |
</div> |
| 102 |
|
| 103 |
<table class="pricing-table"> |
| 104 |
<thead> |
| 105 |
<tr> |
| 106 |
<th><?php esc_html_e('Model', 'botwriter'); ?></th> |
| 107 |
<th><?php esc_html_e('Cost (per 1M tokens)', 'botwriter'); ?></th> |
| 108 |
</tr> |
| 109 |
</thead> |
| 110 |
<tbody> |
| 111 |
<?php foreach ($info['pricing_summary'] as $model => $price): ?> |
| 112 |
<tr> |
| 113 |
<td><code><?php echo esc_html($model); ?></code></td> |
| 114 |
<td><?php echo esc_html($price); ?></td> |
| 115 |
</tr> |
| 116 |
<?php endforeach; ?> |
| 117 |
</tbody> |
| 118 |
</table> |
| 119 |
|
| 120 |
<p class="pricing-note"> |
| 121 |
<a href="<?php echo esc_url($info['pricing_url']); ?>" target="_blank" class="button button-secondary"> |
| 122 |
<span class="dashicons dashicons-external"></span> <?php esc_html_e('View Full Pricing', 'botwriter'); ?> |
| 123 |
</a> |
| 124 |
</p> |
| 125 |
</div> |
| 126 |
|
| 127 |
<div class="provider-features-card"> |
| 128 |
<h4><span class="dashicons dashicons-star-filled"></span> <?php esc_html_e('Features & Benefits', 'botwriter'); ?></h4> |
| 129 |
<ul class="features-list"> |
| 130 |
<?php foreach ($info['features'] as $feature): ?> |
| 131 |
<li><span class="dashicons dashicons-yes-alt"></span> <?php echo esc_html($feature); ?></li> |
| 132 |
<?php endforeach; ?> |
| 133 |
</ul> |
| 134 |
|
| 135 |
<div class="pros-cons"> |
| 136 |
<div class="pros"> |
| 137 |
<h5><?php esc_html_e('Pros', 'botwriter'); ?></h5> |
| 138 |
<ul> |
| 139 |
<?php foreach ($info['pros'] as $pro): ?> |
| 140 |
<li><span class="dashicons dashicons-plus-alt2"></span> <?php echo esc_html($pro); ?></li> |
| 141 |
<?php endforeach; ?> |
| 142 |
</ul> |
| 143 |
</div> |
| 144 |
<div class="cons"> |
| 145 |
<h5><?php esc_html_e('Cons', 'botwriter'); ?></h5> |
| 146 |
<ul> |
| 147 |
<?php foreach ($info['cons'] as $con): ?> |
| 148 |
<li><span class="dashicons dashicons-minus"></span> <?php echo esc_html($con); ?></li> |
| 149 |
<?php endforeach; ?> |
| 150 |
</ul> |
| 151 |
</div> |
| 152 |
</div> |
| 153 |
</div> |
| 154 |
|
| 155 |
<div class="provider-links-card"> |
| 156 |
<h4><span class="dashicons dashicons-admin-links"></span> <?php esc_html_e('Useful Links', 'botwriter'); ?></h4> |
| 157 |
<div class="links-grid"> |
| 158 |
<a href="<?php echo esc_url($info['api_url']); ?>" target="_blank" class="link-item"> |
| 159 |
<span class="dashicons dashicons-admin-network"></span> |
| 160 |
<?php esc_html_e('Get API Key', 'botwriter'); ?> |
| 161 |
</a> |
| 162 |
<a href="<?php echo esc_url($info['docs_url']); ?>" target="_blank" class="link-item"> |
| 163 |
<span class="dashicons dashicons-book"></span> |
| 164 |
<?php esc_html_e('Documentation', 'botwriter'); ?> |
| 165 |
</a> |
| 166 |
<a href="<?php echo esc_url($info['pricing_url']); ?>" target="_blank" class="link-item"> |
| 167 |
<span class="dashicons dashicons-money-alt"></span> |
| 168 |
<?php esc_html_e('Pricing', 'botwriter'); ?> |
| 169 |
</a> |
| 170 |
<a href="https://status.openai.com/" target="_blank" class="link-item"> |
| 171 |
<span class="dashicons dashicons-heart"></span> |
| 172 |
<?php esc_html_e('API Status', 'botwriter'); ?> |
| 173 |
</a> |
| 174 |
</div> |
| 175 |
</div> |
| 176 |
</div> |
| 177 |
<?php |
| 178 |
} |
| 179 |
|