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