Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
feat: add timestamps fields to suggestion schema (#52)
Browse files Browse the repository at this point in the history
# Description

Add `inserted_at` and `updated_at` fields to `Suggestion` schema for API
v1.

Refs #45 

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

(Please describe the tests that you ran to verify your changes. And
ideally, reference `tests`)

- [x] Modifying tests.

**Checklist**

- [ ] I added relevant documentation
- [ ] follows the style guidelines of this project
- [x] I did a self-review of my code
- [ ] I made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I filled out [the contributor form](https://tally.so/r/n9XrxK)
(see text above)
- [x] I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)

---------

Co-authored-by: Paco Aranda <francis@argilla.io>
  • Loading branch information
jfcalvo and frascuchon authored Mar 6, 2024
1 parent 5ae49f4 commit 6541a64
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 12 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ These are the section headers that we use:
### Added

- Add support for creating and listing questions with `SpanQuestionSettings`. ([#24](https://github.com/argilla-io/argilla-server/pull/24))
- Add `inserted_at` and `updated_at` missing fields to API v1 `Suggestion` schema. ([#52](https://github.com/argilla-io/argilla-server/pull/52))

## [1.25.0](https://github.com/argilla-io/argilla-server/compare/v1.24.0...v1.25.0)

>[!IMPORTANT]
> [!IMPORTANT]
> This version include changes related to the search index. So, a reindex is needed.
> Visit the [docs](https://docs.argilla.io/en/latest/getting_started/installation/configurations/database_migrations.html#feedback-datasets) for more info.
Expand All @@ -46,12 +47,12 @@ These are the section headers that we use:

### Fixed

- Max size parameter for getting the metadata property metrics is currently set as 2^14(=12) instead of 2 ** 14 ([#30](https://github.com/argilla-io/argilla-server/pull/30)) ([v1.24-fix](https://github.com/bharath97-git/argilla-server/releases/tag/v1.24-fix))
- Max size parameter for getting the metadata property metrics is currently set as 2^14(=12) instead of 2 \*\* 14 ([#30](https://github.com/argilla-io/argilla-server/pull/30)) ([v1.24-fix](https://github.com/bharath97-git/argilla-server/releases/tag/v1.24-fix))
- Fixed error when combining similarity search with text search. ([#32](https://github.com/argilla-io/argilla-server/pull/32))

## [1.24.0](https://github.com/argilla-io/argilla-server/releases/tag/v1.24.0)

>[!NOTE]
> [!NOTE]
> This version is the first release of the Argilla Server. Before this release, the Argilla Server was part of the [Argilla SDK](https://github.com/argilla-io/argilla).
> Now, the Argilla Server is a separate package that can be installed and used independently of the [Argilla SDK](https://github.com/argilla-io/argilla).
Expand Down
3 changes: 3 additions & 0 deletions src/argilla_server/schemas/v1/suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime
from typing import Any, List, Literal, Optional, Union
from uuid import UUID

Expand Down Expand Up @@ -57,6 +58,8 @@ class BaseSuggestion(BaseModel):

class Suggestion(BaseSuggestion):
id: UUID
inserted_at: datetime
updated_at: datetime

class Config:
orm_mode = True
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/api/v1/records/test_upsert_suggestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime
from uuid import UUID, uuid4

import pytest
Expand Down Expand Up @@ -173,6 +174,8 @@ async def test_upsert_suggestion_for_span_question(
],
"agent": None,
"score": None,
"inserted_at": datetime.fromisoformat(response_json["inserted_at"]).isoformat(),
"updated_at": datetime.fromisoformat(response_json["updated_at"]).isoformat(),
}

async def test_upsert_suggestion_for_span_question_with_empty_value(
Expand Down Expand Up @@ -206,6 +209,8 @@ async def test_upsert_suggestion_for_span_question_with_empty_value(
"value": [],
"agent": None,
"score": None,
"inserted_at": datetime.fromisoformat(response_json["inserted_at"]).isoformat(),
"updated_at": datetime.fromisoformat(response_json["updated_at"]).isoformat(),
}

async def test_upsert_suggestion_for_span_question_with_record_not_providing_required_field(
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/api/v1/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3985,6 +3985,8 @@ async def test_search_current_user_dataset_records_with_include(
"agent": None,
"type": None,
"question_id": str(questions[0].id),
"inserted_at": suggestion_a.inserted_at.isoformat(),
"updated_at": suggestion_a.updated_at.isoformat(),
}
]
expected["items"][1]["record"]["suggestions"] = [
Expand All @@ -3995,6 +3997,8 @@ async def test_search_current_user_dataset_records_with_include(
"agent": "unit-test-agent",
"type": "model",
"question_id": str(questions[0].id),
"inserted_at": suggestion_b.inserted_at.isoformat(),
"updated_at": suggestion_b.updated_at.isoformat(),
}
]

Expand Down
38 changes: 30 additions & 8 deletions tests/unit/api/v1/test_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,24 @@ async def test_update_record(self, async_client: "AsyncClient", mock_search_engi
"responses": [],
"suggestions": [
{
"question_id": str(question_0.id),
"id": str(record.suggestions[0].id),
"type": None,
"score": None,
"value": "suggestion updated 1",
"agent": None,
"id": str(record.suggestions[0].id),
"question_id": str(question_0.id),
"inserted_at": record.suggestions[0].inserted_at.isoformat(),
"updated_at": record.suggestions[0].updated_at.isoformat(),
},
{
"question_id": str(question_1.id),
"id": str(record.suggestions[1].id),
"type": None,
"score": None,
"value": "suggestion updated 2",
"agent": None,
"id": str(record.suggestions[1].id),
"question_id": str(question_1.id),
"inserted_at": record.suggestions[1].inserted_at.isoformat(),
"updated_at": record.suggestions[1].updated_at.isoformat(),
},
],
"vectors": {
Expand Down Expand Up @@ -1211,6 +1215,8 @@ async def test_get_record_suggestions(self, async_client: "AsyncClient", role: U
"score": None,
"value": "This is a unit test suggestion",
"agent": None,
"inserted_at": suggestion_a.inserted_at.isoformat(),
"updated_at": suggestion_a.updated_at.isoformat(),
},
{
"id": str(suggestion_b.id),
Expand All @@ -1219,6 +1225,8 @@ async def test_get_record_suggestions(self, async_client: "AsyncClient", role: U
"score": None,
"value": "This is a another unit test suggestion",
"agent": None,
"inserted_at": suggestion_b.inserted_at.isoformat(),
"updated_at": suggestion_b.updated_at.isoformat(),
},
]
}
Expand Down Expand Up @@ -1255,9 +1263,21 @@ async def test_create_record_suggestion(
json={"question_id": str(question.id), **payload},
)

response_body = response.json()
assert response.status_code == 201
assert response_body == {"id": response_body["id"], "question_id": str(question.id), **payload}

response_json = response.json()
payload.update(
{
"inserted_at": datetime.fromisoformat(response_json["inserted_at"]).isoformat(),
"updated_at": datetime.fromisoformat(response_json["updated_at"]).isoformat(),
}
)
assert response_json == {
"id": response_json["id"],
"question_id": str(question.id),
**payload,
}

assert (await db.execute(select(func.count(Suggestion.id)))).scalar() == 1

async def test_create_record_suggestion_update(
Expand All @@ -1274,16 +1294,18 @@ async def test_create_record_suggestion_update(
json={"question_id": str(question.id), "value": "Testing updating a suggestion"},
)

response_body = response.json()
assert response.status_code == 200
assert response_body == {
assert response.json() == {
"id": str(suggestion.id),
"question_id": str(question.id),
"type": None,
"score": None,
"value": "Testing updating a suggestion",
"agent": None,
"inserted_at": suggestion.inserted_at.isoformat(),
"updated_at": suggestion.updated_at.isoformat(),
}

assert (await db.execute(select(func.count(Suggestion.id)))).scalar() == 1

mock_search_engine.update_record_suggestion.assert_called_once_with(suggestion)
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/api/v1/test_suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime
from typing import TYPE_CHECKING
from uuid import uuid4

Expand Down Expand Up @@ -43,14 +44,19 @@ async def test_delete_suggestion(
)

assert response.status_code == 200
assert response.json() == {

response_json = response.json()
assert response_json == {
"id": str(suggestion.id),
"question_id": str(suggestion.question_id),
"type": None,
"score": None,
"value": "negative",
"agent": None,
"inserted_at": datetime.fromisoformat(response_json["inserted_at"]).isoformat(),
"updated_at": datetime.fromisoformat(response_json["updated_at"]).isoformat(),
}

assert (await db.execute(select(func.count(Suggestion.id)))).scalar() == 0

mock_search_engine.delete_record_suggestion.assert_called_once_with(suggestion)
Expand Down

0 comments on commit 6541a64

Please sign in to comment.