index.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 chatTitle = writable('');
  19. export const channels = writable([]);
  20. export const chats = writable([]);
  21. export const pinnedChats = writable([]);
  22. export const tags = writable([]);
  23. export const models: Writable<Model[]> = writable([]);
  24. export const prompts: Writable<null | Prompt[]> = writable(null);
  25. export const knowledge: Writable<null | Document[]> = writable(null);
  26. export const tools = writable(null);
  27. export const functions = writable(null);
  28. export const banners: Writable<Banner[]> = writable([]);
  29. export const settings: Writable<Settings> = writable({});
  30. export const showSidebar = writable(false);
  31. export const showSettings = writable(false);
  32. export const showArchivedChats = writable(false);
  33. export const showChangelog = writable(false);
  34. export const showControls = writable(false);
  35. export const showOverview = writable(false);
  36. export const showArtifacts = writable(false);
  37. export const showCallOverlay = writable(false);
  38. export const temporaryChatEnabled = writable(false);
  39. export const scrollPaginationEnabled = writable(false);
  40. export const currentChatPage = writable(1);
  41. export type Model = OpenAIModel | OllamaModel;
  42. type BaseModel = {
  43. id: string;
  44. name: string;
  45. info?: ModelConfig;
  46. owned_by: 'ollama' | 'openai' | 'arena';
  47. };
  48. export interface OpenAIModel extends BaseModel {
  49. owned_by: 'openai';
  50. external: boolean;
  51. source?: string;
  52. }
  53. export interface OllamaModel extends BaseModel {
  54. owned_by: 'ollama';
  55. details: OllamaModelDetails;
  56. size: number;
  57. description: string;
  58. model: string;
  59. modified_at: string;
  60. digest: string;
  61. ollama?: {
  62. name?: string;
  63. model?: string;
  64. modified_at: string;
  65. size?: number;
  66. digest?: string;
  67. details?: {
  68. parent_model?: string;
  69. format?: string;
  70. family?: string;
  71. families?: string[];
  72. parameter_size?: string;
  73. quantization_level?: string;
  74. };
  75. urls?: number[];
  76. };
  77. }
  78. type OllamaModelDetails = {
  79. parent_model: string;
  80. format: string;
  81. family: string;
  82. families: string[] | null;
  83. parameter_size: string;
  84. quantization_level: string;
  85. };
  86. type Settings = {
  87. models?: string[];
  88. conversationMode?: boolean;
  89. speechAutoSend?: boolean;
  90. responseAutoPlayback?: boolean;
  91. audio?: AudioSettings;
  92. showUsername?: boolean;
  93. notificationEnabled?: boolean;
  94. title?: TitleSettings;
  95. splitLargeDeltas?: boolean;
  96. chatDirection: 'LTR' | 'RTL';
  97. system?: string;
  98. requestFormat?: string;
  99. keepAlive?: string;
  100. seed?: number;
  101. temperature?: string;
  102. repeat_penalty?: string;
  103. top_k?: string;
  104. top_p?: string;
  105. num_ctx?: string;
  106. num_batch?: string;
  107. num_keep?: string;
  108. options?: ModelOptions;
  109. };
  110. type ModelOptions = {
  111. stop?: boolean;
  112. };
  113. type AudioSettings = {
  114. STTEngine?: string;
  115. TTSEngine?: string;
  116. speaker?: string;
  117. model?: string;
  118. nonLocalVoices?: boolean;
  119. };
  120. type TitleSettings = {
  121. auto?: boolean;
  122. model?: string;
  123. modelExternal?: string;
  124. prompt?: string;
  125. };
  126. type Prompt = {
  127. command: string;
  128. user_id: string;
  129. title: string;
  130. content: string;
  131. timestamp: number;
  132. };
  133. type Document = {
  134. collection_name: string;
  135. filename: string;
  136. name: string;
  137. title: string;
  138. };
  139. type Config = {
  140. status: boolean;
  141. name: string;
  142. version: string;
  143. default_locale: string;
  144. default_models: string;
  145. default_prompt_suggestions: PromptSuggestion[];
  146. features: {
  147. auth: boolean;
  148. auth_trusted_header: boolean;
  149. enable_api_key: boolean;
  150. enable_signup: boolean;
  151. enable_login_form: boolean;
  152. enable_web_search?: boolean;
  153. enable_google_drive_integration: boolean;
  154. enable_image_generation: boolean;
  155. enable_admin_export: boolean;
  156. enable_admin_chat_access: boolean;
  157. enable_community_sharing: boolean;
  158. };
  159. oauth: {
  160. providers: {
  161. [key: string]: string;
  162. };
  163. };
  164. };
  165. type PromptSuggestion = {
  166. content: string;
  167. title: [string, string];
  168. };
  169. type SessionUser = {
  170. id: string;
  171. email: string;
  172. name: string;
  173. role: string;
  174. profile_image_url: string;
  175. };