index.ts 4.5 KB

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