index.ts 3.8 KB

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