This commit is contained in:
Timothy J. Baek 2024-06-26 10:22:31 -07:00
parent aad23af3a3
commit 8dac2a2140
2 changed files with 48 additions and 2 deletions

View File

@ -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", "")

View File

@ -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;
};