mirror of
https://github.com/open-webui/open-webui
synced 2025-01-18 08:40:58 +00:00
refac
This commit is contained in:
parent
aad23af3a3
commit
8dac2a2140
@ -569,12 +569,15 @@ OLLAMA_API_BASE_URL = os.environ.get(
|
||||
)
|
||||
|
||||
OLLAMA_BASE_URL = os.environ.get("OLLAMA_BASE_URL", "")
|
||||
AIOHTTP_CLIENT_TIMEOUT = os.environ.get("AIOHTTP_CLIENT_TIMEOUT", "300")
|
||||
AIOHTTP_CLIENT_TIMEOUT = os.environ.get("AIOHTTP_CLIENT_TIMEOUT", "")
|
||||
|
||||
if AIOHTTP_CLIENT_TIMEOUT == "":
|
||||
AIOHTTP_CLIENT_TIMEOUT = None
|
||||
else:
|
||||
AIOHTTP_CLIENT_TIMEOUT = int(AIOHTTP_CLIENT_TIMEOUT)
|
||||
try:
|
||||
AIOHTTP_CLIENT_TIMEOUT = int(AIOHTTP_CLIENT_TIMEOUT)
|
||||
except:
|
||||
AIOHTTP_CLIENT_TIMEOUT = 300
|
||||
|
||||
|
||||
K8S_FLAG = os.environ.get("K8S_FLAG", "")
|
||||
|
@ -703,3 +703,46 @@ export const getTimeRange = (timestamp) => {
|
||||
return date.getFullYear().toString();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Extract frontmatter as a dictionary from the specified content string.
|
||||
* @param content {string} - The content string with potential frontmatter.
|
||||
* @returns {Object} - The extracted frontmatter as a dictionary.
|
||||
*/
|
||||
export const extractFrontmatter = (content) => {
|
||||
const frontmatter = {};
|
||||
let frontmatterStarted = false;
|
||||
let frontmatterEnded = false;
|
||||
const frontmatterPattern = /^\s*([a-z_]+):\s*(.*)\s*$/i;
|
||||
|
||||
// Split content into lines
|
||||
const lines = content.split('\n');
|
||||
|
||||
// Check if the content starts with triple quotes
|
||||
if (lines[0].trim() !== '"""') {
|
||||
return {};
|
||||
}
|
||||
|
||||
frontmatterStarted = true;
|
||||
|
||||
for (let i = 1; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
|
||||
if (line.includes('"""')) {
|
||||
if (frontmatterStarted) {
|
||||
frontmatterEnded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (frontmatterStarted && !frontmatterEnded) {
|
||||
const match = frontmatterPattern.exec(line);
|
||||
if (match) {
|
||||
const [, key, value] = match;
|
||||
frontmatter[key.trim()] = value.trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return frontmatter;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user