Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test_agents_client.py, test_agents_client_async.py, and conftest.py #38656

Open
wants to merge 208 commits into
base: feature/azure-ai-projects-b2
Choose a base branch
from

Conversation

sophia-ramsey
Copy link
Member

Description

  • Updates test files to include streaming functions and user_functions using various input types.
  • Updates both test files to use with self.create_client() as client: instead of creating and deleting the client in each function
  • Skips certain tests depending on region deployment or sanitation issues, which I am looking into now
  • Updates conftest.py to remove batch sanitizer for ID, but leaves agents tests skipped -- I will upload recordings next.

howieleung and others added 18 commits November 12, 2024 10:54
* Removed enterprise and add installation for tracing

* clean up

* resolved comments
* fix(pylint): Resolve R1705(no-else-return)

* fix(pylint): Resolve C0207(use-maxsplit-arg)

* fix(pylint): Resolve C0412(ungrouped-imports)

* fix(pylint): Resolve W1401(anomalous-backslash-in-string)

* fix(pylint): Resolve W0105(pointless-string-statement)

* fix(pylint): Ignore W0221(arguments-differ)

         pylint has an open issue tracking false positives for
         arguments-differ with overloads in subclasses

* fix(pylint): Ignore W0718(broad-exception-caught)

* fix(pylint): Ignore E0401(import-error) and E0611(no-name-in-module)

* fix(pylint): Ignore C4748(client-accepts-api-verison-keyword)

    Currently, neither client classes supports overriding the api version

* fix(pylint): Ignore W0212(protected-access)

* fix(pylint): resolve W0707(raise-missing-from)

* fix(pylint): Ignore E1102(not-callable)

    pylint appears to fail to correctly infer that
    settings.tracing_implementation actually is callable

* fix(pylint): Ignore W0231(super-init-not-called)

* fix(pylint): Ignore W0613(unused-argument)

* fix(pylint): Ignore W0236(invalid-overriden-method)

* fix(pylint): Ignore R0914(too-many-locals)

* fix(pylint): Ignore R0902(too-many-instance-attributes)

* fix(pylint): Ignore R0915(too-many-statements)

* fix(pylint): Ignore R0911(too-many-return-statements)
@azure-sdk
Copy link
Collaborator

API change check

APIView has identified API level changes in this PR and created following API reviews.

azure-ai-projects

@sophia-ramsey
Copy link
Member Author

sophia-ramsey commented Nov 22, 2024 via email

# These are the user-defined functions that can be called by the agent.


def fetch_current_datetime(format: Optional[str] = None) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can shorten logic here: format: str = "%Y-%m-%d %H:%M:%S", then we will not need if ... else.

:return: The merged dictionary.
:rtype: str
"""
merged = dict1.copy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, it is not necessary, but let us do a deepcopy in case if we will have the collection as a dictionary value

import copy
...
merged = copy.deepcopy(dict1)

client.agents.delete_agent(agent.id)
print("Deleted agent")

# test update agent without body: JSON
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us move test descriptions to the docstring:

@agentClientPreparer()
@recorded_by_proxy
def test_update_agent_2(self, **kwargs):
"""test update agent without body: JSON"""

@recorded_by_proxy
def test_update_agent_2(self, **kwargs):
# create client
with self.create_client(**kwargs) as client:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we can create utility test, which accepts body?

class TestAgentClient:
    # Make body a statuc field to easily take it
    BODY = {
            "name": "my-agent",
            "model": "gpt-4o",
            "instructions": "You are helpful agent"
        }
    def _do_test_update_agent(self, body, **kwargs)
        """Test agent"""
        with self.create_client(**kwargs) as client:
           assert isinstance(client, AIProjectClient)
           # create agent
            agent = client.agents.create_agent(body=body)
            assert agent.id
            print("Created agent, agent ID", agent.id)

            # update agent and confirm changes went through
            agent = client.agents.update_agent(assistant_id=agent.id, name="my-agent2")
            assert agent.name
            assert agent.name == "my-agent2"

            # delete agent and close client
            client.agents.delete_agent(agent.id)
            print("Deleted agent")

    @agentClientPreparer()
    @recorded_by_proxy
    def test_update_agent_2(self, **kwargs):
        self._do_test_update_agent(TestAgentClient.BODY, **kwargs)

    @agentClientPreparer()
    @recorded_by_proxy
    def test_update_agent_as_json(self, **kwargs):
        self._do_test_update_agent(json.dumps(TestAgentClient.BODY), **kwargs)

    @agentClientPreparer()
    @recorded_by_proxy
    def test_update_agent_as_bin(self, **kwargs):
        self._do_test_update_agent(json.dumps(TestAgentClient.BODY).encode('utf-8'), **kwargs)

"role": "user",
"content": "Hello, tell me a joke"
}
binary_body = json.dumps(body).encode("utf-8")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us also use utility method here, because we only change the way body is being encoded.

@agentClientPreparer()
@recorded_by_proxy_async
async def test_update_message_with_body(self, **kwargs):
# create client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us use utility test with different body encodings

@agentClientPreparer()
@recorded_by_proxy_async
async def test_create_run_with_iobytes(self, **kwargs):
# create client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us use utility test with different body encodings

@agentClientPreparer()
@recorded_by_proxy_async
async def test_submit_tool_outputs_to_run(self, **kwargs):
async def test_update_run_with_body(self, **kwargs):
# create client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us use utility test with different body encodings

@pytest.mark.skip("File ID issues with sanitization.")
@recorded_by_proxy_async
async def test_submit_tool_outputs_to_run_with_body(self, **kwargs):
# create client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us use utility test with different body encodings

@agentClientPreparer()
@recorded_by_proxy_async
async def test_create_thread_and_run_with_body(self, **kwargs):
# time.sleep(26)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us use utility test with different body encodings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.