model-config.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import { ModalConfigValidator, ModelConfig } from "../store";
  2. import Locale from "../locales";
  3. import { InputRange } from "./input-range";
  4. import { ListItem, Select } from "./ui-lib";
  5. import { useAllModels } from "../utils/hooks";
  6. export function ModelConfigList(props: {
  7. modelConfig: ModelConfig;
  8. updateConfig: (updater: (config: ModelConfig) => void) => void;
  9. }) {
  10. const allModels = useAllModels();
  11. return (
  12. <>
  13. <ListItem title={Locale.Settings.Model}>
  14. <Select
  15. value={props.modelConfig.model}
  16. onChange={(e) => {
  17. props.updateConfig(
  18. (config) =>
  19. (config.model = ModalConfigValidator.model(
  20. e.currentTarget.value,
  21. )),
  22. );
  23. }}
  24. >
  25. {allModels
  26. .filter((v) => v.available)
  27. .map((v, i) => (
  28. <option value={v.name} key={i}>
  29. {v.displayName}
  30. </option>
  31. ))}
  32. </Select>
  33. </ListItem>
  34. <ListItem
  35. title={Locale.Settings.Temperature.Title}
  36. subTitle={Locale.Settings.Temperature.SubTitle}
  37. >
  38. <InputRange
  39. value={props.modelConfig.temperature?.toFixed(1)}
  40. min="0"
  41. max="1" // lets limit it to 0-1
  42. step="0.1"
  43. onChange={(e) => {
  44. props.updateConfig(
  45. (config) =>
  46. (config.temperature = ModalConfigValidator.temperature(
  47. e.currentTarget.valueAsNumber,
  48. )),
  49. );
  50. }}
  51. ></InputRange>
  52. </ListItem>
  53. <ListItem
  54. title={Locale.Settings.TopP.Title}
  55. subTitle={Locale.Settings.TopP.SubTitle}
  56. >
  57. <InputRange
  58. value={(props.modelConfig.top_p ?? 1).toFixed(1)}
  59. min="0"
  60. max="1"
  61. step="0.1"
  62. onChange={(e) => {
  63. props.updateConfig(
  64. (config) =>
  65. (config.top_p = ModalConfigValidator.top_p(
  66. e.currentTarget.valueAsNumber,
  67. )),
  68. );
  69. }}
  70. ></InputRange>
  71. </ListItem>
  72. <ListItem
  73. title={Locale.Settings.MaxTokens.Title}
  74. subTitle={Locale.Settings.MaxTokens.SubTitle}
  75. >
  76. <input
  77. type="number"
  78. min={1024}
  79. max={512000}
  80. value={props.modelConfig.max_tokens}
  81. onChange={(e) =>
  82. props.updateConfig(
  83. (config) =>
  84. (config.max_tokens = ModalConfigValidator.max_tokens(
  85. e.currentTarget.valueAsNumber,
  86. )),
  87. )
  88. }
  89. ></input>
  90. </ListItem>
  91. <ListItem
  92. title={Locale.Settings.PresencePenalty.Title}
  93. subTitle={Locale.Settings.PresencePenalty.SubTitle}
  94. >
  95. <InputRange
  96. value={props.modelConfig.presence_penalty?.toFixed(1)}
  97. min="-2"
  98. max="2"
  99. step="0.1"
  100. onChange={(e) => {
  101. props.updateConfig(
  102. (config) =>
  103. (config.presence_penalty =
  104. ModalConfigValidator.presence_penalty(
  105. e.currentTarget.valueAsNumber,
  106. )),
  107. );
  108. }}
  109. ></InputRange>
  110. </ListItem>
  111. <ListItem
  112. title={Locale.Settings.FrequencyPenalty.Title}
  113. subTitle={Locale.Settings.FrequencyPenalty.SubTitle}
  114. >
  115. <InputRange
  116. value={props.modelConfig.frequency_penalty?.toFixed(1)}
  117. min="-2"
  118. max="2"
  119. step="0.1"
  120. onChange={(e) => {
  121. props.updateConfig(
  122. (config) =>
  123. (config.frequency_penalty =
  124. ModalConfigValidator.frequency_penalty(
  125. e.currentTarget.valueAsNumber,
  126. )),
  127. );
  128. }}
  129. ></InputRange>
  130. </ListItem>
  131. <ListItem
  132. title={Locale.Settings.InjectSystemPrompts.Title}
  133. subTitle={Locale.Settings.InjectSystemPrompts.SubTitle}
  134. >
  135. <input
  136. type="checkbox"
  137. checked={props.modelConfig.enableInjectSystemPrompts}
  138. onChange={(e) =>
  139. props.updateConfig(
  140. (config) =>
  141. (config.enableInjectSystemPrompts = e.currentTarget.checked),
  142. )
  143. }
  144. ></input>
  145. </ListItem>
  146. <ListItem
  147. title={Locale.Settings.InputTemplate.Title}
  148. subTitle={Locale.Settings.InputTemplate.SubTitle}
  149. >
  150. <input
  151. type="text"
  152. value={props.modelConfig.template}
  153. onChange={(e) =>
  154. props.updateConfig(
  155. (config) => (config.template = e.currentTarget.value),
  156. )
  157. }
  158. ></input>
  159. </ListItem>
  160. <ListItem
  161. title={Locale.Settings.HistoryCount.Title}
  162. subTitle={Locale.Settings.HistoryCount.SubTitle}
  163. >
  164. <InputRange
  165. title={props.modelConfig.historyMessageCount.toString()}
  166. value={props.modelConfig.historyMessageCount}
  167. min="0"
  168. max="64"
  169. step="1"
  170. onChange={(e) =>
  171. props.updateConfig(
  172. (config) => (config.historyMessageCount = e.target.valueAsNumber),
  173. )
  174. }
  175. ></InputRange>
  176. </ListItem>
  177. <ListItem
  178. title={Locale.Settings.CompressThreshold.Title}
  179. subTitle={Locale.Settings.CompressThreshold.SubTitle}
  180. >
  181. <input
  182. type="number"
  183. min={500}
  184. max={4000}
  185. value={props.modelConfig.compressMessageLengthThreshold}
  186. onChange={(e) =>
  187. props.updateConfig(
  188. (config) =>
  189. (config.compressMessageLengthThreshold =
  190. e.currentTarget.valueAsNumber),
  191. )
  192. }
  193. ></input>
  194. </ListItem>
  195. <ListItem title={Locale.Memory.Title} subTitle={Locale.Memory.Send}>
  196. <input
  197. type="checkbox"
  198. checked={props.modelConfig.sendMemory}
  199. onChange={(e) =>
  200. props.updateConfig(
  201. (config) => (config.sendMemory = e.currentTarget.checked),
  202. )
  203. }
  204. ></input>
  205. </ListItem>
  206. </>
  207. );
  208. }