declarations.ts 3.3 KB

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