index.ts 4.3 KB

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