index.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import { APP_NAME } from '$lib/constants';
  2. import { type Writable, writable } from 'svelte/store';
  3. import type { ModelConfig } from '$lib/apis';
  4. import type { Banner } from '$lib/types';
  5. import type { Socket } from 'socket.io-client';
  6. import emojiShortCodes from '$lib/emoji-shortcodes.json';
  7. // Backend
  8. export const WEBUI_NAME = writable(APP_NAME);
  9. export const config: Writable<Config | undefined> = writable(undefined);
  10. export const user: Writable<SessionUser | undefined> = writable(undefined);
  11. // Electron App
  12. export const isApp = writable(false);
  13. export const appInfo = writable(null);
  14. export const appData = writable(null);
  15. // Frontend
  16. export const MODEL_DOWNLOAD_POOL = writable({});
  17. export const mobile = writable(false);
  18. export const socket: Writable<null | Socket> = writable(null);
  19. export const activeUserIds: Writable<null | string[]> = writable(null);
  20. export const USAGE_POOL: Writable<null | string[]> = writable(null);
  21. export const theme = writable('system');
  22. export const shortCodesToEmojis = writable(
  23. Object.entries(emojiShortCodes).reduce((acc, [key, value]) => {
  24. if (typeof value === 'string') {
  25. acc[value] = key;
  26. } else {
  27. for (const v of value) {
  28. acc[v] = key;
  29. }
  30. }
  31. return acc;
  32. }, {})
  33. );
  34. export const TTSWorker = writable(null);
  35. export const chatId = writable('');
  36. export const chatTitle = writable('');
  37. export const channels = writable([]);
  38. export const chats = writable([]);
  39. export const pinnedChats = writable([]);
  40. export const tags = writable([]);
  41. export const models: Writable<Model[]> = writable([]);
  42. export const prompts: Writable<null | Prompt[]> = writable(null);
  43. export const knowledge: Writable<null | Document[]> = writable(null);
  44. export const tools = writable(null);
  45. export const functions = writable(null);
  46. export const banners: Writable<Banner[]> = writable([]);
  47. export const settings: Writable<Settings> = writable({});
  48. export const showSidebar = writable(false);
  49. export const showSettings = writable(false);
  50. export const showArchivedChats = writable(false);
  51. export const showChangelog = writable(false);
  52. export const showControls = writable(false);
  53. export const showOverview = writable(false);
  54. export const showArtifacts = writable(false);
  55. export const showCallOverlay = writable(false);
  56. export const temporaryChatEnabled = writable(false);
  57. export const scrollPaginationEnabled = writable(false);
  58. export const currentChatPage = writable(1);
  59. export const isLastActiveTab = writable(true);
  60. export const playingNotificationSound = writable(false);
  61. export type Model = OpenAIModel | OllamaModel;
  62. type BaseModel = {
  63. id: string;
  64. name: string;
  65. info?: ModelConfig;
  66. owned_by: 'ollama' | 'openai' | 'arena';
  67. };
  68. export interface OpenAIModel extends BaseModel {
  69. owned_by: 'openai';
  70. external: boolean;
  71. source?: string;
  72. }
  73. export interface OllamaModel extends BaseModel {
  74. owned_by: 'ollama';
  75. details: OllamaModelDetails;
  76. size: number;
  77. description: string;
  78. model: string;
  79. modified_at: string;
  80. digest: string;
  81. ollama?: {
  82. name?: string;
  83. model?: string;
  84. modified_at: string;
  85. size?: number;
  86. digest?: string;
  87. details?: {
  88. parent_model?: string;
  89. format?: string;
  90. family?: string;
  91. families?: string[];
  92. parameter_size?: string;
  93. quantization_level?: string;
  94. };
  95. urls?: number[];
  96. };
  97. }
  98. type OllamaModelDetails = {
  99. parent_model: string;
  100. format: string;
  101. family: string;
  102. families: string[] | null;
  103. parameter_size: string;
  104. quantization_level: string;
  105. };
  106. type Settings = {
  107. models?: string[];
  108. conversationMode?: boolean;
  109. speechAutoSend?: boolean;
  110. responseAutoPlayback?: boolean;
  111. audio?: AudioSettings;
  112. showUsername?: boolean;
  113. notificationEnabled?: boolean;
  114. title?: TitleSettings;
  115. splitLargeDeltas?: boolean;
  116. chatDirection: 'LTR' | 'RTL';
  117. system?: string;
  118. requestFormat?: string;
  119. keepAlive?: string;
  120. seed?: number;
  121. temperature?: string;
  122. repeat_penalty?: string;
  123. top_k?: string;
  124. top_p?: string;
  125. num_ctx?: string;
  126. num_batch?: string;
  127. num_keep?: string;
  128. options?: ModelOptions;
  129. };
  130. type ModelOptions = {
  131. stop?: boolean;
  132. };
  133. type AudioSettings = {
  134. STTEngine?: string;
  135. TTSEngine?: string;
  136. speaker?: string;
  137. model?: string;
  138. nonLocalVoices?: boolean;
  139. };
  140. type TitleSettings = {
  141. auto?: boolean;
  142. model?: string;
  143. modelExternal?: string;
  144. prompt?: string;
  145. };
  146. type Prompt = {
  147. command: string;
  148. user_id: string;
  149. title: string;
  150. content: string;
  151. timestamp: number;
  152. };
  153. type Document = {
  154. collection_name: string;
  155. filename: string;
  156. name: string;
  157. title: string;
  158. };
  159. type Config = {
  160. status: boolean;
  161. name: string;
  162. version: string;
  163. default_locale: string;
  164. default_models: string;
  165. default_prompt_suggestions: PromptSuggestion[];
  166. features: {
  167. auth: boolean;
  168. auth_trusted_header: boolean;
  169. enable_api_key: boolean;
  170. enable_signup: boolean;
  171. enable_login_form: boolean;
  172. enable_web_search?: boolean;
  173. enable_google_drive_integration: boolean;
  174. enable_image_generation: boolean;
  175. enable_admin_export: boolean;
  176. enable_admin_chat_access: boolean;
  177. enable_community_sharing: boolean;
  178. enable_autocomplete_generation: boolean;
  179. };
  180. oauth: {
  181. providers: {
  182. [key: string]: string;
  183. };
  184. };
  185. };
  186. type PromptSuggestion = {
  187. content: string;
  188. title: [string, string];
  189. };
  190. type SessionUser = {
  191. id: string;
  192. email: string;
  193. name: string;
  194. role: string;
  195. profile_image_url: string;
  196. };