feat: complete local version to overwrite remote

This commit is contained in:
DelLevin-Home
2026-06-16 03:30:57 +08:00
parent 1735c19f48
commit 3c78293f4d
129 changed files with 22814 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
"""
分词接口调用示例
"""
import requests
import json
BASE_URL = "http://127.0.0.1:27056"
# BASE_URL = "http://fenci.iletter.top/"
def tokenize_single(text):
"""单文本分词"""
url = f"{BASE_URL}/tokenize"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer DdzBgb8GEkBpA8gtCJXP24hGJz9bXpEOi6z91fHm25X59q5968XqtLxPi1MfiTHJ"
}
payload = {"input_text": text}
response = requests.post(url, headers=headers, json=payload)
print(response.json())
return response.json()
def tokenize_batch(texts):
"""批量分词"""
url = f"{BASE_URL}/batch-tokenize"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer DdzBgb8GEkBpA8gtCJXP24hGJz9bXpEOi6z91fHm25X59q5968XqtLxPi1MfiTHJ"
}
payload = {"texts": texts}
response = requests.post(url, headers=headers, json=payload)
return response.json()
if __name__ == "__main__":
# 示例 1: 单文本分词
print("=" * 50)
print("示例 1: 单文本分词")
print("=" * 50)
text = "MemoFlowMookNoteVoceChat"
result = tokenize_single(text)
if result["success"]:
print(f"原文: {result['original_text']}")
print(f"\n分词结果:")
for token in result["tokens"]:
print(f" [{token['type']:12}] {token['text']}")
print(f"\n统计信息:")
stats = result["stats"]
print(f" 总计: {stats['total']} 个单词")
print(f" 中文: {stats['chinese']}")
print(f" 英文: {stats['english']}")
print(f" 数字: {stats['number']}")
print(f" 标点: {stats['punctuation']}")
else:
print(f"错误: {result['error']}")