MCPcopy
hub / github.com/algorithmicsuperintelligence/optillm / get_llm_response

Function get_llm_response

scripts/eval_imobench_answer.py:161–199  ·  view source on GitHub ↗

Get response from the LLM for a mathematical problem

(problem: str, model: str, client: OpenAI, extra_body: dict = None, timeout: int = 300)

Source from the content-addressed store, hash-verified

159
160
161def get_llm_response(problem: str, model: str, client: OpenAI, extra_body: dict = None, timeout: int = 300) -> Dict:
162 """
163 Get response from the LLM for a mathematical problem
164 """
165 try:
166 kwargs = {}
167 if extra_body:
168 kwargs["extra_body"] = extra_body
169
170 response = client.with_options(timeout=timeout).chat.completions.create(
171 model=model,
172 messages=[
173 {"role": "system", "content": SYSTEM_PROMPT},
174 {"role": "user", "content": problem}
175 ],
176 max_tokens=16000,
177 temperature=0.1,
178 **kwargs
179 )
180
181 solution_text = response.choices[0].message.content.strip()
182 reasoning_tokens = getattr(response.usage, 'reasoning_tokens', 0)
183 total_tokens = response.usage.total_tokens if hasattr(response.usage, 'total_tokens') else 0
184
185 return {
186 "solution": solution_text,
187 "reasoning_tokens": reasoning_tokens,
188 "total_tokens": total_tokens,
189 "success": True
190 }
191
192 except Exception as e:
193 logger.error(f"Error getting LLM response: {e}")
194 return {
195 "solution": f"Error: {str(e)}",
196 "reasoning_tokens": 0,
197 "total_tokens": 0,
198 "success": False
199 }
200
201
202def save_result(filename: str, result: Dict):

Callers 1

mainFunction · 0.70

Calls 1

createMethod · 0.45

Tested by

no test coverage detected