index.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import {
  2. ChatConfig,
  3. LLMProvider,
  4. LLMProviders,
  5. ModelConfig,
  6. ProviderConfig,
  7. } from "@/app/store";
  8. import { Updater } from "@/app/typing";
  9. import { OpenAIModelConfig } from "./openai/model";
  10. import { OpenAIProviderConfig } from "./openai/provider";
  11. import { ListItem, Select } from "../ui-lib";
  12. import Locale from "@/app/locales";
  13. import { InputRange } from "../input-range";
  14. export function ModelConfigList(props: {
  15. provider: LLMProvider;
  16. config: ModelConfig;
  17. updateConfig: Updater<ModelConfig>;
  18. }) {
  19. if (props.provider === "openai") {
  20. return (
  21. <OpenAIModelConfig
  22. config={props.config.openai}
  23. updateConfig={(update) => {
  24. props.updateConfig((config) => update(config.openai));
  25. }}
  26. models={[
  27. {
  28. name: "gpt-3.5-turbo",
  29. available: true,
  30. },
  31. {
  32. name: "gpt-4",
  33. available: true,
  34. },
  35. ]}
  36. />
  37. );
  38. }
  39. return null;
  40. }
  41. export function ProviderConfigList(props: {
  42. provider: LLMProvider;
  43. config: ProviderConfig;
  44. updateConfig: Updater<ProviderConfig>;
  45. }) {
  46. if (props.provider === "openai") {
  47. return (
  48. <OpenAIProviderConfig
  49. config={props.config.openai}
  50. updateConfig={(update) => {
  51. props.updateConfig((config) => update(config.openai));
  52. }}
  53. />
  54. );
  55. }
  56. return null;
  57. }
  58. export function ProviderSelectItem(props: {
  59. value: LLMProvider;
  60. update: (value: LLMProvider) => void;
  61. }) {
  62. return (
  63. <ListItem title="服务提供商" subTitle="切换不同的模型提供商">
  64. <Select
  65. value={props.value}
  66. onChange={(e) => {
  67. props.update(e.target.value as LLMProvider);
  68. }}
  69. >
  70. {LLMProviders.map(([k, v]) => (
  71. <option value={v} key={k}>
  72. {k}
  73. </option>
  74. ))}
  75. </Select>
  76. </ListItem>
  77. );
  78. }
  79. export function ChatConfigList(props: {
  80. config: ChatConfig;
  81. updateConfig: (updater: (config: ChatConfig) => void) => void;
  82. }) {
  83. return (
  84. <>
  85. <ListItem
  86. title={Locale.Settings.InjectSystemPrompts.Title}
  87. subTitle={Locale.Settings.InjectSystemPrompts.SubTitle}
  88. >
  89. <input
  90. type="checkbox"
  91. checked={props.config.enableInjectSystemPrompts}
  92. onChange={(e) =>
  93. props.updateConfig(
  94. (config) =>
  95. (config.enableInjectSystemPrompts = e.currentTarget.checked),
  96. )
  97. }
  98. ></input>
  99. </ListItem>
  100. <ListItem
  101. title={Locale.Settings.InputTemplate.Title}
  102. subTitle={Locale.Settings.InputTemplate.SubTitle}
  103. >
  104. <input
  105. type="text"
  106. value={props.config.template}
  107. onChange={(e) =>
  108. props.updateConfig(
  109. (config) => (config.template = e.currentTarget.value),
  110. )
  111. }
  112. ></input>
  113. </ListItem>
  114. <ListItem
  115. title={Locale.Settings.HistoryCount.Title}
  116. subTitle={Locale.Settings.HistoryCount.SubTitle}
  117. >
  118. <InputRange
  119. title={props.config.historyMessageCount.toString()}
  120. value={props.config.historyMessageCount}
  121. min="0"
  122. max="64"
  123. step="1"
  124. onChange={(e) =>
  125. props.updateConfig(
  126. (config) => (config.historyMessageCount = e.target.valueAsNumber),
  127. )
  128. }
  129. ></InputRange>
  130. </ListItem>
  131. <ListItem
  132. title={Locale.Settings.CompressThreshold.Title}
  133. subTitle={Locale.Settings.CompressThreshold.SubTitle}
  134. >
  135. <input
  136. type="number"
  137. min={500}
  138. max={4000}
  139. value={props.config.compressMessageLengthThreshold}
  140. onChange={(e) =>
  141. props.updateConfig(
  142. (config) =>
  143. (config.compressMessageLengthThreshold =
  144. e.currentTarget.valueAsNumber),
  145. )
  146. }
  147. ></input>
  148. </ListItem>
  149. <ListItem title={Locale.Memory.Title} subTitle={Locale.Memory.Send}>
  150. <input
  151. type="checkbox"
  152. checked={props.config.sendMemory}
  153. onChange={(e) =>
  154. props.updateConfig(
  155. (config) => (config.sendMemory = e.currentTarget.checked),
  156. )
  157. }
  158. ></input>
  159. </ListItem>
  160. </>
  161. );
  162. }