declarations.ts 3.1 KB

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