Repository navigation
Add get, delete and reset-settings methods for chat workspaces #1291
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
Closed
imranrkhan13
wants to merge
4
commits into
meilisearch:main
from
imranrkhan13:add-chat-workspace-methods
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a45bf77
Add get, delete and reset-settings methods for chat workspaces
imranrkhan13 a71b3ee
Add tests for chat workspace methods
imranrkhan13 7a19e4a
Update validation for workspace_uid in client.py
imranrkhan13 0bbf333
Add regression tests for ? and # in chat workspace uid
imranrkhan13 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
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,56 @@ | ||
| import pytest | ||
|
|
||
| from meilisearch.errors import MeilisearchApiError | ||
|
|
||
| WORKSPACE = "test-workspace" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def chat_workspace(client): | ||
| """Enable the chat completions feature and create a workspace.""" | ||
| client.update_experimental_features({"chatCompletions": True}) | ||
| client.update_chat_workspace_settings(WORKSPACE, {"source": "openAi", "apiKey": "test-key"}) | ||
| yield WORKSPACE | ||
| try: | ||
| client.delete_chat_workspace(WORKSPACE) | ||
| except MeilisearchApiError: | ||
| pass | ||
| client.update_experimental_features({"chatCompletions": False}) | ||
|
|
||
|
|
||
| def test_get_chat_workspace(client, chat_workspace): | ||
| """Test that an existing workspace can be fetched.""" | ||
| assert client.get_chat_workspace(chat_workspace) == {"uid": chat_workspace} | ||
|
|
||
|
|
||
| def test_get_chat_workspace_not_found(client, chat_workspace): | ||
| """Test that fetching an unknown workspace raises an API error.""" | ||
| with pytest.raises(MeilisearchApiError) as exc: | ||
| client.get_chat_workspace("does-not-exist") | ||
| assert exc.value.code == "chat_not_found" | ||
|
|
||
|
|
||
| def test_reset_chat_workspace_settings(client, chat_workspace): | ||
| """Test that resetting settings removes the stored API key.""" | ||
| result = client.reset_chat_workspace_settings(chat_workspace) | ||
| assert result["apiKey"] is None | ||
| assert client.get_chat_workspace_settings(chat_workspace)["apiKey"] is None | ||
|
|
||
|
|
||
| def test_delete_chat_workspace(client, chat_workspace): | ||
| """Test that a deleted workspace can no longer be fetched.""" | ||
| client.delete_chat_workspace(chat_workspace) | ||
| with pytest.raises(MeilisearchApiError) as exc: | ||
| client.get_chat_workspace(chat_workspace) | ||
| assert exc.value.code == "chat_not_found" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "method", | ||
| ["get_chat_workspace", "delete_chat_workspace", "reset_chat_workspace_settings"], | ||
| ) | ||
| @pytest.mark.parametrize("uid", ["", "a/b", "a\\b", "a?b", "a#b"]) | ||
| def test_chat_workspace_methods_reject_invalid_uid(client, method, uid): | ||
| """Test that an empty uid or one with path separators or URL delimiters is rejected before any request.""" | ||
| with pytest.raises(ValueError): | ||
| getattr(client, method)(uid) |
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.