huggingface_hub.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import { ProviderEnum } from '../declarations'
  2. import type { FormValue, ProviderConfig } from '../declarations'
  3. import { Huggingface, HuggingfaceText } from '@/app/components/base/icons/src/public/llm'
  4. const config: ProviderConfig = {
  5. selector: {
  6. name: {
  7. 'en': 'Hugging Face',
  8. 'zh-Hans': 'Hugging Face',
  9. },
  10. icon: <Huggingface className='w-full h-full' />,
  11. },
  12. item: {
  13. key: ProviderEnum.huggingface_hub,
  14. titleIcon: {
  15. 'en': <HuggingfaceText className='h-6' />,
  16. 'zh-Hans': <HuggingfaceText className='h-6' />,
  17. },
  18. hit: {
  19. 'en': '🐑 Llama 2 Supported',
  20. 'zh-Hans': '🐑 Llama 2 已支持',
  21. },
  22. },
  23. modal: {
  24. key: ProviderEnum.huggingface_hub,
  25. title: {
  26. 'en': 'Hugging Face Model',
  27. 'zh-Hans': 'Hugging Face Model',
  28. },
  29. icon: <Huggingface className='h-6' />,
  30. link: {
  31. href: 'https://huggingface.co/settings/tokens',
  32. label: {
  33. 'en': 'Get your API key from Hugging Face Hub',
  34. 'zh-Hans': '从 Hugging Face Hub 获取 API Key',
  35. },
  36. },
  37. defaultValue: {
  38. model_type: 'text-generation',
  39. huggingfacehub_api_type: 'hosted_inference_api',
  40. },
  41. validateKeys: (v?: FormValue) => {
  42. if (v?.huggingfacehub_api_type === 'hosted_inference_api') {
  43. return [
  44. 'huggingfacehub_api_token',
  45. 'model_name',
  46. ]
  47. }
  48. if (v?.huggingfacehub_api_type === 'inference_endpoints') {
  49. return [
  50. 'huggingfacehub_api_token',
  51. 'model_name',
  52. 'huggingfacehub_endpoint_url',
  53. ]
  54. }
  55. return []
  56. },
  57. fields: [
  58. {
  59. type: 'radio',
  60. key: 'huggingfacehub_api_type',
  61. required: true,
  62. label: {
  63. 'en': 'Endpoint Type',
  64. 'zh-Hans': '端点类型',
  65. },
  66. options: [
  67. {
  68. key: 'hosted_inference_api',
  69. label: {
  70. 'en': 'Hosted Inference API',
  71. 'zh-Hans': 'Hosted Inference API',
  72. },
  73. },
  74. {
  75. key: 'inference_endpoints',
  76. label: {
  77. 'en': 'Inference Endpoints',
  78. 'zh-Hans': 'Inference Endpoints',
  79. },
  80. },
  81. ],
  82. },
  83. {
  84. type: 'text',
  85. key: 'huggingfacehub_api_token',
  86. required: true,
  87. label: {
  88. 'en': 'API Token',
  89. 'zh-Hans': 'API Token',
  90. },
  91. placeholder: {
  92. 'en': 'Enter your Hugging Face Hub API Token here',
  93. 'zh-Hans': '在此输入您的 Hugging Face Hub API Token',
  94. },
  95. },
  96. {
  97. type: 'text',
  98. key: 'model_name',
  99. required: true,
  100. label: {
  101. 'en': 'Model Name',
  102. 'zh-Hans': '模型名称',
  103. },
  104. placeholder: {
  105. 'en': 'Enter your Model Name here',
  106. 'zh-Hans': '在此输入您的模型名称',
  107. },
  108. },
  109. {
  110. hidden: (value?: FormValue) => value?.huggingfacehub_api_type === 'hosted_inference_api',
  111. type: 'text',
  112. key: 'huggingfacehub_endpoint_url',
  113. label: {
  114. 'en': 'Endpoint URL',
  115. 'zh-Hans': '端点 URL',
  116. },
  117. placeholder: {
  118. 'en': 'Enter your Endpoint URL here',
  119. 'zh-Hans': '在此输入您的端点 URL',
  120. },
  121. },
  122. ],
  123. },
  124. }
  125. export default config