Repository navigation
Add remaining chats API methods #1292
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
Open
imranrkhan13
wants to merge
6
commits into
meilisearch:main
Choose a base branch
from
imranrkhan13:add-chats-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ea687dd
Add chat path to settings config
imranrkhan13 87e2acd
Add chat workspace client tests
imranrkhan13 a7ad921
Add index chat settings tests
imranrkhan13 09b6f87
Add index chat settings code samples
imranrkhan13 b169863
Add chat workspace get, delete and reset-settings methods to Client
imranrkhan13 a50b289
Add index chat settings get, update and reset methods
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
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
| 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) | ||
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,68 @@ | ||
| import pytest | ||
|
|
||
| DEFAULT_CHAT_SETTINGS_KEYS = { | ||
| "description", | ||
| "documentTemplate", | ||
| "documentTemplateMaxBytes", | ||
| "searchParameters", | ||
| } | ||
|
|
||
| NEW_CHAT_SETTINGS = { | ||
| "description": "A collection of movies", | ||
| "documentTemplate": "A movie titled {{ doc.title }}", | ||
| "documentTemplateMaxBytes": 200, | ||
| "searchParameters": {"limit": 5}, | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def chat_completions_enabled(client): | ||
| """Updating index chat settings requires the chatCompletions experimental feature.""" | ||
| previous = client.get_experimental_features().get("chatCompletions", False) | ||
| client.update_experimental_features({"chatCompletions": True}) | ||
| yield | ||
| client.update_experimental_features({"chatCompletions": previous}) | ||
|
|
||
|
|
||
| def test_get_chat_settings(empty_index): | ||
| response = empty_index().get_chat_settings() | ||
|
|
||
| assert DEFAULT_CHAT_SETTINGS_KEYS == set(response) | ||
| assert response["description"] == "" | ||
| assert response["documentTemplateMaxBytes"] == 400 | ||
| assert response["searchParameters"] == {} | ||
|
|
||
|
|
||
| def test_update_chat_settings(empty_index, chat_completions_enabled): | ||
| index = empty_index() | ||
|
|
||
| response = index.update_chat_settings(NEW_CHAT_SETTINGS) | ||
| index.wait_for_task(response.task_uid) | ||
| response = index.get_chat_settings() | ||
|
|
||
| assert response == NEW_CHAT_SETTINGS | ||
|
|
||
|
|
||
| def test_update_chat_settings_partial(empty_index, chat_completions_enabled): | ||
| index = empty_index() | ||
| index.wait_for_task(index.update_chat_settings(NEW_CHAT_SETTINGS).task_uid) | ||
|
|
||
| response = index.update_chat_settings({"description": "Updated"}) | ||
| index.wait_for_task(response.task_uid) | ||
| response = index.get_chat_settings() | ||
|
|
||
| assert response["description"] == "Updated" | ||
| assert response["documentTemplate"] == NEW_CHAT_SETTINGS["documentTemplate"] | ||
| assert response["searchParameters"] == NEW_CHAT_SETTINGS["searchParameters"] | ||
|
|
||
|
|
||
| def test_reset_chat_settings(empty_index, chat_completions_enabled): | ||
| index = empty_index() | ||
| default_settings = index.get_chat_settings() | ||
| index.wait_for_task(index.update_chat_settings(NEW_CHAT_SETTINGS).task_uid) | ||
| assert index.get_chat_settings() != default_settings | ||
|
|
||
| response = index.reset_chat_settings() | ||
| index.wait_for_task(response.task_uid) | ||
|
|
||
| assert index.get_chat_settings() == default_settings |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Restore the previous
chatCompletionsvalue.If
chatCompletionswas enabled before this fixture ran, Line 18 disables it after the test. Later tests can then fail because this fixture changed shared server state. Save the previous value before enabling the feature, and restore that value during teardown.Proposed fix
🤖 Prompt for AI Agents