Skip to content

Commit

Permalink
🦺 Initial request validation (#42)
Browse files Browse the repository at this point in the history
* ➕ Switch validator for garde

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

* 🦺 Add initial input request validation with garde

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

* 🚧 Attempt custom validation

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

* 🥅🚧 Input masks validation

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

* ✅ Initial request validation tests

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

* ✅ Garde validation case

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

* 🔧 Pass along input text preservation

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

* ✅ Error string checking

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

* 🥅 Use error handling objects

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

* 📝🦺 Update errors in API

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

* 📌 Switch API validation dependencies

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

* 🎨 Lint

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

* ♻️ Validation without garde

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

* ✅🏷️ Update tests and types

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

* 🎨 Linting

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>

---------

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>
  • Loading branch information
evaline-ju authored May 24, 2024
1 parent f6e8eed commit 34f04ff
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 141 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] }
url = "2.5.0"
uuid = { version = "1.8.0", features = ["v4", "fast-rng"] }
validator = { version = "0.18.1", features = ["derive"] } # For API validation

[build-dependencies]
tonic-build = "0.11.0"
Expand Down
56 changes: 24 additions & 32 deletions docs/api/orchestrator_openapi_0_1_0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ClassifiedGeneratedTextResult'
'404':
description: Resource Not Found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
$ref: '#/components/schemas/Error'
/api/v1/task/server-streaming-classification-with-text-generation:
post:
tags:
Expand All @@ -49,12 +55,18 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ClassifiedGeneratedTextStreamResult'
'404':
description: Resource Not Found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
$ref: '#/components/schemas/Error'
components:
schemas:
ClassifiedGeneratedTextResult:
Expand Down Expand Up @@ -156,6 +168,16 @@ components:
required: ["input_token_count", "token_classification_results", "start_index"]
type: object
title: ClassifiedGeneratedTextStreamResult
Error:
type: object
properties:
code:
type: string
details:
type: string
required:
- code
- details
ExponentialDecayLengthPenalty:
properties:
start_index:
Expand Down Expand Up @@ -299,15 +321,6 @@ components:
additionalProperties: false
type: object
title: GuardrailsTextGenerationParameters
HTTPValidationError:
properties:
detail:
items:
$ref: '#/components/schemas/ValidationError'
type: array
title: Detail
type: object
title: HTTPValidationError
InputWarning:
properties:
id:
Expand Down Expand Up @@ -368,24 +381,3 @@ components:
required: ["start", "end", "word", "entity", "entity_group", "score"]
type: object
title: TokenClassificationResult
ValidationError:
properties:
loc:
items:
anyOf:
- type: string
- type: integer
type: array
title: Location
msg:
type: string
title: Message
type:
type: string
title: Error Type
type: object
required:
- loc
- msg
- type
title: ValidationError
4 changes: 2 additions & 2 deletions src/clients/detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ pub struct DetectorResponse {
impl From<Detection> for crate::models::TokenClassificationResult {
fn from(value: Detection) -> Self {
Self {
start: value.start as i32,
end: value.end as i32,
start: value.start as u32,
end: value.end as u32,
word: value.text,
entity: value.detection,
entity_group: value.detection_type,
Expand Down
Loading

0 comments on commit 34f04ff

Please sign in to comment.