-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path_utils.py
More file actions
28 lines (23 loc) · 985 Bytes
/
_utils.py
File metadata and controls
28 lines (23 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Tencent is pleased to support the open source community by making tRPC-Agent-Python available.
#
# Copyright (C) 2026 Tencent. All rights reserved.
#
# tRPC-Agent-Python is licensed under Apache-2.0.
"""Utility functions for memory service."""
import re
from datetime import datetime
def format_timestamp(timestamp: float) -> str:
"""Format the timestamp of the memory entry."""
return datetime.fromtimestamp(timestamp).isoformat()
def extract_words_lower(text: str) -> set[str]:
"""Extract words from a string and convert them to lowercase.
Extracts both English words and Chinese characters.
For English: extracts words (sequences of letters)
For Chinese: extracts individual characters (Unicode range \u4e00-\u9fff)
"""
words = set()
# Extract English words
words.update([word.lower() for word in re.findall(r'[A-Za-z]+', text)])
# Extract Chinese characters
words.update(re.findall(r'[\u4e00-\u9fff]', text))
return words