Skip to content

Commit a730a63

Browse files
authored
fix assistant creating without file (#689)
* fix assistant creating without file * add a simple unit test * format code
1 parent b0a6d72 commit a730a63

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

autogen/agentchat/contrib/gpt_assistant_agent.py

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(
6464
instructions=instructions,
6565
tools=llm_config.get("tools", []),
6666
model=llm_config.get("model", "gpt-4-1106-preview"),
67+
file_ids=llm_config.get("file_ids", []),
6768
)
6869
else:
6970
# retrieve an existing assistant

test/agentchat/contrib/test_gpt_assistant.py

+35
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
import autogen
5+
from autogen import OpenAIWrapper
56

67
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
78
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST # noqa: E402
@@ -169,8 +170,42 @@ def test_gpt_assistant_existing_no_instructions():
169170
assert instruction_match is True
170171

171172

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+
172206
if __name__ == "__main__":
173207
test_gpt_assistant_chat()
174208
test_get_assistant_instructions()
175209
test_gpt_assistant_instructions_overwrite()
176210
test_gpt_assistant_existing_no_instructions()
211+
test_get_assistant_files()

0 commit comments

Comments
 (0)