尧图网络 高端网站定制 · 原创设计
免费咨询热线
400-888-6620
免费获取方案
文本分类模型
# !/usr/bin/env python3 import argparse import asyncio import json import os import random import time from datetime import datetime from pathlib import Path import httpx from openai import AsyncOpenAI # 配置 # LLM_BASE_URL os.getenv(LLM_BASE_URL) # LLM_MODEL os.getenv(LLM_MODEL) LLM_API_KEY os.getenv(LLM_API_KEY) or empty LLM_TIMEOUT float(os.getenv(LLM_TIMEOUT, 30)) # 对象种类 CATEGORIES [徽章, 戒指, 动物, 人物, 其他] CATEGORIES_STR 、.join(CATEGORIES) SYSTEM_PROMPT f你是一个文本分类专家。根据给定的文生图提示词判断主要对象的种类。 可选种类{CATEGORIES_STR} 严格只输出一个词不要解释。 async def classify(text: str) - str: 分类提示词 if not text.strip(): return client AsyncOpenAI(api_keyLLM_API_KEY, base_urlLLM_BASE_URL, http_clienthttpx.AsyncClient(timeoutLLM_TIMEOUT), ) try: resp await client.chat.completions.create(modelLLM_MODEL, messages[{role: system, content: SYSTEM_PROMPT}, {role: user, content: text.strip()}, ], temperature0.1, max_tokens20, ) result resp.choices[0].message.content.strip() # 提取第一个词 for cat in CATEGORIES: if cat in result: return cat return result finally: await client.close() async def main(): parser argparse.ArgumentParser() parser.add_argument(--output, typePath, defaultNone) parser.add_argument(--seed, typeint, defaultNone) args parser.parse_args() test_prompts [ # 人物 A single 3D designer art toy figure, presented in a strict horizontal triptych layout with left side view, middle front view, and right rear view. Strictly limited to a palette of exactly 4 pure colors: 1. Pure white for the head, gloves, and boots; 2. Dark ultramarine blue for the torso, arms, and legs; 3. Crimson red for the flowing cape; 4. Silver-grey for the facial mask details and chest logo., # 徽章 A beautifully crafted enamel pin badge, featuring a detailed dragon design in gold and red colors, with subtle metallic sheen, professional product photography, white background, high resolution, studio lighting., # 戒指 A stunning platinum engagement ring with a 2-carat diamond center stone, surrounded by smaller pavé-set diamonds, intricate filigree details on the band, elegant jewelry photography, soft natural lighting, macro shot, 8K., # 动物 A majestic golden eagle soaring through the sky with wings fully extended, dramatic sunset background, sharp focus on feathers, hyper-realistic wildlife photography, National Geographic style, 8K, cinematic composition., # 其他 A futuristic skyscraper with a sleek glass facade, reflecting the surrounding cityscape, dramatic night lighting, long exposure photography, architectural marvel, modern minimalist design, high resolution, 8K., # 其他 A delicious gourmet burger on a wooden table, perfectly chargrilled beef patty, melted cheddar cheese, crispy bacon, fresh lettuce and tomato, steam rising, warm ambient lighting, food photography, shallow depth of field, 8K, mouth-watering., ] results [] # 逐个测试 for i, prompt in enumerate(test_prompts, 1): total_start time.time() predicted await classify(prompt) results.append({predicted: predicted}) print(f{i} {predicted} {time.time() - total_start:.2f}) if __name__ __main__: asyncio.run(main())
RELATED

相关推荐

NLP 模型评测与多任务性能对比:发布前检查失败路径与回滚

NLP 模型评测与多任务性能对比:发布前检查失败路径与回滚

NLP 模型评测与多任务性能对比:发布前检查失败路径与回滚 1. 离线高分:先排除训练集与评测集重叠 评测结果异常升高时,应先检查训练集、验证集和测试集的来源、版本与文本重叠。可在公开或合成语料上使用 N-gram 或 MinHash 检测,…

📅 2026/9/1 14:57:29
2025届必备的AI辅助论文平台横评

2025届必备的AI辅助论文平台横评

Ai论文网站排名(开题报告、文献综述、降aigc率、降重综合对比) TOP1. 千笔AI TOP2. aipasspaper TOP3. 清北论文 TOP4. 豆包 TOP5. kimi TOP6. deepseek 正变得越来越受众多学生青睐的, 能用来撰写学术文章的免费AI论文工具, 因人工智能迅速发展,…

📅 2026/9/15 14:30:13
喜马拉雅FM下载器:跨平台音频保存解决方案

喜马拉雅FM下载器:跨平台音频保存解决方案

喜马拉雅FM下载器:跨平台音频保存解决方案 【免费下载链接】xmly-downloader-qt5 喜马拉雅FM专辑下载器. 支持VIP与付费专辑. 使用GoQt5编写(Not Qt Binding). 项目地址: https://gitcode.com/gh_mirrors/xm/xmly-downloader-qt5 还在为喜马拉雅VIP到期后无法…

📅 2026/8/23 14:47:23
MORE NEWS

更多资讯

📰

本地优先开源AI角色扮演工具Utopia:从Ollama到角色卡的完整实践

如果你在找一个“不绑大厂、本地优先”的开源AI角色扮演工具,我这一个月写的 Utopia 可能正好对得上号。事情起因很简单:我一个朋友想找个能陪他聊虚拟角色的工具,但他不想注册大厂账号、不想按月付费、不想把对话记录留在云端,还…

📰

Java中的length:数组属性、String方法与集合size的底层原理

1. 一道 Java 面试题把我问懵之后,我把 length 彻底研究了一遍先说个场景。面试官随手在白板上写了两行代码,一行int[] arr new int[10]; arr.length;,一行String s "hello"; s.length();,问我有什么区别。我很快答出…

📰

Ego-Planner实战:解决无人机撞树问题的避障指南

室外飞无人机,我最怕的不是炸机,是撞树。尤其多旋翼在树林、果园或者园区绿地里穿行,树冠、细枝、电线杆,随便来一下就是螺旋桨报废、电机堵转,运气差一点整机直接摔。很多朋友第一反应是“避障没做好”,但…

📰

从零构建本地AI角色扮演工具:Ollama+FastAPI+Vue实战

上个月有个周五晚上,朋友发来一条语音,语气比白天开会时精神多了:“能不能帮我弄一个能自己在电脑上跑的AI角色扮演工具?”我第一反应是,这不是现成一堆开源项目么,去GitHub上拉一个就行。结果她把需求一条…

📰

Jetson Orin NX串口读取GNSS模块:NMEA解析与RTK定位实战

做室外机器人定位这件事,绕不开GNSS。我最近在Jetson Orin NX 16GB上接了一个联适R70M-GNSS模块,目标很明确:用串口把高精度定位数据读出来,并解析成程序能直接用的经纬度和状态信息。这套组合不是什么高深技术,但正因…

📰

ADS AEL参数化设计:磁性元件建模与自动化实现

1. 这不是“写个脚本”那么简单:为什么参数化电感与变压器设计是ADS用户真正的分水岭在ADS(Advanced Design System)里写AEL(ADS Expression Language)脚本,很多人停留在“把S参数读出来画个图”或者“循环…

TODAY

今日更新

THIS WEEK

本周精选

THIS MONTH

本月热门

读完文章,想聊聊您的网站?

告诉我们您的行业与需求,资深顾问一对一梳理方案与报价,全程免费。

📞 💬