Timothy J. Baek пре 10 месеци
родитељ
комит
8dac2a2140
2 измењених фајлова са 48 додато и 2 уклоњено
  1. 5 2
      backend/config.py
  2. 43 0
      src/lib/utils/index.ts

+ 5 - 2
backend/config.py

@@ -569,12 +569,15 @@ OLLAMA_API_BASE_URL = os.environ.get(
 )
 )
 
 
 OLLAMA_BASE_URL = os.environ.get("OLLAMA_BASE_URL", "")
 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 == "":
 if AIOHTTP_CLIENT_TIMEOUT == "":
     AIOHTTP_CLIENT_TIMEOUT = None
     AIOHTTP_CLIENT_TIMEOUT = None
 else:
 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", "")
 K8S_FLAG = os.environ.get("K8S_FLAG", "")

+ 43 - 0
src/lib/utils/index.ts

@@ -703,3 +703,46 @@ export const getTimeRange = (timestamp) => {
 		return date.getFullYear().toString();
 		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;
+};