declarations.ts 3.4 KB

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