|
28 | 28 | # pylint: disable=line-too-long |
29 | 29 |
|
30 | 30 | # English Prompt |
31 | | -IMAGE_HELPFULNESS_PROMPT_EN = """ |
| 31 | +IMAGE_HELPFULNESS_PROMPT_EN = textwrap.dedent( |
| 32 | + """ |
32 | 33 | # Task Description |
33 | 34 | You are a multi-modal document evaluation assistant. You will receive an image and its textual context. |
34 | 35 | Your task is to evaluate the helpfulness of the image in enabling human readers to comprehend the text (context above and below) it accompanies. |
|
63 | 64 | # Image |
64 | 65 | [Insert Image Here] |
65 | 66 | """ |
| 67 | +).strip() |
66 | 68 |
|
67 | 69 | # Chinese Prompt |
68 | | -IMAGE_HELPFULNESS_PROMPT_ZH = """ |
| 70 | +IMAGE_HELPFULNESS_PROMPT_ZH = textwrap.dedent( |
| 71 | + """ |
69 | 72 | # 任务描述 |
70 | 73 | 你是一名多模态文档评估助手。你将收到一张图片及其文本背景。 |
71 | 74 | 你的任务是评估图片对于帮助人类读者理解其伴随文本(上下文)的有用性。 |
|
100 | 103 | # 图片 |
101 | 104 | [在此插入图片] |
102 | 105 | """ |
| 106 | +).strip() |
103 | 107 |
|
104 | 108 | # Build default template from prompts |
105 | 109 | DEFAULT_IMAGE_HELPFULNESS_TEMPLATE = PromptTemplate( |
106 | 110 | messages={ |
107 | 111 | LanguageEnum.EN: [ |
108 | 112 | ChatMessage( |
109 | 113 | role="user", |
110 | | - content=textwrap.dedent(IMAGE_HELPFULNESS_PROMPT_EN), |
| 114 | + content=IMAGE_HELPFULNESS_PROMPT_EN, |
111 | 115 | ), |
112 | 116 | ], |
113 | 117 | LanguageEnum.ZH: [ |
114 | 118 | ChatMessage( |
115 | 119 | role="user", |
116 | | - content=textwrap.dedent(IMAGE_HELPFULNESS_PROMPT_ZH), |
| 120 | + content=IMAGE_HELPFULNESS_PROMPT_ZH, |
117 | 121 | ), |
118 | 122 | ], |
119 | 123 | }, |
@@ -161,13 +165,14 @@ class ImageHelpfulnessGrader(LLMGrader): |
161 | 165 | GraderScore with normalized helpfulness score [0, 1] |
162 | 166 |
|
163 | 167 | Example: |
| 168 | + >>> import asyncio |
164 | 169 | >>> from openjudge.model.openai_llm import OpenAIChatModel |
165 | 170 | >>> from openjudge.multimodal import ImageHelpfulnessGrader, MLLMImage |
166 | 171 | >>> |
167 | 172 | >>> model = OpenAIChatModel(api_key="sk-...", model="qwen3-max") |
168 | 173 | >>> grader = ImageHelpfulnessGrader(model=model) |
169 | 174 | >>> |
170 | | - >>> result = await grader.aevaluate( |
| 175 | + >>> result = asyncio.run(grader.aevaluate( |
171 | 176 | ... response=[ |
172 | 177 | ... "The system architecture has three layers.", |
173 | 178 | ... MLLMImage(url="https://example.com/arch_diagram.jpg"), |
@@ -200,7 +205,7 @@ def __init__( |
200 | 205 | mode=GraderMode.POINTWISE, |
201 | 206 | description="Evaluate image helpfulness for understanding text", |
202 | 207 | model=model, |
203 | | - template=template, |
| 208 | + template=template or DEFAULT_IMAGE_HELPFULNESS_TEMPLATE, |
204 | 209 | language=language, |
205 | 210 | ) |
206 | 211 | self.max_context_size = max_context_size |
@@ -362,4 +367,4 @@ async def aevaluate( |
362 | 367 | ) |
363 | 368 |
|
364 | 369 |
|
365 | | -__all__ = ["ImageHelpfulnessGrader"] |
| 370 | +__all__ = ["ImageHelpfulnessGrader", "DEFAULT_IMAGE_HELPFULNESS_TEMPLATE"] |
0 commit comments