Refactor process_tags

This commit is contained in:
Oleksandr Kozachuk
2023-04-07 17:56:02 +02:00
parent b23a9f663f
commit 4ee777118d
4 changed files with 41 additions and 30 deletions
+15
View File
@@ -55,3 +55,18 @@ def create_chat(question: Optional[str],
if question:
append_message(chat, 'user', question)
return chat
def get_tags(config: Dict[str, Any], prefix: Optional[str]) -> List[str]:
result = []
for file in sorted(pathlib.Path(config['db']).iterdir()):
if file.suffix == '.yaml':
with open(file, 'r') as f:
data = yaml.load(f, Loader=yaml.FullLoader)
for tag in data.get('tags', []):
if prefix and len(prefix) > 0:
if tag.startswith(prefix):
result.append(tag)
else:
result.append(tag)
return list(set(result))