From de0aa8c292513fe88797b5ec764b2c424f3cab2c Mon Sep 17 00:00:00 2001 From: Evaline Ju <69598118+evaline-ju@users.noreply.github.com> Date: Thu, 22 Aug 2024 09:13:38 -0600 Subject: [PATCH] :label: Make evidence value optional (#174) * :memo: Make evidence value optional Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com> * :label::bulb: Make evidence value optional Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com> --------- Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com> --- docs/api/openapi_detector_api.yaml | 2 -- docs/api/orchestrator_openapi_0_1_0.yaml | 2 -- src/clients/detector.rs | 12 ++++++++---- src/models.rs | 18 +++++++++++------- src/orchestrator/unary.rs | 4 ++-- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/docs/api/openapi_detector_api.yaml b/docs/api/openapi_detector_api.yaml index 46c20979..30f40a45 100644 --- a/docs/api/openapi_detector_api.yaml +++ b/docs/api/openapi_detector_api.yaml @@ -370,7 +370,6 @@ components: type: object required: - name - - value title: Evidence EvidenceObj: properties: @@ -397,7 +396,6 @@ components: type: object required: - name - - value title: EvidenceObj GenerationAnalysisHttpRequest: properties: diff --git a/docs/api/orchestrator_openapi_0_1_0.yaml b/docs/api/orchestrator_openapi_0_1_0.yaml index 3e634f17..7a0a2e38 100644 --- a/docs/api/orchestrator_openapi_0_1_0.yaml +++ b/docs/api/orchestrator_openapi_0_1_0.yaml @@ -615,7 +615,6 @@ components: type: object required: - name - - value title: Evidence EvidenceObj: properties: @@ -641,7 +640,6 @@ components: type: object required: - name - - value title: EvidenceObj FinishReason: type: string diff --git a/src/clients/detector.rs b/src/clients/detector.rs index 22800f66..c15323db 100644 --- a/src/clients/detector.rs +++ b/src/clients/detector.rs @@ -162,9 +162,11 @@ impl ContentAnalysisRequest { pub struct Evidence { /// Evidence name pub name: String, - /// Evidence value - pub value: String, + /// Optional, evidence value + #[serde(skip_serializing_if = "Option::is_none")] + pub value: Option, /// Optional, score for evidence + #[serde(skip_serializing_if = "Option::is_none")] pub score: Option, } @@ -173,9 +175,11 @@ pub struct Evidence { pub struct EvidenceObj { /// Evidence name pub name: String, - /// Evidence value - pub value: String, + /// Optional, evidence value + #[serde(skip_serializing_if = "Option::is_none")] + pub value: Option, /// Optional, score for evidence + #[serde(skip_serializing_if = "Option::is_none")] pub score: Option, /// Optional, evidence on evidence value // Evidence nesting should likely not go beyond this diff --git a/src/models.rs b/src/models.rs index c0217a9a..7080f34a 100644 --- a/src/models.rs +++ b/src/models.rs @@ -986,9 +986,11 @@ fn validate_detector_params( pub struct Evidence { // Name for the evidence pub name: String, - // Value for the evidence - pub value: String, - // Computed score for the value + // Optional, value for the evidence + #[serde(skip_serializing_if = "Option::is_none")] + pub value: Option, + // Optional, computed score for the value + #[serde(skip_serializing_if = "Option::is_none")] pub score: Option, } @@ -997,11 +999,13 @@ pub struct Evidence { pub struct EvidenceObj { // Name for the evidence pub name: String, - // Value for the evidence - pub value: String, - // Computed score for the value + // Optional, value for the evidence + #[serde(skip_serializing_if = "Option::is_none")] + pub value: Option, + // Optional, omputed score for the value + #[serde(skip_serializing_if = "Option::is_none")] pub score: Option, - // Additional evidence + // Optional, additional evidence #[serde(skip_serializing_if = "Option::is_none")] pub evidence: Option>, } diff --git a/src/orchestrator/unary.rs b/src/orchestrator/unary.rs index 8324739a..96a2dfbd 100644 --- a/src/orchestrator/unary.rs +++ b/src/orchestrator/unary.rs @@ -968,7 +968,7 @@ mod tests { evidence: Some( [EvidenceObj { name: "relevant chunk".into(), - value: "What is capital of Brazil".into(), + value: Some("What is capital of Brazil".into()), score: Some(0.99), evidence: None, }] @@ -988,7 +988,7 @@ mod tests { evidence: Some( [EvidenceObj { name: "relevant chunk".into(), - value: "What is capital of Brazil".into(), + value: Some("What is capital of Brazil".into()), score: Some(0.99), evidence: None, }]