Coverage for open_webui/constants.py: 99%

93 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 05:07 +0000

1from __future__ import annotations 

2 

3import errno 

4from enum import Enum 

5 

6_ERRNO_MESSAGES = { 

7 errno.ENAMETOOLONG: 'File name is too long.', 

8 errno.ENOSPC: 'The server is out of storage space.', 

9 errno.EDQUOT: 'Server storage quota exceeded.', 

10 errno.EACCES: 'Server storage is not writable.', 

11 errno.EPERM: 'Server storage is not writable.', 

12 errno.EROFS: 'Server storage is not writable.', 

13} 

14 

15 

16def _error_message(err='', fallback='') -> str: 

17 if not err: 

18 return 'Something went wrong :/' 

19 if isinstance(err, OSError) and err.errno in _ERRNO_MESSAGES: 

20 return f'[ERROR: {_ERRNO_MESSAGES[err.errno]}]' 

21 if isinstance(err, Exception): 

22 return f'[ERROR: {fallback}]' if fallback else 'Something went wrong :/' 

23 return f'[ERROR: {err}]' 

24 

25 

26class MESSAGES(str, Enum): 

27 DEFAULT = lambda msg='': f'{msg if msg else ""}' 

28 MODEL_ADDED = lambda model='': f"The model '{model}' has been added successfully." 

29 MODEL_DELETED = lambda model='': f"The model '{model}' has been deleted successfully." 

30 

31 

32class WEBHOOK_MESSAGES(str, Enum): 

33 DEFAULT = lambda msg='': f'{msg if msg else ""}' 

34 USER_SIGNUP = lambda username='': f'New user signed up: {username}' if username else 'New user signed up' 

35 

36 

37class ERROR_MESSAGES(str, Enum): 

38 def __str__(self) -> str: 

39 return super().__str__() 

40 

41 DEFAULT = _error_message 

42 ENV_VAR_NOT_FOUND = 'Required environment variable not found. Terminating now.' 

43 CREATE_USER_ERROR = 'Oops! Something went wrong while creating your account. Please try again later. If the issue persists, contact support for assistance.' 

44 DELETE_USER_ERROR = 'Oops! Something went wrong. We encountered an issue while trying to delete the user. Please give it another shot.' 

45 EMAIL_MISMATCH = 'Uh-oh! This email does not match the email your provider is registered with. Please check your email and try again.' 

46 EMAIL_TAKEN = 'Uh-oh! This email is already registered. Sign in with your existing account or choose another email to start anew.' 

47 USERNAME_TAKEN = 'Uh-oh! This username is already registered. Please choose another username.' 

48 PASSWORD_TOO_LONG = ( 

49 'Uh-oh! The password you entered is too long. Please make sure your password is less than 72 bytes long.' 

50 ) 

51 COMMAND_TAKEN = 'Uh-oh! This command is already registered. Please choose another command string.' 

52 FILE_EXISTS = 'Uh-oh! This file is already registered. Please choose another file.' 

53 

54 ID_TAKEN = 'Uh-oh! This id is already registered. Please choose another id string.' 

55 MODEL_ID_TAKEN = 'Uh-oh! This model id is already registered. Please choose another model id string.' 

56 NAME_TAG_TAKEN = 'Uh-oh! This name tag is already registered. Please choose another name tag string.' 

57 MODEL_ID_TOO_LONG = 'The model id is too long. Please make sure your model id is less than 256 characters long.' 

58 

59 INVALID_TOKEN = 'Your session has expired or the token is invalid. Please sign in again.' 

60 INVALID_CRED = 'The email or password provided is incorrect. Please check for typos and try logging in again.' 

61 INVALID_EMAIL_FORMAT = "The email format you entered is invalid. Please double-check and make sure you're using a valid email address (e.g., yourname@example.com)." 

62 INCORRECT_PASSWORD = 'The password provided is incorrect. Please check for typos and try again.' 

63 INVALID_TRUSTED_HEADER = ( 

64 'Your provider has not provided a trusted header. Please contact your administrator for assistance.' 

65 ) 

66 

67 EXISTING_USERS = "You can't turn off authentication because there are existing users. If you want to disable WEBUI_AUTH, make sure your web interface doesn't have any existing users and is a fresh installation." 

68 

69 UNAUTHORIZED = '401 Unauthorized' 

70 ACCESS_PROHIBITED = ( 

71 'You do not have permission to access this resource. Please contact your administrator for assistance.' 

72 ) 

73 ACTION_PROHIBITED = 'The requested action has been restricted as a security measure.' 

74 

75 FILE_NOT_SENT = 'FILE_NOT_SENT' 

76 FILE_NOT_SUPPORTED = "Oops! It seems like the file format you're trying to upload is not supported. Please upload a file with a supported format and try again." 

