Test that Assistant can answer questions using code.
(test_settings: Settings)
| 297 | strict=False, |
| 298 | ) |
| 299 | def 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 | |
| 336 | def test_openai_assistant_multi(test_settings: Settings): |
nothing calls this directly
no test coverage detected
searching dependent graphs…