declarations.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_type: ModelType
  64. model_provider: {
  65. provider_name: ProviderEnum
  66. provider_type: PreferredProviderTypeEnum
  67. quota_type: 'trial' | 'paid'
  68. quota_unit: 'times' | 'tokens'
  69. quota_used: number
  70. quota_limit: number
  71. }
  72. features: ModelFeature[]
  73. }
  74. export type ProviderConfigModal = {
  75. key: ProviderEnum
  76. title: TypeWithI18N
  77. icon: ReactElement
  78. defaultValue?: FormValue
  79. validateKeys?: string[] | ((v?: FormValue) => string[])
  80. fields: Field[]
  81. link: {
  82. href: string
  83. label: TypeWithI18N
  84. }
  85. }
  86. export type ProviderConfig = {
  87. selector: ProviderSelector
  88. item: ProviderConfigItem
  89. modal: ProviderConfigModal
  90. }
  91. export enum PreferredProviderTypeEnum {
  92. 'system' = 'system',
  93. 'custom' = 'custom',
  94. }
  95. export enum ModelFlexibilityEnum {
  96. 'fixed' = 'fixed',
  97. 'configurable' = 'configurable',
  98. }
  99. export type ProviderCommon = {
  100. provider_name: ProviderEnum
  101. provider_type: PreferredProviderTypeEnum
  102. is_valid: boolean
  103. last_used: number
  104. }
  105. export type ProviderWithQuota = {
  106. quota_type: string
  107. quota_unit: string
  108. quota_limit: number
  109. quota_used: number
  110. } & ProviderCommon
  111. export type ProviderWithConfig = {
  112. config: Record<string, string>
  113. } & ProviderCommon
  114. export type Model = {
  115. model_name: string
  116. model_type: string
  117. config: Record<string, string>
  118. }
  119. export type ProviderWithModels = {
  120. models: Model[]
  121. } & ProviderCommon
  122. export type ProviderInstance = ProviderWithQuota | ProviderWithConfig | ProviderWithModels
  123. export type Provider = {
  124. preferred_provider_type: PreferredProviderTypeEnum
  125. model_flexibility: ModelFlexibilityEnum
  126. providers: ProviderInstance[]
  127. }
  128. export type ProviderMap = {
  129. [k in ProviderEnum]: Provider
  130. }