index.tsx 4.9 KB

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