增加多模态模型识别功能。
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
|
||||
def build_closedset_prompt(
|
||||
labels: List[str],
|
||||
fewshot_hints: Optional[Dict[str, str]] = None,
|
||||
ingredient_only: bool = False,
|
||||
) -> str:
|
||||
label_str = ",".join(labels)
|
||||
|
||||
hint_lines: List[str] = []
|
||||
if fewshot_hints:
|
||||
hint_lines.append("以下是少量文字示例帮助你区分:")
|
||||
for k, v in list(fewshot_hints.items())[:20]:
|
||||
hint_lines.append(f"- {k}:{v}")
|
||||
hints = "\n".join(hint_lines)
|
||||
|
||||
constraint = (
|
||||
"你只需输出食材名称,不要包含任何烹饪方式或形态描述(如切丝/切片/炒/煮/红烧/清炒等)。\n"
|
||||
if ingredient_only
|
||||
else ""
|
||||
)
|
||||
|
||||
return (
|
||||
"你是食品图像分类专家。请严格在给定的标签集合中选择最符合图片内容的一个标签。\n"
|
||||
"只允许返回一个标签,禁止输出集合外的词。请同时给出0-1置信度。\n"
|
||||
f"{constraint}"
|
||||
f"标签集合(封闭集,中文):{label_str}\n"
|
||||
f"{hints}\n"
|
||||
'请仅输出合法 JSON:{"label":"<标签>","confidence":0-1}\n'
|
||||
"不要输出任何额外解释或文本。"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user