PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.5
4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 All 203 releases
betterdocs / react-src / admin / settings / fields / MinTokenNumber.js

MinTokenNumber.js in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.5, at react-src/admin/settings/fields/MinTokenNumber.js

74 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React from 'react';
2 import { __, sprintf } from '@wordpress/i18n';
3 import {
4 GenericInput,
5 useBuilderContext,
6 validFieldProps,
7 withLabel
8 } from 'quickbuilder';
9
10 /**
11 * Number input that shows an inline warning when its value falls below
12 * the per-model minimum defined in `props.min_token_map`. The minimum is
13 * keyed by the family of the currently-selected model field
14 * (`props.model_field` -> read live from builderContext.values).
15 *
16 * Renders through quickbuilder's GenericInput + withLabel so the DOM
17 * structure and styling match every other number field in BetterDocs
18 * settings. The notice is informational only — actual save blocking
19 * happens server-side in Core/Settings.php::save_settings().
20 */
21 const MinTokenNumber = (props) => {
22 const builderContext = useBuilderContext();
23
24 const liveValue = builderContext.values?.[props.name];
25 const currentVal = parseInt(
26 typeof liveValue !== 'undefined' ? liveValue : props.value ?? props.default ?? 0,
27 10
28 );
29
30 const currentModel = String(builderContext.values?.[props.model_field] ?? '');
31 // gpt-5.x point releases (e.g. gpt-5.5) need a heavier token floor and longer
32 // server limits than the base gpt-5 family, so they get their own map key.
33 const isPointRelease = /^gpt-5\.\d/.test(currentModel);
34 const family = isPointRelease
35 ? 'gpt-5.5'
36 : currentModel.indexOf('gpt-5') === 0
37 ? 'gpt-5'
38 : 'gpt-4';
39 const minToken = parseInt(props.min_token_map?.[family] ?? 0, 10);
40 const isBelow = minToken > 0 && currentVal < minToken;
41
42 // Strip our custom props so they don't leak as HTML attributes on the input.
43 const validProps = validFieldProps(props, ['min_token_map', 'model_field', 'context']);
44
45 return (
46 <>
47 <GenericInput {...validProps} type="number" min={1} />
48 {isBelow && (
49 <div className="betterdocs-min-token-notice" role="alert">
50 {sprintf(
51 /* translators: 1: minimum number of tokens, 2: model identifier */
52 __(
53 'Recommended minimum is %1$d tokens for %2$s. Lower values can cause empty or truncated responses.',
54 'betterdocs'
55 ),
56 minToken,
57 currentModel || family
58 )}
59 </div>
60 )}
61 {isPointRelease && (
62 <div className="betterdocs-min-token-notice betterdocs-server-time-notice" role="alert">
63 {__(
64 'GPT-5.5 produces large, slow responses. Raise your server limits before using it — increase PHP max execution time / your web-server timeout (e.g. 300 seconds) and memory_limit, or generation may time out before it finishes.',
65 'betterdocs'
66 )}
67 </div>
68 )}
69 </>
70 );
71 };
72
73 export default withLabel(MinTokenNumber);
74