From b79243e59576c6ac6bb6224640b821636758fd8a Mon Sep 17 00:00:00 2001 From: Caleb Courier Date: Fri, 5 Apr 2024 09:39:16 -0500 Subject: [PATCH 1/4] fix api client kwargs, ignore incorrect typing errors --- guardrails/api_client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guardrails/api_client.py b/guardrails/api_client.py index 8b7376e89..bf8b7323b 100644 --- a/guardrails/api_client.py +++ b/guardrails/api_client.py @@ -23,10 +23,10 @@ def __init__(self, base_url: Optional[str] = None, api_key: Optional[str] = None api_key if api_key is not None else os.environ.get("GUARDRAILS_API_KEY", "") ) self._client = AuthenticatedClient( - _base_url=self.base_url, - _follow_redirects=True, + base_url=self.base_url, # type: ignore + follow_redirects=True, # type: ignore token=self.api_key, - _timeout=Timeout(300), + timeout=Timeout(300), # type: ignore ) def upsert_guard(self, guard: Guard): From b7a7e3057c69ea363b263f57ee5ac23ead1f8cd2 Mon Sep 17 00:00:00 2001 From: Caleb Courier Date: Fri, 5 Apr 2024 11:15:50 -0500 Subject: [PATCH 2/4] make reasks a list --- guardrails/guard.py | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/guardrails/guard.py b/guardrails/guard.py index 0f65407fc..068cf7c40 100644 --- a/guardrails/guard.py +++ b/guardrails/guard.py @@ -1430,27 +1430,25 @@ def _call_server( if isinstance(h.validated_output, AnyObject) else h.validated_output ), - reasks=( + reasks=list( [ - ( - FieldReAsk( - incorrect_value=r.to_dict().get( - "incorrect_value" - ), - path=r.to_dict().get("path"), - fail_results=[ - FailResult( - error_message=r.to_dict().get( - "error_message" - ), - fix_value=r.to_dict().get( - "fix_value" - ), - ) - ], - ) - for r in h.reasks # type: ignore + FieldReAsk( + incorrect_value=r.to_dict().get( + "incorrect_value" + ), + path=r.to_dict().get("path"), + fail_results=[ + FailResult( + error_message=r.to_dict().get( + "error_message" + ), + fix_value=r.to_dict().get( + "fix_value" + ), + ) + ], ) + for r in h.reasks # type: ignore ] if h.reasks != UNSET else [] From aad8179ed96842a7422a90f4e91bf3242e9d5479 Mon Sep 17 00:00:00 2001 From: Caleb Courier Date: Fri, 5 Apr 2024 11:31:06 -0500 Subject: [PATCH 3/4] construct ValidationOutcome manually --- guardrails/guard.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/guardrails/guard.py b/guardrails/guard.py index 068cf7c40..7148d4f53 100644 --- a/guardrails/guard.py +++ b/guardrails/guard.py @@ -1442,9 +1442,7 @@ def _call_server( error_message=r.to_dict().get( "error_message" ), - fix_value=r.to_dict().get( - "fix_value" - ), + fix_value=r.to_dict().get("fix_value"), ) ], ) @@ -1461,6 +1459,14 @@ def _call_server( if self.history.length == 0: self.history.push(call_log) - return ValidationOutcome[OT].from_guard_history(call_log) + # Our interfaces are too different for this to work right now. + # Once we move towards shared interfaces for both the open source + # and the api we can re-enable this. + # return ValidationOutcome[OT].from_guard_history(call_log) + return ValidationOutcome[OT]( + raw_llm_output=validation_output.raw_llm_response, # type: ignore + validated_output=cast(OT, validation_output.validated_output), + validation_passed=validation_output.result, + ) else: raise ValueError("Guard does not have an api client!") From 55d0eed6733d07ed5de32099f87835a7f43ce2f1 Mon Sep 17 00:00:00 2001 From: Caleb Courier Date: Fri, 5 Apr 2024 15:42:14 -0500 Subject: [PATCH 4/4] update guardrails-api-client --- poetry.lock | 12 ++++++------ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/poetry.lock b/poetry.lock index e47608f14..5d9c06983 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. [[package]] name = "aiohttp" @@ -1804,13 +1804,13 @@ protobuf = ["grpcio-tools (>=1.62.1)"] [[package]] name = "guardrails-api-client" -version = "0.1.0" +version = "0.1.1" description = "A client library for accessing Guardrails API" optional = false -python-versions = ">=3.8, <4" +python-versions = "<4,>=3.8" files = [ - {file = "guardrails-api-client-0.1.0.tar.gz", hash = "sha256:89276b4c4f1d7bca280c04a18f9eafaaafa3fea73da90ce2061790ebbb2af475"}, - {file = "guardrails_api_client-0.1.0-py3-none-any.whl", hash = "sha256:ec5f5abbd0adc72203ac1601e6aee562db2de65bd5ec509b45c26fd0eed7c733"}, + {file = "guardrails-api-client-0.1.1.tar.gz", hash = "sha256:d707661b0e63269c9ab257c4ba6eed20af18a734607cab8bb3bee0d2883bc50f"}, + {file = "guardrails_api_client-0.1.1-py3-none-any.whl", hash = "sha256:99baf4a11fcc61b420197c019fa24a479a44afb44b858e43d874cc95926295fd"}, ] [package.dependencies] @@ -8150,4 +8150,4 @@ vectordb = ["faiss-cpu", "numpy"] [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "0a872ca2ce54a5f8f7636cb1be1dd01fab9ad2ac29b6b6c6563a7bd382c3ffa4" +content-hash = "4073f58d4362af9147bc404b760d25659dfaf5a223566a926edf0f26e6a072cc" diff --git a/pyproject.toml b/pyproject.toml index 0699197ef..026af0af3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,7 +55,7 @@ opentelemetry-exporter-otlp-proto-http = "1.20.0" langchain-core = "^0.1.18" coloredlogs = "^15.0.1" requests = "^2.31.0" -guardrails-api-client = "^0.1.0" +guardrails-api-client = "^0.1.1" jwt = "^1.3.1"