declarations.ts 3.2 KB

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