Files
python_script/根据文章内容生成标签/main.py
DelLevin-Home af250800d6 首次提交
2026-01-15 14:20:44 +08:00

37 lines
980 B
Python

import extract_doc_tag as ex_doc_tag
# --- 方式一:指定文件路径 ---
file_path = 'test.txt'
try:
with open(file_path, 'r', encoding='utf-8') as file:
my_article_content = file.read()
except FileNotFoundError:
print(f"错误:找不到文件 '{file_path}'")
exit(1)
except Exception as e:
print(f"读取文件时发生错误: {e}")
exit(1)
model = "qwen3:1.7b"
extracted_tags = ex_doc_tag.extract_tags_with_ollama_from_content(
model,
my_article_content,
max_tags=8,
min_length=2,
max_length=6
)
if extracted_tags['code'] == 0:
print('思考过程:')
print(extracted_tags['data']['think'])
print('=' * 60)
print('文章内容长度', len(my_article_content))
# print(f"Ollama 模型:{model}")
print('=' * 60)
print('文章标签:', extracted_tags['data']['tags'])
print('=' * 60)
print(f"总耗时: {extracted_tags['data']['consume']:.2f}")
else:
print(extracted_tags)