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

Method process_item

eval/src/vllm_request.py:100–165  ·  view source on GitHub ↗
(self, item, image_root)

Source from the content-addressed store, hash-verified

98 ]
99
100 def process_item(self, item, image_root):
101 attempt = 0
102 result = None
103 start_time = time.monotonic()
104
105 while attempt < self.max_retries:
106 try:
107 attempt += 1
108 session = self._get_session()
109 raw_messages = self.build_messages(item, image_root)
110
111 payload = {
112 "model": "QwenVL",
113 "messages": raw_messages,
114 "do_sample": False,
115 "max_tokens": 4096,
116 }
117
118 response = session.post(
119 f"{self.api_url}/v1/chat/completions",
120 json=payload,
121 timeout=self.timeout_base + attempt * 5,
122 )
123 if response.status_code in {429, 500, 502, 503, 504}:
124 raise requests.HTTPError(
125 f"Retryable HTTP {response.status_code}",
126 response=response,
127 )
128 response.raise_for_status()
129
130 output = response.json()["choices"][0]["message"]["content"]
131
132 item["model_output"] = output
133 item["success"] = True
134 result = item
135
136 break
137
138 except Exception as e:
139 if attempt == self.max_retries:
140 print(f"请求失败(已达最大重试次数): {str(e)}")
141 result = {
142 "idx": item.get("idx"),
143 "question": item["problem"],
144 "image_path": item.get("images", []),
145 "error": str(e),
146 "attempt": attempt,
147 "success": False
148 }
149 else:
150 sleep_time = min(
151 self.backoff_base ** attempt + random.uniform(0, 1),
152 self.backoff_cap,
153 )
154 time.sleep(sleep_time)
155 if result is None:
156 result = {
157 "idx": item.get("idx"),

Callers

nothing calls this directly

Calls 2

_get_sessionMethod · 0.95
build_messagesMethod · 0.95

Tested by

no test coverage detected