Skip to content

Commit

Permalink
Add a test; add method to delete assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
gagb committed Nov 11, 2023
1 parent 0b8e233 commit d7cf481
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 9 additions & 0 deletions autogen/agentchat/contrib/gpt_assistant_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,15 @@ def oai_threads(self) -> Dict[Agent, Any]:
"""Return the threads of the agent."""
return self._openai_threads

@property
def assistant_id(self):
"""Return the assistant id"""
return self._openai_assistant.id

def get_assistant_instructions(self):
"""Return the assistant instructions from OAI assistant API"""
return self._openai_assistant.instructions

def delete_assistant(self):
"""Delete the assistant from OAI assistant API"""
self._openai_client.beta.assistants.delete(self.assistant_id)
27 changes: 26 additions & 1 deletion test/agentchat/contrib/test_gpt_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ def test_gpt_assistant_chat():
"description": "This is an API endpoint allowing users (analysts) to input question about GitHub in text format to retrieve the realted and structured data.",
}

config_list = autogen.config_list_from_json(OAI_CONFIG_LIST, file_location=KEY_LOC)
analyst = GPTAssistantAgent(
name="Open_Source_Project_Analyst",
llm_config={"tools": [{"type": "function", "function": ossinsight_api_schema}]},
llm_config={"tools": [{"type": "function", "function": ossinsight_api_schema}], "config_list": config_list},
instructions="Hello, Open Source Project Analyst. You'll conduct comprehensive evaluations of open source projects or organizations on the GitHub platform",
)
analyst.register_function(
Expand All @@ -62,5 +63,29 @@ def test_gpt_assistant_chat():
assert len(analyst._openai_threads) == 0


def test_get_assistant_instructions():
"""
Create a new assistant
Set its instructions
Retrieve the instructions
assert that the retrieved instructions match the set instructions
"""

config_list = autogen.config_list_from_json(OAI_CONFIG_LIST, file_location=KEY_LOC)
assistant = GPTAssistantAgent(
"assistant",
instructions="This is a test",
llm_config={
"config_list": config_list,
},
)

instruction_match = assistant.get_assistant_instructions() == "This is a test"
assistant.delete_assistant()

assert instruction_match is True


if __name__ == "__main__":
test_gpt_assistant_chat()
test_get_assistant_instructions()

0 comments on commit d7cf481

Please sign in to comment.