declarations.ts 3.0 KB

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