MCPcopy
hub / github.com/langroid/langroid / test_openai_asst_code_interpreter

Function test_openai_asst_code_interpreter

tests/main/test_openai_assistant.py:299–333  ·  view source on GitHub ↗

Test that Assistant can answer questions using code.

(test_settings: Settings)

Source from the content-addressed store, hash-verified

297 strict=False,
298)
299def test_openai_asst_code_interpreter(test_settings: Settings):
300 """
301 Test that Assistant can answer questions using code.
302 """
303 set_global(test_settings)
304 cfg = OpenAIAssistantConfig(
305 llm=OpenAIGPTConfig(),
306 system_message="Answer questions by running code if needed",
307 )
308 agent = OpenAIAssistant(cfg)
309
310 # create temp file with in-code text content
311 text = """
312 Vlad Nabrosky was born in Russia. He then emigrated to the United States,
313 where he wrote the novel Lomita. He was a professor at Purnell University.
314 """
315
316 # open a temp file and write text to it
317 with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
318 f.write(text)
319 f.close()
320 # get the filename
321 filename = f.name
322
323 # must enable retrieval first, then add file
324 agent.add_assistant_tools([AssistantTool(type="code_interpreter")])
325 agent.add_assistant_files([filename])
326
327 response = agent.llm_response(
328 "what is the 10th fibonacci number, when you start with 1 and 2?"
329 )
330 assert "89" in response.content
331
332 response = agent.llm_response("how many words are in the file?")
333 assert str(len(text.split())) in response.content
334
335
336def test_openai_assistant_multi(test_settings: Settings):

Callers

nothing calls this directly

Calls 11

add_assistant_toolsMethod · 0.95
add_assistant_filesMethod · 0.95
llm_responseMethod · 0.95
set_globalFunction · 0.90
OpenAIGPTConfigClass · 0.90
OpenAIAssistantClass · 0.90
AssistantToolClass · 0.90
writeMethod · 0.80
closeMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…