ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
import re
|
||||
|
||||
def parse(line: str) -> dict | None:
|
||||
# 定义日志格式的正则表达式模式
|
||||
pattern = r'^\[(?P<timestamp>[^\]]+)\]\s*\((?P<level>[^)]+)\)\s*<tool=(?P<tool>[^>]+)>\s*\{latency_ms=(?P<latency_ms>\d+)\s+status=(?P<status>\w+)\}\s*::\s*(?P<message>.*)$'
|
||||
|
||||
# 尝试匹配日志行
|
||||
match = re.match(pattern, line.strip())
|
||||
if not match:
|
||||
return None
|
||||
|
||||
# 提取匹配的组
|
||||
groups = match.groupdict()
|
||||
|
||||
# 检查所有必需字段是否存在且不为空
|
||||
required_keys = ['timestamp', 'level', 'tool', 'latency_ms', 'status', 'message']
|
||||
for key in required_keys:
|
||||
if key not in groups or not groups[key]:
|
||||
return None
|
||||
|
||||
# 转换latency_ms为整数
|
||||
try:
|
||||
groups['latency_ms'] = int(groups['latency_ms'])
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
return groups
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import re
|
||||
|
||||
def parse(line: str) -> dict | None:
|
||||
# 定义匹配日志格式的正则表达式
|
||||
pattern = r'^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z)\|([A-Z]+)\|([\w.]+)\|step=(\d+)\|(.*)$'
|
||||
match = re.match(pattern, line.strip())
|
||||
|
||||
if not match:
|
||||
return None
|
||||
|
||||
# 提取各个字段
|
||||
timestamp = match.group(1)
|
||||
level = match.group(2)
|
||||
module = match.group(3)
|
||||
step = match.group(4)
|
||||
message = match.group(5)
|
||||
|
||||
# 确保所有必需字段都不为空
|
||||
if not all([timestamp, level, module, step, message]):
|
||||
return None
|
||||
|
||||
return {
|
||||
'timestamp': timestamp,
|
||||
'level': level,
|
||||
'module': module,
|
||||
'step': step,
|
||||
'message': message
|
||||
}
|
||||
Reference in New Issue
Block a user