declarations.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. 'jina' = 'jina',
  44. }
  45. export type ProviderConfigItem = {
  46. key: ProviderEnum
  47. titleIcon: TypeWithI18N<ReactElement>
  48. subTitleIcon?: ReactElement
  49. desc?: TypeWithI18N
  50. bgColor?: string
  51. hit?: TypeWithI18N
  52. disable?: {
  53. tip: TypeWithI18N
  54. link: {
  55. href: TypeWithI18N
  56. label: TypeWithI18N
  57. }
  58. }
  59. }
  60. export enum ModelType {
  61. textGeneration = 'text-generation',
  62. embeddings = 'embeddings',
  63. speech2text = 'speech2text',
  64. reranking = 'reranking',
  65. }
  66. export enum ModelFeature {
  67. agentThought = 'agent_thought',
  68. vision = 'vision',
  69. }
  70. // backend defined model struct: /console/api/workspaces/current/models/model-type/:model_type
  71. export type BackendModel = {
  72. model_name: string
  73. model_display_name: string // not always exist
  74. model_type: ModelType
  75. model_mode: ModelModeType
  76. model_provider: {
  77. provider_name: ProviderEnum
  78. provider_type: PreferredProviderTypeEnum
  79. quota_type: 'trial' | 'paid'
  80. quota_unit: 'times' | 'tokens'
  81. quota_used: number
  82. quota_limit: number
  83. }
  84. features: ModelFeature[]
  85. }
  86. export type ProviderConfigModal = {
  87. key: ProviderEnum
  88. title: TypeWithI18N
  89. icon: ReactElement
  90. defaultValue?: FormValue
  91. validateKeys?: string[] | ((v?: FormValue) => string[])
  92. filterValue?: (v?: FormValue) => FormValue
  93. fields: Field[]
  94. link: {
  95. href: string
  96. label: TypeWithI18N
  97. }
  98. }
  99. export type ProviderConfig = {
  100. selector: ProviderSelector
  101. item: ProviderConfigItem
  102. modal: ProviderConfigModal
  103. }
  104. export enum PreferredProviderTypeEnum {
  105. 'system' = 'system',
  106. 'custom' = 'custom',
  107. }
  108. export enum ModelFlexibilityEnum {
  109. 'fixed' = 'fixed',
  110. 'configurable' = 'configurable',
  111. }
  112. export type ProviderCommon = {
  113. provider_name: ProviderEnum
  114. provider_type: PreferredProviderTypeEnum
  115. is_valid: boolean
  116. last_used: number
  117. }
  118. export type ProviderWithQuota = {
  119. quota_type: string
  120. quota_unit: string
  121. quota_limit: number
  122. quota_used: number
  123. } & ProviderCommon
  124. export type ProviderWithConfig = {
  125. config: Record<string, string>
  126. } & ProviderCommon
  127. export type Model = {
  128. model_name: string
  129. model_type: string
  130. config: Record<string, string>
  131. }
  132. export type ProviderWithModels = {
  133. models: Model[]
  134. } & ProviderCommon
  135. export type ProviderInstance = ProviderWithQuota | ProviderWithConfig | ProviderWithModels
  136. export type Provider = {
  137. preferred_provider_type: PreferredProviderTypeEnum
  138. model_flexibility: ModelFlexibilityEnum
  139. providers: ProviderInstance[]
  140. }
  141. export type ProviderMap = {
  142. [k in ProviderEnum]: Provider
  143. }