MCPcopy Create free account
hub / github.com/CodeGoat24/UniGenBench / call_evaluation_gemini

Function call_evaluation_gemini

eval/src/eval_common.py:277–330  ·  view source on GitHub ↗

Evaluate a single image using Gemini API via OpenAI-compatible client.

(task)

Source from the content-addressed store, hash-verified

275# ============================================================
276
277def call_evaluation_gemini(task):
278 """Evaluate a single image using Gemini API via OpenAI-compatible client."""
279 from openai import OpenAI
280
281 index = task["index"]
282 prompt = task["prompt"]
283 testpoint = task["testpoint"]
284 test_desc = task["test_desc"]
285 img_path = task["img_path"]
286 lang = task["lang"]
287 max_retries = task["max_retries"]
288 api_key = task["api_key"]
289 base_url = task["base_url"]
290 model_name = task.get("model_name", "gemini-2.5-pro")
291
292 system_prompt = build_system_prompt(prompt, testpoint, test_desc, lang)
293 base64_image = local_image_to_data_url(img_path)
294 client = OpenAI(api_key=api_key, base_url=base_url)
295
296 text = None
297 for attempt in range(max_retries + 1):
298 try:
299 response = client.chat.completions.create(
300 model=model_name,
301 messages=[{
302 "role": "user",
303 "content": [
304 {"type": "text", "text": system_prompt},
305 {"type": "image_url", "image_url": {"url": base64_image}},
306 ],
307 }],
308 max_tokens=4096,
309 )
310 text = response.choices[0].message.content
311 except Exception as e:
312 print(f"Gemini API error (attempt {attempt + 1}/{max_retries + 1}): {e}")
313 text = None
314
315 if text is None:
316 continue
317
318 parsed = parse_evaluation_response(text, testpoint)
319 if parsed is not None:
320 analysis, score = parsed
321 result_json = {
322 "prompt": prompt,
323 "testpoint": testpoint,
324 "analysis": analysis,
325 "score": score,
326 }
327 return make_result(index, testpoint, prompt, img_path, text, result_json)
328
329 # All retries exhausted
330 return make_result(index, testpoint, prompt, img_path, text)
331
332
333# ============================================================

Callers

nothing calls this directly

Calls 4

build_system_promptFunction · 0.85
local_image_to_data_urlFunction · 0.85
make_resultFunction · 0.85

Tested by

no test coverage detected