feat(vertex_ai_anthropic.py): support response_schema for vertex ai anthropic calls

allows passing response_schema for anthropic calls. supports schema validation.
This commit is contained in:
Krrish Dholakia 2024-07-18 16:57:38 -07:00
parent 432b7ae264
commit aac912d3f8
6 changed files with 189 additions and 48 deletions

View file

@ -13,7 +13,12 @@ def validate_schema(schema: dict, response: str):
from litellm import JSONSchemaValidationError
response_dict = json.loads(response)
try:
response_dict = json.loads(response)
except json.JSONDecodeError:
raise JSONSchemaValidationError(
model="", llm_provider="", raw_response=response, schema=response
)
try:
validate(response_dict, schema=schema)