declarations.ts 3.3 KB

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