declarations.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. export type FormValue = Record<string, any>
  2. export type TypeWithI18N<T = string> = {
  3. en_US: T
  4. zh_Hans: T
  5. [key: string]: T
  6. }
  7. export enum FormTypeEnum {
  8. textInput = 'text-input',
  9. textNumber = 'number-input',
  10. secretInput = 'secret-input',
  11. select = 'select',
  12. radio = 'radio',
  13. files = 'files',
  14. }
  15. export type FormOption = {
  16. label: TypeWithI18N
  17. value: string
  18. show_on: FormShowOnObject[]
  19. }
  20. export enum ModelTypeEnum {
  21. textGeneration = 'llm',
  22. textEmbedding = 'text-embedding',
  23. rerank = 'rerank',
  24. speech2text = 'speech2text',
  25. moderation = 'moderation',
  26. tts = 'tts',
  27. }
  28. export const MODEL_TYPE_TEXT = {
  29. [ModelTypeEnum.textGeneration]: 'LLM',
  30. [ModelTypeEnum.textEmbedding]: 'Text Embedding',
  31. [ModelTypeEnum.rerank]: 'Rerank',
  32. [ModelTypeEnum.speech2text]: 'Speech2text',
  33. [ModelTypeEnum.moderation]: 'Moderation',
  34. [ModelTypeEnum.tts]: 'TTS',
  35. }
  36. export enum ConfigurationMethodEnum {
  37. predefinedModel = 'predefined-model',
  38. customizableModel = 'customizable-model',
  39. fetchFromRemote = 'fetch-from-remote',
  40. }
  41. export enum ModelFeatureEnum {
  42. toolCall = 'tool-call',
  43. multiToolCall = 'multi-tool-call',
  44. agentThought = 'agent-thought',
  45. vision = 'vision',
  46. }
  47. export enum ModelFeatureTextEnum {
  48. toolCall = 'Tool Call',
  49. multiToolCall = 'Multi Tool Call',
  50. agentThought = 'Agent Thought',
  51. vision = 'Vision',
  52. }
  53. export enum ModelStatusEnum {
  54. active = 'active',
  55. noConfigure = 'no-configure',
  56. quotaExceeded = 'quota-exceeded',
  57. noPermission = 'no-permission',
  58. disabled = 'disabled',
  59. }
  60. export const MODEL_STATUS_TEXT: { [k: string]: TypeWithI18N } = {
  61. 'no-configure': {
  62. en_US: 'No Configure',
  63. zh_Hans: '未配置凭据',
  64. },
  65. 'quota-exceeded': {
  66. en_US: 'Quota Exceeded',
  67. zh_Hans: '额度不足',
  68. },
  69. 'no-permission': {
  70. en_US: 'No Permission',
  71. zh_Hans: '无使用权限',
  72. },
  73. }
  74. export enum CustomConfigurationStatusEnum {
  75. active = 'active',
  76. noConfigure = 'no-configure',
  77. }
  78. export type FormShowOnObject = {
  79. variable: string
  80. value: string
  81. }
  82. export type CredentialFormSchemaBase = {
  83. variable: string
  84. label: TypeWithI18N
  85. type: FormTypeEnum
  86. required: boolean
  87. default?: string
  88. tooltip?: TypeWithI18N
  89. show_on: FormShowOnObject[]
  90. url?: string
  91. }
  92. export type CredentialFormSchemaTextInput = CredentialFormSchemaBase & { max_length?: number; placeholder?: TypeWithI18N }
  93. export type CredentialFormSchemaNumberInput = CredentialFormSchemaBase & { min?: number; max?: number; placeholder?: TypeWithI18N }
  94. export type CredentialFormSchemaSelect = CredentialFormSchemaBase & { options: FormOption[]; placeholder?: TypeWithI18N }
  95. export type CredentialFormSchemaRadio = CredentialFormSchemaBase & { options: FormOption[] }
  96. export type CredentialFormSchemaSecretInput = CredentialFormSchemaBase & { placeholder?: TypeWithI18N }
  97. export type CredentialFormSchema = CredentialFormSchemaTextInput | CredentialFormSchemaSelect | CredentialFormSchemaRadio | CredentialFormSchemaSecretInput
  98. export type ModelItem = {
  99. model: string
  100. label: TypeWithI18N
  101. model_type: ModelTypeEnum
  102. features?: ModelFeatureEnum[]
  103. fetch_from: ConfigurationMethodEnum
  104. status: ModelStatusEnum
  105. model_properties: Record<string, string | number>
  106. load_balancing_enabled: boolean
  107. deprecated?: boolean
  108. }
  109. export enum PreferredProviderTypeEnum {
  110. system = 'system',
  111. custom = 'custom',
  112. }
  113. export enum CurrentSystemQuotaTypeEnum {
  114. trial = 'trial',
  115. free = 'free',
  116. paid = 'paid',
  117. }
  118. export enum QuotaUnitEnum {
  119. times = 'times',
  120. tokens = 'tokens',
  121. credits = 'credits',
  122. }
  123. export type QuotaConfiguration = {
  124. quota_type: CurrentSystemQuotaTypeEnum
  125. quota_unit: QuotaUnitEnum
  126. quota_limit: number
  127. quota_used: number
  128. last_used: number
  129. is_valid: boolean
  130. }
  131. export type ModelProvider = {
  132. provider: string
  133. label: TypeWithI18N
  134. description?: TypeWithI18N
  135. help: {
  136. title: TypeWithI18N
  137. url: TypeWithI18N
  138. }
  139. icon_small: TypeWithI18N
  140. icon_large: TypeWithI18N
  141. background?: string
  142. supported_model_types: ModelTypeEnum[]
  143. configurate_methods: ConfigurationMethodEnum[]
  144. provider_credential_schema: {
  145. credential_form_schemas: CredentialFormSchema[]
  146. }
  147. model_credential_schema: {
  148. model: {
  149. label: TypeWithI18N
  150. placeholder: TypeWithI18N
  151. }
  152. credential_form_schemas: CredentialFormSchema[]
  153. }
  154. preferred_provider_type: PreferredProviderTypeEnum
  155. custom_configuration: {
  156. status: CustomConfigurationStatusEnum
  157. }
  158. system_configuration: {
  159. enabled: boolean
  160. current_quota_type: CurrentSystemQuotaTypeEnum
  161. quota_configurations: QuotaConfiguration[]
  162. }
  163. }
  164. export type Model = {
  165. provider: string
  166. icon_large: TypeWithI18N
  167. icon_small: TypeWithI18N
  168. label: TypeWithI18N
  169. models: ModelItem[]
  170. status: ModelStatusEnum
  171. }
  172. export type DefaultModelResponse = {
  173. model: string
  174. model_type: ModelTypeEnum
  175. provider: {
  176. provider: string
  177. icon_large: TypeWithI18N
  178. icon_small: TypeWithI18N
  179. }
  180. }
  181. export type DefaultModel = {
  182. provider: string
  183. model: string
  184. }
  185. export type CustomConfigurationModelFixedFields = {
  186. __model_name: string
  187. __model_type: ModelTypeEnum
  188. }
  189. export type ModelParameterRule = {
  190. default?: number | string | boolean | string[]
  191. help?: TypeWithI18N
  192. label: TypeWithI18N
  193. min?: number
  194. max?: number
  195. name: string
  196. precision?: number
  197. required: false
  198. type: string
  199. use_template?: string
  200. options?: string[]
  201. tagPlaceholder?: TypeWithI18N
  202. }
  203. export type ModelLoadBalancingConfigEntry = {
  204. /** model balancing config entry id */
  205. id?: string
  206. /** is config entry enabled */
  207. enabled?: boolean
  208. /** config entry name */
  209. name: string
  210. /** model balancing credential */
  211. credentials: Record<string, string | undefined | boolean>
  212. /** is config entry currently removed from Round-robin queue */
  213. in_cooldown?: boolean
  214. /** cooldown time (in seconds) */
  215. ttl?: number
  216. }
  217. export type ModelLoadBalancingConfig = {
  218. enabled: boolean
  219. configs: ModelLoadBalancingConfigEntry[]
  220. }