You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import type { ReactElement } from 'react'
  2. import type { ModelModeType } from '@/types/app'
  3. export type FormValue = Record<string, string>
  4. export type TypeWithI18N<T = string> = {
  5. 'en': T
  6. 'zh-Hans': T
  7. }
  8. export type Option = {
  9. key: string
  10. label: TypeWithI18N
  11. }
  12. export type ProviderSelector = {
  13. name: TypeWithI18N
  14. icon: ReactElement
  15. }
  16. export type Field = {
  17. hidden?: (v?: FormValue) => boolean
  18. type: string
  19. key: string
  20. required?: boolean
  21. label: TypeWithI18N
  22. options?: Option[] | ((v: FormValue) => Option[])
  23. placeholder?: TypeWithI18N
  24. help?: TypeWithI18N
  25. }
  26. export enum ProviderEnum {
  27. 'openai' = 'openai',
  28. 'anthropic' = 'anthropic',
  29. 'replicate' = 'replicate',
  30. 'azure_openai' = 'azure_openai',
  31. 'huggingface_hub' = 'huggingface_hub',
  32. 'tongyi' = 'tongyi',
  33. 'wenxin' = 'wenxin',
  34. 'spark' = 'spark',
  35. 'minimax' = 'minimax',
  36. 'chatglm' = 'chatglm',
  37. 'xinference' = 'xinference',
  38. 'openllm' = 'openllm',
  39. 'localai' = 'localai',
  40. 'zhipuai' = 'zhipuai',
  41. 'baichuan' = 'baichuan',
  42. 'cohere' = 'cohere',
  43. }
  44. export type ProviderConfigItem = {
  45. key: ProviderEnum
  46. titleIcon: TypeWithI18N<ReactElement>
  47. subTitleIcon?: ReactElement
  48. desc?: TypeWithI18N
  49. bgColor?: string
  50. hit?: TypeWithI18N
  51. disable?: {
  52. tip: TypeWithI18N
  53. link: {
  54. href: TypeWithI18N
  55. label: TypeWithI18N
  56. }
  57. }
  58. }
  59. export enum ModelType {
  60. textGeneration = 'text-generation',
  61. embeddings = 'embeddings',
  62. speech2text = 'speech2text',
  63. reranking = 'reranking',
  64. }
  65. export enum ModelFeature {
  66. agentThought = 'agent_thought',
  67. vision = 'vision',
  68. }
  69. // backend defined model struct: /console/api/workspaces/current/models/model-type/:model_type
  70. export type BackendModel = {
  71. model_name: string
  72. model_display_name: string // not always exist
  73. model_type: ModelType
  74. model_mode: ModelModeType
  75. model_provider: {
  76. provider_name: ProviderEnum
  77. provider_type: PreferredProviderTypeEnum
  78. quota_type: 'trial' | 'paid'
  79. quota_unit: 'times' | 'tokens'
  80. quota_used: number
  81. quota_limit: number
  82. }
  83. features: ModelFeature[]
  84. }
  85. export type ProviderConfigModal = {
  86. key: ProviderEnum
  87. title: TypeWithI18N
  88. icon: ReactElement
  89. defaultValue?: FormValue
  90. validateKeys?: string[] | ((v?: FormValue) => string[])
  91. filterValue?: (v?: FormValue) => FormValue
  92. fields: Field[]
  93. link: {
  94. href: string
  95. label: TypeWithI18N
  96. }
  97. }
  98. export type ProviderConfig = {
  99. selector: ProviderSelector
  100. item: ProviderConfigItem
  101. modal: ProviderConfigModal
  102. }
  103. export enum PreferredProviderTypeEnum {
  104. 'system' = 'system',
  105. 'custom' = 'custom',
  106. }
  107. export enum ModelFlexibilityEnum {
  108. 'fixed' = 'fixed',
  109. 'configurable' = 'configurable',
  110. }
  111. export type ProviderCommon = {
  112. provider_name: ProviderEnum
  113. provider_type: PreferredProviderTypeEnum
  114. is_valid: boolean
  115. last_used: number
  116. }
  117. export type ProviderWithQuota = {
  118. quota_type: string
  119. quota_unit: string
  120. quota_limit: number
  121. quota_used: number
  122. } & ProviderCommon
  123. export type ProviderWithConfig = {
  124. config: Record<string, string>
  125. } & ProviderCommon
  126. export type Model = {
  127. model_name: string
  128. model_type: string
  129. config: Record<string, string>
  130. }
  131. export type ProviderWithModels = {
  132. models: Model[]
  133. } & ProviderCommon
  134. export type ProviderInstance = ProviderWithQuota | ProviderWithConfig | ProviderWithModels
  135. export type Provider = {
  136. preferred_provider_type: PreferredProviderTypeEnum
  137. model_flexibility: ModelFlexibilityEnum
  138. providers: ProviderInstance[]
  139. }
  140. export type ProviderMap = {
  141. [k in ProviderEnum]: Provider
  142. }