|
2 | 2 | import os
|
3 | 3 | import sys
|
4 | 4 | import autogen
|
| 5 | +from autogen import OpenAIWrapper |
5 | 6 |
|
6 | 7 | sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
|
7 | 8 | from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST # noqa: E402
|
@@ -169,8 +170,42 @@ def test_gpt_assistant_existing_no_instructions():
|
169 | 170 | assert instruction_match is True
|
170 | 171 |
|
171 | 172 |
|
| 173 | +@pytest.mark.skipif( |
| 174 | + sys.platform in ["darwin", "win32"] or skip_test, |
| 175 | + reason="do not run on MacOS or windows or dependency is not installed", |
| 176 | +) |
| 177 | +def test_get_assistant_files(): |
| 178 | + """ |
| 179 | + Test function to create a new GPTAssistantAgent, set its instructions, retrieve the instructions, |
| 180 | + and assert that the retrieved instructions match the set instructions. |
| 181 | + """ |
| 182 | + current_file_path = os.path.abspath(__file__) |
| 183 | + openai_client = OpenAIWrapper(config_list=config_list)._clients[0] |
| 184 | + file = openai_client.files.create(file=open(current_file_path, "rb"), purpose="assistants") |
| 185 | + |
| 186 | + assistant = GPTAssistantAgent( |
| 187 | + "assistant", |
| 188 | + instructions="This is a test", |
| 189 | + llm_config={ |
| 190 | + "config_list": config_list, |
| 191 | + "tools": [{"type": "retrieval"}], |
| 192 | + "file_ids": [file.id], |
| 193 | + }, |
| 194 | + ) |
| 195 | + |
| 196 | + files = assistant.openai_client.beta.assistants.files.list(assistant_id=assistant.assistant_id) |
| 197 | + retrived_file_ids = [fild.id for fild in files] |
| 198 | + expected_file_id = file.id |
| 199 | + |
| 200 | + assistant.delete_assistant() |
| 201 | + openai_client.files.delete(file.id) |
| 202 | + |
| 203 | + assert expected_file_id in retrived_file_ids |
| 204 | + |
| 205 | + |
172 | 206 | if __name__ == "__main__":
|
173 | 207 | test_gpt_assistant_chat()
|
174 | 208 | test_get_assistant_instructions()
|
175 | 209 | test_gpt_assistant_instructions_overwrite()
|
176 | 210 | test_gpt_assistant_existing_no_instructions()
|
| 211 | + test_get_assistant_files() |
0 commit comments