| 1 |
<?php |
| 2 |
/** |
| 3 |
* Anthropic (Claude) Provider Settings |
| 4 |
* |
| 5 |
* @package BotWriter |
| 6 |
*/ |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Get Anthropic provider info |
| 14 |
*/ |
| 15 |
function botwriter_get_anthropic_info() { |
| 16 |
return [ |
| 17 |
'name' => 'Anthropic (Claude)', |
| 18 |
'description' => __('Creator of Claude, known for being helpful, harmless, and honest. Excellent for long-form content and nuanced writing.', 'botwriter'), |
| 19 |
'website' => 'https://anthropic.com', |
| 20 |
'api_url' => 'https://console.anthropic.com/settings/keys', |
| 21 |
'docs_url' => 'https://docs.anthropic.com/', |
| 22 |
'pricing_url' => 'https://anthropic.com/pricing#api', |
| 23 |
'free_credits' => __('$5 free credits for new API accounts', 'botwriter'), |
| 24 |
'pricing_summary' => [ |
| 25 |
'claude-opus-4.5' => '$5/1M input, $25/1M output', |
| 26 |
'claude-sonnet-4.5' => '$3/1M input, $15/1M output', |
| 27 |
'claude-haiku-4.5' => '$1/1M input, $5/1M output', |
| 28 |
], |
| 29 |
'features' => [ |
| 30 |
__('200K context window (can read entire books)', 'botwriter'), |
| 31 |
__('Excellent at following complex instructions', 'botwriter'), |
| 32 |
__('Superior for long-form, nuanced content', 'botwriter'), |
| 33 |
__('Strong safety and ethical guidelines', 'botwriter'), |
| 34 |
__('Great at coding and technical writing', 'botwriter'), |
| 35 |
], |
| 36 |
'pros' => [ |
| 37 |
__('Best for long-form content', 'botwriter'), |
| 38 |
__('Very nuanced responses', 'botwriter'), |
| 39 |
__('Excellent instruction following', 'botwriter'), |
| 40 |
__('Prompt caching (save up to 90%)', 'botwriter'), |
| 41 |
], |
| 42 |
'cons' => [ |
| 43 |
__('Can be overly cautious sometimes', 'botwriter'), |
| 44 |
__('No image generation (text only)', 'botwriter'), |
| 45 |
], |
| 46 |
]; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Render Anthropic settings tab content |
| 51 |
*/ |
| 52 |
function botwriter_render_anthropic_settings($settings, $is_active) { |
| 53 |
$info = botwriter_get_anthropic_info(); |
| 54 |
?> |
| 55 |
<div class="provider-config-section"> |
| 56 |
<div class="provider-config-card"> |
| 57 |
<h4><?php esc_html_e('API Configuration', 'botwriter'); ?></h4> |
| 58 |
<div class="form-row"> |
| 59 |
<label><?php esc_html_e('API Key:', 'botwriter'); ?></label> |
| 60 |
<div class="api-key-wrapper"> |
| 61 |
<input type="password" name="botwriter_anthropic_api_key" class="form-control api-key-input" |
| 62 |
value="<?php echo esc_attr(botwriter_decrypt_api_key(get_option('botwriter_anthropic_api_key'))); ?>" |
| 63 |
placeholder="sk-ant-..."> |
| 64 |
<button type="button" class="button toggle-api-key"><?php esc_html_e('Show', 'botwriter'); ?></button> |
| 65 |
<button type="button" class="button button-secondary test-api-key" data-provider="anthropic"> |
| 66 |
<span class="dashicons dashicons-yes-alt"></span> <?php esc_html_e('Test API Key & Update Models', 'botwriter'); ?> |
| 67 |
</button> |
| 68 |
<span class="test-api-result"></span> |
| 69 |
</div> |
| 70 |
<p class="description"><?php esc_html_e('Your Anthropic API key starts with "sk-ant-"', 'botwriter'); ?></p> |
| 71 |
<?php botwriter_api_key_transmission_notice(); ?> |
| 72 |
</div> |
| 73 |
<div class="form-row"> |
| 74 |
<label><?php esc_html_e('Model:', 'botwriter'); ?></label> |
| 75 |
<div class="model-select-wrapper"> |
| 76 |
<?php botwriter_render_model_select('anthropic', 'botwriter_anthropic_model', $settings['botwriter_anthropic_model']); ?> |
| 77 |
<button type="button" class="button button-secondary test-model" data-provider="anthropic"> |
| 78 |
<span class="dashicons dashicons-controls-play"></span> <?php esc_html_e('Test Model', 'botwriter'); ?> |
| 79 |
</button> |
| 80 |
<span class="test-model-result"></span> |
| 81 |
</div> |
| 82 |
</div> |
| 83 |
</div> |
| 84 |
|
| 85 |
<div class="provider-info-card"> |
| 86 |
<h4><span class="dashicons dashicons-info-outline"></span> <?php esc_html_e('How to Get Your API Key', 'botwriter'); ?></h4> |
| 87 |
<ol class="setup-steps"> |
| 88 |
<li><?php esc_html_e('Go to', 'botwriter'); ?> <a href="https://console.anthropic.com/login" target="_blank">console.anthropic.com</a> <?php esc_html_e('and create an account', 'botwriter'); ?></li> |
| 89 |
<li><?php esc_html_e('Navigate to', 'botwriter'); ?> <a href="https://console.anthropic.com/settings/keys" target="_blank"><?php esc_html_e('API Keys', 'botwriter'); ?></a></li> |
| 90 |
<li><?php esc_html_e('Click "Create Key"', 'botwriter'); ?></li> |
| 91 |
<li><?php esc_html_e('Copy the key (it starts with "sk-ant-") and paste it above', 'botwriter'); ?></li> |
| 92 |
<li><?php esc_html_e('Add billing information in', 'botwriter'); ?> <a href="https://console.anthropic.com/settings/billing" target="_blank"><?php esc_html_e('Billing settings', 'botwriter'); ?></a></li> |
| 93 |
</ol> |
| 94 |
<div class="info-tip"> |
| 95 |
<span class="dashicons dashicons-lightbulb"></span> |
| 96 |
<p><?php esc_html_e('Tip: New accounts receive $5 in free API credits to get started!', 'botwriter'); ?></p> |
| 97 |
</div> |
| 98 |
</div> |
| 99 |
|
| 100 |
<div class="provider-pricing-card"> |
| 101 |
<h4><span class="dashicons dashicons-money-alt"></span> <?php esc_html_e('Pricing Overview', 'botwriter'); ?></h4> |
| 102 |
|
| 103 |
<div class="pricing-highlight"> |
| 104 |
<span class="free-credits-badge"><?php esc_html_e('Free Credits', 'botwriter'); ?></span> |
| 105 |
<p><?php echo esc_html($info['free_credits']); ?></p> |
| 106 |
</div> |
| 107 |
|
| 108 |
<table class="pricing-table"> |
| 109 |
<thead> |
| 110 |
<tr> |
| 111 |
<th><?php esc_html_e('Model', 'botwriter'); ?></th> |
| 112 |
<th><?php esc_html_e('Cost (per 1M tokens)', 'botwriter'); ?></th> |
| 113 |
</tr> |
| 114 |
</thead> |
| 115 |
<tbody> |
| 116 |
<?php foreach ($info['pricing_summary'] as $model => $price): ?> |
| 117 |
<tr> |
| 118 |
<td><code><?php echo esc_html($model); ?></code></td> |
| 119 |
<td><?php echo esc_html($price); ?></td> |
| 120 |
</tr> |
| 121 |
<?php endforeach; ?> |
| 122 |
</tbody> |
| 123 |
</table> |
| 124 |
|
| 125 |
<div class="cost-saving-tip"> |
| 126 |
<span class="dashicons dashicons-saved"></span> |
| 127 |
<strong><?php esc_html_e('Save 50%:', 'botwriter'); ?></strong> |
| 128 |
<?php esc_html_e('Use Batch Processing for non-urgent tasks with 24-hour turnaround.', 'botwriter'); ?> |
| 129 |
</div> |
| 130 |
|
| 131 |
<p class="pricing-note"> |
| 132 |
<a href="<?php echo esc_url($info['pricing_url']); ?>" target="_blank" class="button button-secondary"> |
| 133 |
<span class="dashicons dashicons-external"></span> <?php esc_html_e('View Full Pricing', 'botwriter'); ?> |
| 134 |
</a> |
| 135 |
</p> |
| 136 |
</div> |
| 137 |
|
| 138 |
<div class="provider-features-card"> |
| 139 |
<h4><span class="dashicons dashicons-star-filled"></span> <?php esc_html_e('Features & Benefits', 'botwriter'); ?></h4> |
| 140 |
<ul class="features-list"> |
| 141 |
<?php foreach ($info['features'] as $feature): ?> |
| 142 |
<li><span class="dashicons dashicons-yes-alt"></span> <?php echo esc_html($feature); ?></li> |
| 143 |
<?php endforeach; ?> |
| 144 |
</ul> |
| 145 |
|
| 146 |
<div class="pros-cons"> |
| 147 |
<div class="pros"> |
| 148 |
<h5><?php esc_html_e('Pros', 'botwriter'); ?></h5> |
| 149 |
<ul> |
| 150 |
<?php foreach ($info['pros'] as $pro): ?> |
| 151 |
<li><span class="dashicons dashicons-plus-alt2"></span> <?php echo esc_html($pro); ?></li> |
| 152 |
<?php endforeach; ?> |
| 153 |
</ul> |
| 154 |
</div> |
| 155 |
<div class="cons"> |
| 156 |
<h5><?php esc_html_e('Cons', 'botwriter'); ?></h5> |
| 157 |
<ul> |
| 158 |
<?php foreach ($info['cons'] as $con): ?> |
| 159 |
<li><span class="dashicons dashicons-minus"></span> <?php echo esc_html($con); ?></li> |
| 160 |
<?php endforeach; ?> |
| 161 |
</ul> |
| 162 |
</div> |
| 163 |
</div> |
| 164 |
</div> |
| 165 |
|
| 166 |
<div class="provider-links-card"> |
| 167 |
<h4><span class="dashicons dashicons-admin-links"></span> <?php esc_html_e('Useful Links', 'botwriter'); ?></h4> |
| 168 |
<div class="links-grid"> |
| 169 |
<a href="<?php echo esc_url($info['api_url']); ?>" target="_blank" class="link-item"> |
| 170 |
<span class="dashicons dashicons-admin-network"></span> |
| 171 |
<?php esc_html_e('Get API Key', 'botwriter'); ?> |
| 172 |
</a> |
| 173 |
<a href="<?php echo esc_url($info['docs_url']); ?>" target="_blank" class="link-item"> |
| 174 |
<span class="dashicons dashicons-book"></span> |
| 175 |
<?php esc_html_e('Documentation', 'botwriter'); ?> |
| 176 |
</a> |
| 177 |
<a href="<?php echo esc_url($info['pricing_url']); ?>" target="_blank" class="link-item"> |
| 178 |
<span class="dashicons dashicons-money-alt"></span> |
| 179 |
<?php esc_html_e('Pricing', 'botwriter'); ?> |
| 180 |
</a> |
| 181 |
<a href="https://status.anthropic.com/" target="_blank" class="link-item"> |
| 182 |
<span class="dashicons dashicons-heart"></span> |
| 183 |
<?php esc_html_e('API Status', 'botwriter'); ?> |
| 184 |
</a> |
| 185 |
</div> |
| 186 |
</div> |
| 187 |
</div> |
| 188 |
<?php |
| 189 |
} |
| 190 |
|