model-config.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { ALL_MODELS, ModalConfigValidator, ModelConfig } from "../store";
  2. import Locale from "../locales";
  3. import { InputRange } from "./input-range";
  4. import { List, ListItem, Select } from "./ui-lib";
  5. export function ModelConfigList(props: {
  6. modelConfig: ModelConfig;
  7. updateConfig: (updater: (config: ModelConfig) => void) => void;
  8. }) {
  9. return (
  10. <>
  11. <ListItem title={Locale.Settings.Model}>
  12. <Select
  13. value={props.modelConfig.model}
  14. onChange={(e) => {
  15. props.updateConfig(
  16. (config) =>
  17. (config.model = ModalConfigValidator.model(
  18. e.currentTarget.value,
  19. )),
  20. );
  21. }}
  22. >
  23. {ALL_MODELS.map((v) => (
  24. <option value={v.name} key={v.name} disabled={!v.available}>
  25. {v.name}
  26. </option>
  27. ))}
  28. </Select>
  29. </ListItem>
  30. <ListItem
  31. title={Locale.Settings.Temperature.Title}
  32. subTitle={Locale.Settings.Temperature.SubTitle}
  33. >
  34. <InputRange
  35. value={props.modelConfig.temperature?.toFixed(1)}
  36. min="0"
  37. max="1" // lets limit it to 0-1
  38. step="0.1"
  39. onChange={(e) => {
  40. props.updateConfig(
  41. (config) =>
  42. (config.temperature = ModalConfigValidator.temperature(
  43. e.currentTarget.valueAsNumber,
  44. )),
  45. );
  46. }}
  47. ></InputRange>
  48. </ListItem>
  49. <ListItem
  50. title={Locale.Settings.MaxTokens.Title}
  51. subTitle={Locale.Settings.MaxTokens.SubTitle}
  52. >
  53. <input
  54. type="number"
  55. min={100}
  56. max={32000}
  57. value={props.modelConfig.max_tokens}
  58. onChange={(e) =>
  59. props.updateConfig(
  60. (config) =>
  61. (config.max_tokens = ModalConfigValidator.max_tokens(
  62. e.currentTarget.valueAsNumber,
  63. )),
  64. )
  65. }
  66. ></input>
  67. </ListItem>
  68. <ListItem
  69. title={Locale.Settings.PresencePenlty.Title}
  70. subTitle={Locale.Settings.PresencePenlty.SubTitle}
  71. >
  72. <InputRange
  73. value={props.modelConfig.presence_penalty?.toFixed(1)}
  74. min="-2"
  75. max="2"
  76. step="0.1"
  77. onChange={(e) => {
  78. props.updateConfig(
  79. (config) =>
  80. (config.presence_penalty =
  81. ModalConfigValidator.presence_penalty(
  82. e.currentTarget.valueAsNumber,
  83. )),
  84. );
  85. }}
  86. ></InputRange>
  87. </ListItem>
  88. <ListItem
  89. title={Locale.Settings.HistoryCount.Title}
  90. subTitle={Locale.Settings.HistoryCount.SubTitle}
  91. >
  92. <InputRange
  93. title={props.modelConfig.historyMessageCount.toString()}
  94. value={props.modelConfig.historyMessageCount}
  95. min="0"
  96. max="32"
  97. step="1"
  98. onChange={(e) =>
  99. props.updateConfig(
  100. (config) => (config.historyMessageCount = e.target.valueAsNumber),
  101. )
  102. }
  103. ></InputRange>
  104. </ListItem>
  105. <ListItem
  106. title={Locale.Settings.CompressThreshold.Title}
  107. subTitle={Locale.Settings.CompressThreshold.SubTitle}
  108. >
  109. <input
  110. type="number"
  111. min={500}
  112. max={4000}
  113. value={props.modelConfig.compressMessageLengthThreshold}
  114. onChange={(e) =>
  115. props.updateConfig(
  116. (config) =>
  117. (config.compressMessageLengthThreshold =
  118. e.currentTarget.valueAsNumber),
  119. )
  120. }
  121. ></input>
  122. </ListItem>
  123. <ListItem title={Locale.Memory.Title} subTitle={Locale.Memory.Send}>
  124. <input
  125. type="checkbox"
  126. checked={props.modelConfig.sendMemory}
  127. onChange={(e) =>
  128. props.updateConfig(
  129. (config) => (config.sendMemory = e.currentTarget.checked),
  130. )
  131. }
  132. ></input>
  133. </ListItem>
  134. </>
  135. );
  136. }