-
Notifications
You must be signed in to change notification settings - Fork 56
Configuring aiohttp.web.ClientSession creation for CopilotStudio through ConnectionSettings #278
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...s/microsoft-agents-copilotstudio-client/microsoft_agents/copilotstudio/client/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...microsoft-agents-copilotstudio-client/microsoft_agents/copilotstudio/client/agent_type.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...nt/microsoft_agents/copilotstudio/client/direct_to_engine_connection_settings_protocol.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...agents-copilotstudio-client/microsoft_agents/copilotstudio/client/execute_turn_request.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...agents-copilotstudio-client/microsoft_agents/copilotstudio/client/power_platform_cloud.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...-copilotstudio-client/microsoft_agents/copilotstudio/client/power_platform_environment.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import pytest | ||
|
|
||
| from contextlib import asynccontextmanager | ||
|
|
||
| from microsoft_agents.activity import Activity | ||
|
|
||
| from microsoft_agents.copilotstudio.client import ( | ||
| ConnectionSettings, | ||
| CopilotClient, | ||
| PowerPlatformEnvironment, | ||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| from aiohttp import ClientSession, ClientError | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_copilot_client_error(mocker): | ||
| # Define the connection settings | ||
| connection_settings = ConnectionSettings( | ||
| "environment-id", | ||
| "agent-id", | ||
| client_session_settings={"base_url": "https://api.copilotstudio.com"}, | ||
| ) | ||
|
|
||
| mock_session = mocker.MagicMock(spec=ClientSession) | ||
| mock_session.__aenter__.return_value = mock_session | ||
|
|
||
| @asynccontextmanager | ||
| async def response(): | ||
| mock_response = mocker.Mock() | ||
| mock_response.status = 401 | ||
| yield mock_response | ||
|
|
||
| mock_session.post.return_value = response() | ||
|
|
||
| mocker.patch("aiohttp.ClientSession.__new__", return_value=mock_session) | ||
|
|
||
| # Create a CopilotClient instance | ||
| copilot_client = CopilotClient(connection_settings, "token") | ||
|
|
||
| with pytest.raises(ClientError): | ||
| async for message in copilot_client.start_conversation(): | ||
| # Process the message received from the conversation | ||
| print(message) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_copilot_client_basic(mocker): | ||
| # Define the connection settings | ||
| connection_settings = ConnectionSettings( | ||
| "environment-id", | ||
| "agent-id", | ||
| client_session_settings={"base_url": "https://api.copilotstudio.com"}, | ||
| ) | ||
|
|
||
| mock_session = mocker.MagicMock(spec=ClientSession) | ||
| mock_session.__aenter__.return_value = mock_session | ||
|
|
||
| @asynccontextmanager | ||
| async def response(): | ||
| mock_response = mocker.Mock() | ||
| mock_response.status = 200 | ||
|
|
||
| activity = Activity( | ||
| type="message", text="Hello, world!", conversation={"id": "1234567890"} | ||
| ) | ||
| activity_json = activity.model_dump_json(exclude_unset=True) | ||
|
|
||
| async def content(): | ||
| yield "event: activity".encode() | ||
| yield f"data: {activity_json}".encode() | ||
|
|
||
| mock_response.content = content() | ||
|
|
||
| yield mock_response | ||
|
|
||
| mock_session.post.return_value = response() | ||
|
|
||
| mocker.patch("aiohttp.ClientSession.__new__", return_value=mock_session) | ||
|
|
||
| # Create a CopilotClient instance | ||
| copilot_client = CopilotClient(connection_settings, "token") | ||
|
|
||
| count = 0 | ||
| async for message in copilot_client.start_conversation(): | ||
| count += 1 | ||
| assert message.type == "message" | ||
| assert message.text == "Hello, world!" | ||
| assert message.conversation.id == "1234567890" | ||
|
|
||
| assert count == 1 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.