77 

78 NOT_FOUND = "We could not find what you're looking for :/" 

79 USER_NOT_FOUND = "We could not find what you're looking for :/" 

80 API_KEY_NOT_FOUND = "Oops! It looks like there's a hiccup. The API key is missing. Please make sure to provide a valid API key to access this feature." 

81 API_KEY_NOT_ALLOWED = 'Use of API key is not enabled in the environment.' 

82 

83 MALICIOUS = 'Unusual activities detected, please try again in a few minutes.' 

84 

85 PANDOC_NOT_INSTALLED = 'Pandoc is not installed on the server. Please contact your administrator for assistance.' 

86 INCORRECT_FORMAT = lambda err='': f'Invalid format. Please use the correct format{err}' 

87 RATE_LIMIT_EXCEEDED = 'API rate limit exceeded' 

88 

89 MODEL_NOT_FOUND = lambda name='': f"Model '{name}' was not found" 

90 OPENAI_NOT_FOUND = lambda name='': 'OpenAI API was not found' 

91 OLLAMA_NOT_FOUND = 'WebUI could not connect to Ollama' 

92 CREATE_API_KEY_ERROR = 'Oops! Something went wrong while creating your API key. Please try again later. If the issue persists, contact support for assistance.' 

93 API_KEY_CREATION_NOT_ALLOWED = 'API key creation is not allowed in the environment.' 

94 

95 EMPTY_CONTENT = 'The content provided is empty. Please ensure that there is text or data present before proceeding.' 

96 

97 DB_NOT_SQLITE = 'This feature is only available with SQLite databases.' 

98 

99 INVALID_URL = 'The URL you provided is invalid. Please double-check and try again.' 

100 

101 WEB_SEARCH_ERROR = 'Something went wrong while searching the web.' 

102 

103 OLLAMA_API_DISABLED = 'The Ollama API is disabled. Please enable it to use this feature.' 

104 

105 FILE_TOO_LARGE = lambda size='': ( 

106 f"Oops! The file you're trying to upload is too large. Please upload a file that is less than {size}." 

107 ) 

108 

109 DUPLICATE_CONTENT = 'Duplicate content detected. Please provide unique content to proceed.' 

110 FILE_NOT_PROCESSED = ( 

111 'Extracted content is not available for this file. Please ensure that the file is processed before proceeding.' 

112 ) 

113 

114 INVALID_PASSWORD = lambda err='': err if err else 'The password does not meet the required validation criteria.' 

115 

116 AUTOMATION_LIMIT_EXCEEDED = lambda size='': f'Automation limit reached ({size})' 

117 AUTOMATION_TOO_FREQUENT = lambda interval='': f'Schedule too frequent. Minimum interval is {interval} seconds.' 

118 AUTOMATION_INVALID_RRULE = lambda err='': f'Invalid RRULE: {err}' 

119 AUTOMATION_NO_FUTURE_RUNS = 'RRULE has no future occurrences' 

120 AUTOMATION_COUNT_REQUIRES_DTSTART = ( 

121 'RRULE with COUNT requires an explicit DTSTART line to anchor the occurrence window' 

122 ) 

123 CALENDAR_RRULE_TOO_FREQUENT = 'Recurring events cannot repeat more often than daily' 

124 

125 FEATURE_DISABLED = lambda name='': f'{name} is disabled' 

126 INPUT_TOO_LONG = lambda size='': f'Input prompt exceeds maximum length of {size}' 

127 # LICENSE covers this Open WebUI error identifier. 

128 # Do not alter, remove, obscure, or replace it except as LICENSE permits: 

129 # https://docs.openwebui.com/license. 

130 SERVER_CONNECTION_ERROR = 'Open WebUI: Server Connection Error' 

131 REQUIRED_FIELD_EMPTY = lambda name='': f'Required field {name} is empty' 

132 OAUTH_NOT_CONFIGURED = lambda name='': f"Provider '{name}' is not configured" 

133 

134 

135class TASKS(str, Enum): 

136 def __str__(self) -> str: 

137 return super().__str__() 

138 

139 DEFAULT = lambda task='': f'{task if task else "generation"}' 

140 TITLE_GENERATION = 'title_generation' 

141 FOLLOW_UP_GENERATION = 'follow_up_generation' 

142 TAGS_GENERATION = 'tags_generation' 

143 EMOJI_GENERATION = 'emoji_generation' 

144 QUERY_GENERATION = 'query_generation' 

145 IMAGE_PROMPT_GENERATION = 'image_prompt_generation' 

146 AUTOCOMPLETE_GENERATION = 'autocomplete_generation' 

147 FUNCTION_CALLING = 'function_calling' 

148 MOA_RESPONSE_GENERATION = 'moa_response_generation'