index.ts 3.6 KB

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