MCPcopy
hub / github.com/landing-ai/vision-agent / test_code

Function test_code

vision_agent/agent/vision_agent_coder_v2.py:195–258  ·  view source on GitHub ↗
(
    tester: LMM,
    debugger: LMM,
    chat: List[AgentMessage],
    plan: str,
    code: str,
    tool_docs: str,
    code_interpreter: CodeInterpreter,
    media_list: List[Union[str, Path]],
    verbose: bool,
)

Source from the content-addressed store, hash-verified

193
194
195def test_code(
196 tester: LMM,
197 debugger: LMM,
198 chat: List[AgentMessage],
199 plan: str,
200 code: str,
201 tool_docs: str,
202 code_interpreter: CodeInterpreter,
203 media_list: List[Union[str, Path]],
204 verbose: bool,
205) -> CodeContext:
206 try:
207 code = strip_function_calls(code)
208 except Exception:
209 # the code may be malformatted, this will fail in the exec call and the agent
210 # will attempt to debug it
211 pass
212 test = write_test(
213 tester=tester,
214 chat=chat,
215 tool_util_docs=get_utilties_docstring(),
216 code=code,
217 media_list=media_list,
218 )
219 if verbose:
220 print_code("Code:", code)
221 print_code("Test:", test)
222 result = code_interpreter.exec_isolation(
223 f"{DefaultImports.to_code_string()}\n{code}\n{test}"
224 )
225 if verbose:
226 _CONSOLE.print(
227 f"[bold cyan]Code execution result:[/bold cyan] [yellow]{escape(result.text(include_logs=True))}[/yellow]"
228 )
229
230 count = 0
231 debug_info = ""
232 while (not result.success or len(result.logs.stdout) == 0) and count < 3:
233 code, test, debug_info = debug_code(
234 debugger,
235 get_utilties_docstring() + "\n" + tool_docs,
236 plan,
237 code,
238 test,
239 result,
240 debug_info,
241 verbose,
242 )
243 result = code_interpreter.exec_isolation(
244 f"{DefaultImports.to_code_string()}\n{code}\n{test}"
245 )
246 count += 1
247 if verbose:
248 print_code("Code and test after attempted fix:", code, test)
249 _CONSOLE.print(
250 f"[bold cyan]Code execution result after attempted fix:[/bold cyan] [yellow]{escape(result.text(include_logs=True))}[/yellow]"
251 )
252

Callers 2

write_and_test_codeFunction · 0.85

Calls 9

strip_function_callsFunction · 0.90
get_utilties_docstringFunction · 0.90
print_codeFunction · 0.90
CodeContextClass · 0.90
write_testFunction · 0.85
debug_codeFunction · 0.85
exec_isolationMethod · 0.80
to_code_stringMethod · 0.80
textMethod · 0.80

Tested by

no test coverage detected