From 5fb93c49abc3c24fd444aec8f20416d58cf52537 Mon Sep 17 00:00:00 2001 From: Caleb Courier Date: Tue, 16 Apr 2024 09:59:17 -0500 Subject: [PATCH 01/10] add litellm completion and v1 openai methods --- service-specs/guardrails-service-spec.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service-specs/guardrails-service-spec.yml b/service-specs/guardrails-service-spec.yml index 8abcb18..73ef2fb 100644 --- a/service-specs/guardrails-service-spec.yml +++ b/service-specs/guardrails-service-spec.yml @@ -493,8 +493,12 @@ components: enum: [ "openai.Completion.create", + "openai.completions.create", "openai.ChatCompletion.create", + "openai.chat.completions.create", "openai.Completion.acreate", "openai.ChatCompletion.acreate", + "litellm.completion", + "litellm.acompletion" ] additionalProperties: {} From ca2a24a6151df03081736d45e89ea493ee3e4a6c Mon Sep 17 00:00:00 2001 From: CalebCourier Date: Tue, 16 Apr 2024 15:00:05 +0000 Subject: [PATCH 02/10] update generated sdk --- .../guardrails_api_client/models/validate_payload_llm_api.py | 4 ++++ open-api-spec.yml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/guardrails-api-client/guardrails_api_client/models/validate_payload_llm_api.py b/guardrails-api-client/guardrails_api_client/models/validate_payload_llm_api.py index 560092a..f4c203f 100644 --- a/guardrails-api-client/guardrails_api_client/models/validate_payload_llm_api.py +++ b/guardrails-api-client/guardrails_api_client/models/validate_payload_llm_api.py @@ -2,8 +2,12 @@ class ValidatePayloadLlmApi(str, Enum): + LITELLM_ACOMPLETION = "litellm.acompletion" + LITELLM_COMPLETION = "litellm.completion" OPENAI_CHATCOMPLETION_ACREATE = "openai.ChatCompletion.acreate" OPENAI_CHATCOMPLETION_CREATE = "openai.ChatCompletion.create" + OPENAI_CHAT_COMPLETIONS_CREATE = "openai.chat.completions.create" + OPENAI_COMPLETIONS_CREATE = "openai.completions.create" OPENAI_COMPLETION_ACREATE = "openai.Completion.acreate" OPENAI_COMPLETION_CREATE = "openai.Completion.create" diff --git a/open-api-spec.yml b/open-api-spec.yml index d352366..db07370 100644 --- a/open-api-spec.yml +++ b/open-api-spec.yml @@ -780,7 +780,7 @@ components: additionalProperties: {} llmApi: type: string - enum: ["openai.Completion.create", "openai.ChatCompletion.create", "openai.Completion.acreate", "openai.ChatCompletion.acreate"] + enum: ["openai.Completion.create", "openai.completions.create", "openai.ChatCompletion.create", "openai.chat.completions.create", "openai.Completion.acreate", "openai.ChatCompletion.acreate", "litellm.completion", "litellm.acompletion"] additionalProperties: {} Ingestion: type: object From 77b052de1d6bf6b30699c4cdba3d9fde17873241 Mon Sep 17 00:00:00 2001 From: Caleb Courier Date: Tue, 16 Apr 2024 10:00:31 -0500 Subject: [PATCH 03/10] bump version --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index 49edee3..ff59bb6 100644 --- a/config.json +++ b/config.json @@ -1,3 +1,3 @@ { - "package_version_override": "0.1.1" + "package_version_override": "0.2.0" } \ No newline at end of file From 65a83f05348a328f3ebf244ed1a2180edc4c7351 Mon Sep 17 00:00:00 2001 From: CalebCourier Date: Tue, 16 Apr 2024 15:00:55 +0000 Subject: [PATCH 04/10] update generated sdk --- guardrails-api-client/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guardrails-api-client/setup.py b/guardrails-api-client/setup.py index 250d793..3fe8f87 100644 --- a/guardrails-api-client/setup.py +++ b/guardrails-api-client/setup.py @@ -7,7 +7,7 @@ setup( name="guardrails-api-client", - version="0.1.1", + version="0.2.0", description="A client library for accessing Guardrails API", long_description=long_description, long_description_content_type="text/markdown", From 7c756ee67795300714639f43e3826e2e1b3c6dfd Mon Sep 17 00:00:00 2001 From: Caleb Courier Date: Tue, 16 Apr 2024 10:11:58 -0500 Subject: [PATCH 05/10] switch from enum to oneOf const --- service-specs/guardrails-service-spec.yml | 32 ++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/service-specs/guardrails-service-spec.yml b/service-specs/guardrails-service-spec.yml index 73ef2fb..58ac22a 100644 --- a/service-specs/guardrails-service-spec.yml +++ b/service-specs/guardrails-service-spec.yml @@ -473,6 +473,25 @@ components: oneOf: - $ref: "#/components/schemas/AnyObject" - $ref: "#/components/schemas/AnyPrimitive" + LlmApi: + type: string + oneOf: + - title: OPENAI_V0_COMPLETION_CREATE + const: openai.Completion.create + - title: OPENAI_V1_COMPLETION_CREATE + const: openai.completions.create + - title: OPENAI_V0_CHAT_COMPLETION_CREATE + const: openai.ChatCompletion.create + - title: OPENAI_V1_CHAT_COMPLETION_CREATE + const: openai.chat.completions.create + - title: OPENAI_V0_COMPLETION_ASYNC_CREATE + const: openai.Completion.acreate + - title: OPENAI_V0_CHAT_COMPLETION_ASYNC_CREATE + const: openai.ChatCompletion.acreate + - title: LITELLM_COMPLETION + const: litellm.completion + - title: LITELLM_ASYNC_COMPLETION + const: litellm.acompletion ValidatePayload: type: object properties: @@ -489,16 +508,5 @@ components: properties: {} additionalProperties: {} llmApi: - type: string - enum: - [ - "openai.Completion.create", - "openai.completions.create", - "openai.ChatCompletion.create", - "openai.chat.completions.create", - "openai.Completion.acreate", - "openai.ChatCompletion.acreate", - "litellm.completion", - "litellm.acompletion" - ] + $ref: "#/components/schemas/LlmApi" additionalProperties: {} From 066f837048e2425aa1c4651681148911fcdacc09 Mon Sep 17 00:00:00 2001 From: CalebCourier Date: Tue, 16 Apr 2024 15:12:22 +0000 Subject: [PATCH 06/10] update generated sdk --- .../guardrails_api_client/models/__init__.py | 2 - .../models/validate_payload.py | 75 +++++++++++++++---- .../models/validate_payload_llm_api.py | 15 ---- open-api-spec.yml | 22 +++++- 4 files changed, 82 insertions(+), 32 deletions(-) delete mode 100644 guardrails-api-client/guardrails_api_client/models/validate_payload_llm_api.py diff --git a/guardrails-api-client/guardrails_api_client/models/__init__.py b/guardrails-api-client/guardrails_api_client/models/__init__.py index 4431d6d..e9ab0c5 100644 --- a/guardrails-api-client/guardrails_api_client/models/__init__.py +++ b/guardrails-api-client/guardrails_api_client/models/__init__.py @@ -33,7 +33,6 @@ from .schema_element import SchemaElement from .status import Status from .validate_payload import ValidatePayload -from .validate_payload_llm_api import ValidatePayloadLlmApi from .validate_payload_prompt_params import ValidatePayloadPromptParams from .validation_output import ValidationOutput from .validator_metrics import ValidatorMetrics @@ -75,7 +74,6 @@ "SchemaElement", "Status", "ValidatePayload", - "ValidatePayloadLlmApi", "ValidatePayloadPromptParams", "ValidationOutput", "ValidatorMetrics", diff --git a/guardrails-api-client/guardrails_api_client/models/validate_payload.py b/guardrails-api-client/guardrails_api_client/models/validate_payload.py index 108baf7..e1eb3cf 100644 --- a/guardrails-api-client/guardrails_api_client/models/validate_payload.py +++ b/guardrails-api-client/guardrails_api_client/models/validate_payload.py @@ -1,9 +1,8 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union +from typing import TYPE_CHECKING, Any, Dict, List, Literal, Type, TypeVar, Union, cast from attrs import define as _attrs_define from attrs import field as _attrs_field -from ..models.validate_payload_llm_api import ValidatePayloadLlmApi from ..types import UNSET, Unset if TYPE_CHECKING: @@ -21,13 +20,26 @@ class ValidatePayload: output. num_reasks (Union[Unset, int]): An override for the number of re-asks to perform prompt_params (Union[Unset, ValidatePayloadPromptParams]): additional params for llm prompts - llm_api (Union[Unset, ValidatePayloadLlmApi]): + llm_api (Union[Literal['litellm.acompletion'], Literal['litellm.completion'], + Literal['openai.ChatCompletion.acreate'], Literal['openai.ChatCompletion.create'], + Literal['openai.Completion.acreate'], Literal['openai.Completion.create'], + Literal['openai.chat.completions.create'], Literal['openai.completions.create'], Unset]): """ llm_output: Union[Unset, str] = UNSET num_reasks: Union[Unset, int] = UNSET prompt_params: Union[Unset, "ValidatePayloadPromptParams"] = UNSET - llm_api: Union[Unset, ValidatePayloadLlmApi] = UNSET + llm_api: Union[ + Literal["litellm.acompletion"], + Literal["litellm.completion"], + Literal["openai.ChatCompletion.acreate"], + Literal["openai.ChatCompletion.create"], + Literal["openai.Completion.acreate"], + Literal["openai.Completion.create"], + Literal["openai.chat.completions.create"], + Literal["openai.completions.create"], + Unset, + ] = UNSET additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: @@ -39,9 +51,21 @@ def to_dict(self) -> Dict[str, Any]: if not isinstance(self.prompt_params, Unset): prompt_params = self.prompt_params.to_dict() - llm_api: Union[Unset, str] = UNSET - if not isinstance(self.llm_api, Unset): - llm_api = self.llm_api.value + llm_api: Union[ + Literal["litellm.acompletion"], + Literal["litellm.completion"], + Literal["openai.ChatCompletion.acreate"], + Literal["openai.ChatCompletion.create"], + Literal["openai.Completion.acreate"], + Literal["openai.Completion.create"], + Literal["openai.chat.completions.create"], + Literal["openai.completions.create"], + Unset, + ] + if isinstance(self.llm_api, Unset): + llm_api = UNSET + else: + llm_api = self.llm_api field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) @@ -73,12 +97,37 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: else: prompt_params = ValidatePayloadPromptParams.from_dict(_prompt_params) - _llm_api = d.pop("llmApi", UNSET) - llm_api: Union[Unset, ValidatePayloadLlmApi] - if isinstance(_llm_api, Unset): - llm_api = UNSET - else: - llm_api = ValidatePayloadLlmApi(_llm_api) + def _parse_llm_api( + data: object, + ) -> Union[ + Literal["litellm.acompletion"], + Literal["litellm.completion"], + Literal["openai.ChatCompletion.acreate"], + Literal["openai.ChatCompletion.create"], + Literal["openai.Completion.acreate"], + Literal["openai.Completion.create"], + Literal["openai.chat.completions.create"], + Literal["openai.completions.create"], + Unset, + ]: + if isinstance(data, Unset): + return data + return cast( + Union[ + Literal["litellm.acompletion"], + Literal["litellm.completion"], + Literal["openai.ChatCompletion.acreate"], + Literal["openai.ChatCompletion.create"], + Literal["openai.Completion.acreate"], + Literal["openai.Completion.create"], + Literal["openai.chat.completions.create"], + Literal["openai.completions.create"], + Unset, + ], + data, + ) + + llm_api = _parse_llm_api(d.pop("llmApi", UNSET)) validate_payload = cls( llm_output=llm_output, diff --git a/guardrails-api-client/guardrails_api_client/models/validate_payload_llm_api.py b/guardrails-api-client/guardrails_api_client/models/validate_payload_llm_api.py deleted file mode 100644 index f4c203f..0000000 --- a/guardrails-api-client/guardrails_api_client/models/validate_payload_llm_api.py +++ /dev/null @@ -1,15 +0,0 @@ -from enum import Enum - - -class ValidatePayloadLlmApi(str, Enum): - LITELLM_ACOMPLETION = "litellm.acompletion" - LITELLM_COMPLETION = "litellm.completion" - OPENAI_CHATCOMPLETION_ACREATE = "openai.ChatCompletion.acreate" - OPENAI_CHATCOMPLETION_CREATE = "openai.ChatCompletion.create" - OPENAI_CHAT_COMPLETIONS_CREATE = "openai.chat.completions.create" - OPENAI_COMPLETIONS_CREATE = "openai.completions.create" - OPENAI_COMPLETION_ACREATE = "openai.Completion.acreate" - OPENAI_COMPLETION_CREATE = "openai.Completion.create" - - def __str__(self) -> str: - return str(self.value) diff --git a/open-api-spec.yml b/open-api-spec.yml index db07370..0fa421d 100644 --- a/open-api-spec.yml +++ b/open-api-spec.yml @@ -763,6 +763,25 @@ components: oneOf: - $ref: "#/components/schemas/AnyObject" - $ref: "#/components/schemas/AnyPrimitive" + LlmApi: + type: string + oneOf: + - title: OPENAI_V0_COMPLETION_CREATE + const: openai.Completion.create + - title: OPENAI_V1_COMPLETION_CREATE + const: openai.completions.create + - title: OPENAI_V0_CHAT_COMPLETION_CREATE + const: openai.ChatCompletion.create + - title: OPENAI_V1_CHAT_COMPLETION_CREATE + const: openai.chat.completions.create + - title: OPENAI_V0_COMPLETION_ASYNC_CREATE + const: openai.Completion.acreate + - title: OPENAI_V0_CHAT_COMPLETION_ASYNC_CREATE + const: openai.ChatCompletion.acreate + - title: LITELLM_COMPLETION + const: litellm.completion + - title: LITELLM_ASYNC_COMPLETION + const: litellm.acompletion ValidatePayload: type: object properties: @@ -779,8 +798,7 @@ components: properties: {} additionalProperties: {} llmApi: - type: string - enum: ["openai.Completion.create", "openai.completions.create", "openai.ChatCompletion.create", "openai.chat.completions.create", "openai.Completion.acreate", "openai.ChatCompletion.acreate", "litellm.completion", "litellm.acompletion"] + $ref: "#/components/schemas/LlmApi" additionalProperties: {} Ingestion: type: object From 0c760681b3d36f42a2bb338aa643bfe7b3752883 Mon Sep 17 00:00:00 2001 From: Caleb Courier Date: Tue, 16 Apr 2024 10:25:36 -0500 Subject: [PATCH 07/10] add descriptions --- service-specs/guardrails-service-spec.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/service-specs/guardrails-service-spec.yml b/service-specs/guardrails-service-spec.yml index 58ac22a..33e7de9 100644 --- a/service-specs/guardrails-service-spec.yml +++ b/service-specs/guardrails-service-spec.yml @@ -478,20 +478,28 @@ components: oneOf: - title: OPENAI_V0_COMPLETION_CREATE const: openai.Completion.create - - title: OPENAI_V1_COMPLETION_CREATE + description: OpenAI V0 Completion Create + - title: OPENAI_V1_COMPLETIONS_CREATE const: openai.completions.create + description: OpenAI V1 Completions Create - title: OPENAI_V0_CHAT_COMPLETION_CREATE const: openai.ChatCompletion.create + description: OpenAI V0 Chat Completion Create - title: OPENAI_V1_CHAT_COMPLETION_CREATE const: openai.chat.completions.create + description: OpenAI V1 Chat Completions Create - title: OPENAI_V0_COMPLETION_ASYNC_CREATE const: openai.Completion.acreate + description: OpenAI V0 Completion Async Create - title: OPENAI_V0_CHAT_COMPLETION_ASYNC_CREATE const: openai.ChatCompletion.acreate + description: OpenAI V0 Chat Completion Async Create - title: LITELLM_COMPLETION const: litellm.completion + description: LiteLLM Completion - title: LITELLM_ASYNC_COMPLETION const: litellm.acompletion + description: LiteLLM Async Completion ValidatePayload: type: object properties: From a82d067c805babafec375194b276c1e595d38a3c Mon Sep 17 00:00:00 2001 From: CalebCourier Date: Tue, 16 Apr 2024 15:26:02 +0000 Subject: [PATCH 08/10] update generated sdk --- open-api-spec.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/open-api-spec.yml b/open-api-spec.yml index 0fa421d..98168d3 100644 --- a/open-api-spec.yml +++ b/open-api-spec.yml @@ -768,20 +768,28 @@ components: oneOf: - title: OPENAI_V0_COMPLETION_CREATE const: openai.Completion.create - - title: OPENAI_V1_COMPLETION_CREATE + description: OpenAI V0 Completion Create + - title: OPENAI_V1_COMPLETIONS_CREATE const: openai.completions.create + description: OpenAI V1 Completions Create - title: OPENAI_V0_CHAT_COMPLETION_CREATE const: openai.ChatCompletion.create + description: OpenAI V0 Chat Completion Create - title: OPENAI_V1_CHAT_COMPLETION_CREATE const: openai.chat.completions.create + description: OpenAI V1 Chat Completions Create - title: OPENAI_V0_COMPLETION_ASYNC_CREATE const: openai.Completion.acreate + description: OpenAI V0 Completion Async Create - title: OPENAI_V0_CHAT_COMPLETION_ASYNC_CREATE const: openai.ChatCompletion.acreate + description: OpenAI V0 Chat Completion Async Create - title: LITELLM_COMPLETION const: litellm.completion + description: LiteLLM Completion - title: LITELLM_ASYNC_COMPLETION const: litellm.acompletion + description: LiteLLM Async Completion ValidatePayload: type: object properties: From f1e677400a7417d3438205a5c0386e75a4258e1b Mon Sep 17 00:00:00 2001 From: Caleb Courier Date: Tue, 16 Apr 2024 10:30:40 -0500 Subject: [PATCH 09/10] revert to enum bc the generated code is more usable --- service-specs/guardrails-service-spec.yml | 40 +++++++---------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/service-specs/guardrails-service-spec.yml b/service-specs/guardrails-service-spec.yml index 33e7de9..73ef2fb 100644 --- a/service-specs/guardrails-service-spec.yml +++ b/service-specs/guardrails-service-spec.yml @@ -473,33 +473,6 @@ components: oneOf: - $ref: "#/components/schemas/AnyObject" - $ref: "#/components/schemas/AnyPrimitive" - LlmApi: - type: string - oneOf: - - title: OPENAI_V0_COMPLETION_CREATE - const: openai.Completion.create - description: OpenAI V0 Completion Create - - title: OPENAI_V1_COMPLETIONS_CREATE - const: openai.completions.create - description: OpenAI V1 Completions Create - - title: OPENAI_V0_CHAT_COMPLETION_CREATE - const: openai.ChatCompletion.create - description: OpenAI V0 Chat Completion Create - - title: OPENAI_V1_CHAT_COMPLETION_CREATE - const: openai.chat.completions.create - description: OpenAI V1 Chat Completions Create - - title: OPENAI_V0_COMPLETION_ASYNC_CREATE - const: openai.Completion.acreate - description: OpenAI V0 Completion Async Create - - title: OPENAI_V0_CHAT_COMPLETION_ASYNC_CREATE - const: openai.ChatCompletion.acreate - description: OpenAI V0 Chat Completion Async Create - - title: LITELLM_COMPLETION - const: litellm.completion - description: LiteLLM Completion - - title: LITELLM_ASYNC_COMPLETION - const: litellm.acompletion - description: LiteLLM Async Completion ValidatePayload: type: object properties: @@ -516,5 +489,16 @@ components: properties: {} additionalProperties: {} llmApi: - $ref: "#/components/schemas/LlmApi" + type: string + enum: + [ + "openai.Completion.create", + "openai.completions.create", + "openai.ChatCompletion.create", + "openai.chat.completions.create", + "openai.Completion.acreate", + "openai.ChatCompletion.acreate", + "litellm.completion", + "litellm.acompletion" + ] additionalProperties: {} From 263c0f1be44dbf273d6f834e79682c08fee8946e Mon Sep 17 00:00:00 2001 From: CalebCourier Date: Tue, 16 Apr 2024 15:31:07 +0000 Subject: [PATCH 10/10] update generated sdk --- .../guardrails_api_client/models/__init__.py | 2 + .../models/validate_payload.py | 75 ++++--------------- .../models/validate_payload_llm_api.py | 15 ++++ open-api-spec.yml | 30 +------- 4 files changed, 32 insertions(+), 90 deletions(-) create mode 100644 guardrails-api-client/guardrails_api_client/models/validate_payload_llm_api.py diff --git a/guardrails-api-client/guardrails_api_client/models/__init__.py b/guardrails-api-client/guardrails_api_client/models/__init__.py index e9ab0c5..4431d6d 100644 --- a/guardrails-api-client/guardrails_api_client/models/__init__.py +++ b/guardrails-api-client/guardrails_api_client/models/__init__.py @@ -33,6 +33,7 @@ from .schema_element import SchemaElement from .status import Status from .validate_payload import ValidatePayload +from .validate_payload_llm_api import ValidatePayloadLlmApi from .validate_payload_prompt_params import ValidatePayloadPromptParams from .validation_output import ValidationOutput from .validator_metrics import ValidatorMetrics @@ -74,6 +75,7 @@ "SchemaElement", "Status", "ValidatePayload", + "ValidatePayloadLlmApi", "ValidatePayloadPromptParams", "ValidationOutput", "ValidatorMetrics", diff --git a/guardrails-api-client/guardrails_api_client/models/validate_payload.py b/guardrails-api-client/guardrails_api_client/models/validate_payload.py index e1eb3cf..108baf7 100644 --- a/guardrails-api-client/guardrails_api_client/models/validate_payload.py +++ b/guardrails-api-client/guardrails_api_client/models/validate_payload.py @@ -1,8 +1,9 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Literal, Type, TypeVar, Union, cast +from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union from attrs import define as _attrs_define from attrs import field as _attrs_field +from ..models.validate_payload_llm_api import ValidatePayloadLlmApi from ..types import UNSET, Unset if TYPE_CHECKING: @@ -20,26 +21,13 @@ class ValidatePayload: output. num_reasks (Union[Unset, int]): An override for the number of re-asks to perform prompt_params (Union[Unset, ValidatePayloadPromptParams]): additional params for llm prompts - llm_api (Union[Literal['litellm.acompletion'], Literal['litellm.completion'], - Literal['openai.ChatCompletion.acreate'], Literal['openai.ChatCompletion.create'], - Literal['openai.Completion.acreate'], Literal['openai.Completion.create'], - Literal['openai.chat.completions.create'], Literal['openai.completions.create'], Unset]): + llm_api (Union[Unset, ValidatePayloadLlmApi]): """ llm_output: Union[Unset, str] = UNSET num_reasks: Union[Unset, int] = UNSET prompt_params: Union[Unset, "ValidatePayloadPromptParams"] = UNSET - llm_api: Union[ - Literal["litellm.acompletion"], - Literal["litellm.completion"], - Literal["openai.ChatCompletion.acreate"], - Literal["openai.ChatCompletion.create"], - Literal["openai.Completion.acreate"], - Literal["openai.Completion.create"], - Literal["openai.chat.completions.create"], - Literal["openai.completions.create"], - Unset, - ] = UNSET + llm_api: Union[Unset, ValidatePayloadLlmApi] = UNSET additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: @@ -51,21 +39,9 @@ def to_dict(self) -> Dict[str, Any]: if not isinstance(self.prompt_params, Unset): prompt_params = self.prompt_params.to_dict() - llm_api: Union[ - Literal["litellm.acompletion"], - Literal["litellm.completion"], - Literal["openai.ChatCompletion.acreate"], - Literal["openai.ChatCompletion.create"], - Literal["openai.Completion.acreate"], - Literal["openai.Completion.create"], - Literal["openai.chat.completions.create"], - Literal["openai.completions.create"], - Unset, - ] - if isinstance(self.llm_api, Unset): - llm_api = UNSET - else: - llm_api = self.llm_api + llm_api: Union[Unset, str] = UNSET + if not isinstance(self.llm_api, Unset): + llm_api = self.llm_api.value field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) @@ -97,37 +73,12 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: else: prompt_params = ValidatePayloadPromptParams.from_dict(_prompt_params) - def _parse_llm_api( - data: object, - ) -> Union[ - Literal["litellm.acompletion"], - Literal["litellm.completion"], - Literal["openai.ChatCompletion.acreate"], - Literal["openai.ChatCompletion.create"], - Literal["openai.Completion.acreate"], - Literal["openai.Completion.create"], - Literal["openai.chat.completions.create"], - Literal["openai.completions.create"], - Unset, - ]: - if isinstance(data, Unset): - return data - return cast( - Union[ - Literal["litellm.acompletion"], - Literal["litellm.completion"], - Literal["openai.ChatCompletion.acreate"], - Literal["openai.ChatCompletion.create"], - Literal["openai.Completion.acreate"], - Literal["openai.Completion.create"], - Literal["openai.chat.completions.create"], - Literal["openai.completions.create"], - Unset, - ], - data, - ) - - llm_api = _parse_llm_api(d.pop("llmApi", UNSET)) + _llm_api = d.pop("llmApi", UNSET) + llm_api: Union[Unset, ValidatePayloadLlmApi] + if isinstance(_llm_api, Unset): + llm_api = UNSET + else: + llm_api = ValidatePayloadLlmApi(_llm_api) validate_payload = cls( llm_output=llm_output, diff --git a/guardrails-api-client/guardrails_api_client/models/validate_payload_llm_api.py b/guardrails-api-client/guardrails_api_client/models/validate_payload_llm_api.py new file mode 100644 index 0000000..f4c203f --- /dev/null +++ b/guardrails-api-client/guardrails_api_client/models/validate_payload_llm_api.py @@ -0,0 +1,15 @@ +from enum import Enum + + +class ValidatePayloadLlmApi(str, Enum): + LITELLM_ACOMPLETION = "litellm.acompletion" + LITELLM_COMPLETION = "litellm.completion" + OPENAI_CHATCOMPLETION_ACREATE = "openai.ChatCompletion.acreate" + OPENAI_CHATCOMPLETION_CREATE = "openai.ChatCompletion.create" + OPENAI_CHAT_COMPLETIONS_CREATE = "openai.chat.completions.create" + OPENAI_COMPLETIONS_CREATE = "openai.completions.create" + OPENAI_COMPLETION_ACREATE = "openai.Completion.acreate" + OPENAI_COMPLETION_CREATE = "openai.Completion.create" + + def __str__(self) -> str: + return str(self.value) diff --git a/open-api-spec.yml b/open-api-spec.yml index 98168d3..db07370 100644 --- a/open-api-spec.yml +++ b/open-api-spec.yml @@ -763,33 +763,6 @@ components: oneOf: - $ref: "#/components/schemas/AnyObject" - $ref: "#/components/schemas/AnyPrimitive" - LlmApi: - type: string - oneOf: - - title: OPENAI_V0_COMPLETION_CREATE - const: openai.Completion.create - description: OpenAI V0 Completion Create - - title: OPENAI_V1_COMPLETIONS_CREATE - const: openai.completions.create - description: OpenAI V1 Completions Create - - title: OPENAI_V0_CHAT_COMPLETION_CREATE - const: openai.ChatCompletion.create - description: OpenAI V0 Chat Completion Create - - title: OPENAI_V1_CHAT_COMPLETION_CREATE - const: openai.chat.completions.create - description: OpenAI V1 Chat Completions Create - - title: OPENAI_V0_COMPLETION_ASYNC_CREATE - const: openai.Completion.acreate - description: OpenAI V0 Completion Async Create - - title: OPENAI_V0_CHAT_COMPLETION_ASYNC_CREATE - const: openai.ChatCompletion.acreate - description: OpenAI V0 Chat Completion Async Create - - title: LITELLM_COMPLETION - const: litellm.completion - description: LiteLLM Completion - - title: LITELLM_ASYNC_COMPLETION - const: litellm.acompletion - description: LiteLLM Async Completion ValidatePayload: type: object properties: @@ -806,7 +779,8 @@ components: properties: {} additionalProperties: {} llmApi: - $ref: "#/components/schemas/LlmApi" + type: string + enum: ["openai.Completion.create", "openai.completions.create", "openai.ChatCompletion.create", "openai.chat.completions.create", "openai.Completion.acreate", "openai.ChatCompletion.acreate", "litellm.completion", "litellm.acompletion"] additionalProperties: {} Ingestion: type: object