localai.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import { ProviderEnum } from '../declarations'
  2. import type { FormValue, ProviderConfig } from '../declarations'
  3. import { Localai, LocalaiText } from '@/app/components/base/icons/src/public/llm'
  4. const config: ProviderConfig = {
  5. selector: {
  6. name: {
  7. 'en': 'LocalAI',
  8. 'zh-Hans': 'LocalAI',
  9. },
  10. icon: <Localai className='w-full h-full' />,
  11. },
  12. item: {
  13. key: ProviderEnum.localai,
  14. titleIcon: {
  15. 'en': <LocalaiText className='h-6' />,
  16. 'zh-Hans': <LocalaiText className='h-6' />,
  17. },
  18. disable: {
  19. tip: {
  20. 'en': 'Only supports the ',
  21. 'zh-Hans': '仅支持',
  22. },
  23. link: {
  24. href: {
  25. 'en': 'https://docs.dify.ai/getting-started/install-self-hosted',
  26. 'zh-Hans': 'https://docs.dify.ai/v/zh-hans/getting-started/install-self-hosted',
  27. },
  28. label: {
  29. 'en': 'community open-source version',
  30. 'zh-Hans': '社区开源版本',
  31. },
  32. },
  33. },
  34. },
  35. modal: {
  36. key: ProviderEnum.localai,
  37. title: {
  38. 'en': 'LocalAI',
  39. 'zh-Hans': 'LocalAI',
  40. },
  41. icon: <Localai className='h-6' />,
  42. link: {
  43. href: 'https://github.com/go-skynet/LocalAI',
  44. label: {
  45. 'en': 'How to deploy LocalAI',
  46. 'zh-Hans': '如何部署 LocalAI',
  47. },
  48. },
  49. defaultValue: {
  50. model_type: 'text-generation',
  51. completion_type: 'completion',
  52. },
  53. validateKeys: (v?: FormValue) => {
  54. if (v?.model_type === 'text-generation') {
  55. return [
  56. 'model_type',
  57. 'model_name',
  58. 'server_url',
  59. 'completion_type',
  60. ]
  61. }
  62. if (v?.model_type === 'embeddings') {
  63. return [
  64. 'model_type',
  65. 'model_name',
  66. 'server_url',
  67. ]
  68. }
  69. return []
  70. },
  71. filterValue: (v?: FormValue) => {
  72. let filteredKeys: string[] = []
  73. if (v?.model_type === 'text-generation') {
  74. filteredKeys = [
  75. 'model_type',
  76. 'model_name',
  77. 'server_url',
  78. 'completion_type',
  79. ]
  80. }
  81. if (v?.model_type === 'embeddings') {
  82. filteredKeys = [
  83. 'model_type',
  84. 'model_name',
  85. 'server_url',
  86. ]
  87. }
  88. return filteredKeys.reduce((prev: FormValue, next: string) => {
  89. prev[next] = v?.[next] || ''
  90. return prev
  91. }, {})
  92. },
  93. fields: [
  94. {
  95. type: 'radio',
  96. key: 'model_type',
  97. required: true,
  98. label: {
  99. 'en': 'Model Type',
  100. 'zh-Hans': '模型类型',
  101. },
  102. options: [
  103. {
  104. key: 'text-generation',
  105. label: {
  106. 'en': 'Text Generation',
  107. 'zh-Hans': '文本生成',
  108. },
  109. },
  110. {
  111. key: 'embeddings',
  112. label: {
  113. 'en': 'Embeddings',
  114. 'zh-Hans': 'Embeddings',
  115. },
  116. },
  117. ],
  118. },
  119. {
  120. type: 'text',
  121. key: 'model_name',
  122. required: true,
  123. label: {
  124. 'en': 'Model Name',
  125. 'zh-Hans': '模型名称',
  126. },
  127. placeholder: {
  128. 'en': 'Enter your Model Name here',
  129. 'zh-Hans': '在此输入您的模型名称',
  130. },
  131. },
  132. {
  133. hidden: (value?: FormValue) => value?.model_type === 'embeddings',
  134. type: 'radio',
  135. key: 'completion_type',
  136. required: true,
  137. label: {
  138. 'en': 'Completion Type',
  139. 'zh-Hans': 'Completion Type',
  140. },
  141. options: [
  142. {
  143. key: 'completion',
  144. label: {
  145. 'en': 'Completion',
  146. 'zh-Hans': 'Completion',
  147. },
  148. },
  149. {
  150. key: 'chat_completion',
  151. label: {
  152. 'en': 'Chat Completion',
  153. 'zh-Hans': 'Chat Completion',
  154. },
  155. },
  156. ],
  157. },
  158. {
  159. type: 'text',
  160. key: 'server_url',
  161. required: true,
  162. label: {
  163. 'en': 'Server url',
  164. 'zh-Hans': 'Server url',
  165. },
  166. placeholder: {
  167. 'en': 'Enter your Server Url, eg: https://example.com/xxx',
  168. 'zh-Hans': '在此输入您的 Server Url,如:https://example.com/xxx',
  169. },
  170. },
  171. ],
  172. },
  173. }
  174. export default config