Files
DelLevin-Home f1b9f6a1d0 222
2026-01-30 22:43:35 +08:00

41 lines
1.1 KiB
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"
# model = "qwen3:0.6b"
# OLLAMA_BASE_URL = "http://127.0.0.1:11434/api/generate"
OLLAMA_BASE_URL = "http://152.136.153.72:27009/api/generate"
extracted_tags = ex_doc_tag.extract_tags_with_ollama_from_content(
OLLAMA_BASE_URL,
model,
my_article_content,
max_tags=5,
min_length=2,
max_length=10
)
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)