# -*- coding: utf-8 -*- | |
import requests | |
from utils.operate_json import * | |
import logging | |
# Create a logger | |
logger = logging.getLogger(__name__) | |
# Set the logging level | |
logger.setLevel(logging.DEBUG) | |
# Create a file handler | |
file_handler = logging.FileHandler('my_app.log') | |
# Create a formatter | |
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
# Add the formatter to the handler | |
file_handler.setFormatter(formatter) | |
# Add the handler to the logger | |
logger.addHandler(file_handler) | |
# 命名实体识别 | |
def name_entity_recognition(text, model="qwen2:7b", url="http://localhost:11434/api/chat"): | |
logger.debug("name_entity_recognition(...) is called.") | |
data = { | |
"model": model, | |
"messages": [ | |
{ | |
"role": "user", | |
"content": "从接下来的文本必须按照类型:内容的格式必须输出所提取人物类型、上衣类型、下衣类型、帽子类型、袜子类型、鞋子类型、背包类型、配饰类型、动作类型、表情类型,注意若未提及则内容输出为None,人物类型只有男性、女性、儿童、群体、None" | |
}, | |
{ | |
"role": "user", | |
"content": text | |
} | |
], | |
"stream": False, | |
"temperature": 0.3 | |
} | |
responce = requests.post(url, json=data) | |
reply = responce.json()['message']['content'] | |
return reply | |
if __name__ == '__main__': | |
text = '这位小朋友身着白色T恤搭配棕色短裤,搭配白色袜子和灰色运动鞋,头戴黄色帽子,肩上挎着黑色包,手里还拿着一把伞,看起来准备好应对任何天气了呢!但是,这位小朋友的鞋子和袜子并不太搭配,灰色运动鞋和白色袜子有点不协调哦,稍微有点扣分。总体来说,搭配清爽舒适,颜色搭配也比较和谐,符合儿童时尚的要求。根据知识库的规则,考虑到服装设计、面料、搭配的角度,以及人物属性,这位小朋友的穿着可以给予7分。' | |
data = name_entity_recognition(text) | |
print(text_to_json(data)) | |