index.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import { APP_NAME } from '$lib/constants';
  2. import { type Writable, writable } from 'svelte/store';
  3. import type { GlobalModelConfig, ModelConfig } from '$lib/apis';
  4. import type { Banner } from '$lib/types';
  5. import type { Socket } from 'socket.io-client';
  6. // Backend
  7. export const WEBUI_NAME = writable(APP_NAME);
  8. export const config: Writable<Config | undefined> = writable(undefined);
  9. export const user: Writable<SessionUser | undefined> = writable(undefined);
  10. // Frontend
  11. export const MODEL_DOWNLOAD_POOL = writable({});
  12. export const mobile = writable(false);
  13. export const socket: Writable<null | Socket> = writable(null);
  14. export const activeUserCount: Writable<null | number> = writable(null);
  15. export const USAGE_POOL: Writable<null | string[]> = writable(null);
  16. export const theme = writable('system');
  17. export const chatId = writable('');
  18. export const chats = writable([]);
  19. export const tags = writable([]);
  20. export const models: Writable<Model[]> = writable([]);
  21. export const prompts: Writable<Prompt[]> = writable([]);
  22. export const documents: Writable<Document[]> = writable([]);
  23. export const tools = writable([]);
  24. export const banners: Writable<Banner[]> = writable([]);
  25. export const settings: Writable<Settings> = writable({});
  26. export const showSidebar = writable(false);
  27. export const showSettings = writable(false);
  28. export const showArchivedChats = writable(false);
  29. export const showChangelog = writable(false);
  30. export const showCallOverlay = writable(false);
  31. export type Model = OpenAIModel | OllamaModel;
  32. type BaseModel = {
  33. id: string;
  34. name: string;
  35. info?: ModelConfig;
  36. };
  37. export interface OpenAIModel extends BaseModel {
  38. external: boolean;
  39. source?: string;
  40. }
  41. export interface OllamaModel extends BaseModel {
  42. details: OllamaModelDetails;
  43. size: number;
  44. description: string;
  45. model: string;
  46. modified_at: string;
  47. digest: string;
  48. }
  49. type OllamaModelDetails = {
  50. parent_model: string;
  51. format: string;
  52. family: string;
  53. families: string[] | null;
  54. parameter_size: string;
  55. quantization_level: string;
  56. };
  57. type Settings = {
  58. models?: string[];
  59. conversationMode?: boolean;
  60. speechAutoSend?: boolean;
  61. responseAutoPlayback?: boolean;
  62. audio?: AudioSettings;
  63. showUsername?: boolean;
  64. saveChatHistory?: boolean;
  65. notificationEnabled?: boolean;
  66. title?: TitleSettings;
  67. splitLargeDeltas?: boolean;
  68. chatDirection: 'LTR' | 'RTL';
  69. system?: string;
  70. requestFormat?: string;
  71. keepAlive?: string;
  72. seed?: number;
  73. temperature?: string;
  74. repeat_penalty?: string;
  75. top_k?: string;
  76. top_p?: string;
  77. num_ctx?: string;
  78. num_batch?: string;
  79. num_keep?: string;
  80. options?: ModelOptions;
  81. };
  82. type ModelOptions = {
  83. stop?: boolean;
  84. };
  85. type AudioSettings = {
  86. STTEngine?: string;
  87. TTSEngine?: string;
  88. speaker?: string;
  89. model?: string;
  90. nonLocalVoices?: boolean;
  91. };
  92. type TitleSettings = {
  93. auto?: boolean;
  94. model?: string;
  95. modelExternal?: string;
  96. prompt?: string;
  97. };
  98. type Prompt = {
  99. command: string;
  100. user_id: string;
  101. title: string;
  102. content: string;
  103. timestamp: number;
  104. };
  105. type Document = {
  106. collection_name: string;
  107. filename: string;
  108. name: string;
  109. title: string;
  110. };
  111. type Config = {
  112. status: boolean;
  113. name: string;
  114. version: string;
  115. default_locale: string;
  116. default_models: string[];
  117. default_prompt_suggestions: PromptSuggestion[];
  118. features: {
  119. auth: boolean;
  120. auth_trusted_header: boolean;
  121. enable_signup: boolean;
  122. enable_web_search?: boolean;
  123. enable_image_generation: boolean;
  124. enable_admin_export: boolean;
  125. enable_community_sharing: boolean;
  126. };
  127. };
  128. type PromptSuggestion = {
  129. content: string;
  130. title: [string, string];
  131. };
  132. type SessionUser = {
  133. id: string;
  134. email: string;
  135. name: string;
  136. role: string;
  137. profile_image_url: string;
  138. };