declarations.ts 3.4 KB

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