declarations.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. fields: Field[]
  84. link: {
  85. href: string
  86. label: TypeWithI18N
  87. }
  88. }
  89. export type ProviderConfig = {
  90. selector: ProviderSelector
  91. item: ProviderConfigItem
  92. modal: ProviderConfigModal
  93. }
  94. export enum PreferredProviderTypeEnum {
  95. 'system' = 'system',
  96. 'custom' = 'custom',
  97. }
  98. export enum ModelFlexibilityEnum {
  99. 'fixed' = 'fixed',
  100. 'configurable' = 'configurable',
  101. }
  102. export type ProviderCommon = {
  103. provider_name: ProviderEnum
  104. provider_type: PreferredProviderTypeEnum
  105. is_valid: boolean
  106. last_used: number
  107. }
  108. export type ProviderWithQuota = {
  109. quota_type: string
  110. quota_unit: string
  111. quota_limit: number
  112. quota_used: number
  113. } & ProviderCommon
  114. export type ProviderWithConfig = {
  115. config: Record<string, string>
  116. } & ProviderCommon
  117. export type Model = {
  118. model_name: string
  119. model_type: string
  120. config: Record<string, string>
  121. }
  122. export type ProviderWithModels = {
  123. models: Model[]
  124. } & ProviderCommon
  125. export type ProviderInstance = ProviderWithQuota | ProviderWithConfig | ProviderWithModels
  126. export type Provider = {
  127. preferred_provider_type: PreferredProviderTypeEnum
  128. model_flexibility: ModelFlexibilityEnum
  129. providers: ProviderInstance[]
  130. }
  131. export type ProviderMap = {
  132. [k in ProviderEnum]: Provider
  133. }