mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-12-16 17:48:19 +00:00
build: add jsonschema library to core dependencies (#8753)
* add jsonschema to core dependencies * release note
This commit is contained in:
parent
542a7f7ef5
commit
2bf6bf6a45
@ -5,12 +5,10 @@
|
|||||||
import json
|
import json
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
|
from jsonschema import ValidationError, validate
|
||||||
|
|
||||||
from haystack import component
|
from haystack import component
|
||||||
from haystack.dataclasses import ChatMessage
|
from haystack.dataclasses import ChatMessage
|
||||||
from haystack.lazy_imports import LazyImport
|
|
||||||
|
|
||||||
with LazyImport(message="Run 'pip install jsonschema'") as jsonschema_import:
|
|
||||||
from jsonschema import ValidationError, validate
|
|
||||||
|
|
||||||
|
|
||||||
def is_valid_json(s: str) -> bool:
|
def is_valid_json(s: str) -> bool:
|
||||||
@ -110,7 +108,6 @@ class JsonSchemaValidator:
|
|||||||
the messages' content is validated.
|
the messages' content is validated.
|
||||||
:param error_template: A custom template string for formatting the error message in case of validation failure.
|
:param error_template: A custom template string for formatting the error message in case of validation failure.
|
||||||
"""
|
"""
|
||||||
jsonschema_import.check()
|
|
||||||
self.json_schema = json_schema
|
self.json_schema = json_schema
|
||||||
self.error_template = error_template
|
self.error_template = error_template
|
||||||
|
|
||||||
|
|||||||
@ -5,15 +5,13 @@
|
|||||||
from dataclasses import asdict, dataclass
|
from dataclasses import asdict, dataclass
|
||||||
from typing import Any, Callable, Dict, List, Optional
|
from typing import Any, Callable, Dict, List, Optional
|
||||||
|
|
||||||
|
from jsonschema import Draft202012Validator
|
||||||
|
from jsonschema.exceptions import SchemaError
|
||||||
|
|
||||||
from haystack.core.serialization import generate_qualified_class_name, import_class_by_name
|
from haystack.core.serialization import generate_qualified_class_name, import_class_by_name
|
||||||
from haystack.lazy_imports import LazyImport
|
|
||||||
from haystack.tools.errors import ToolInvocationError
|
from haystack.tools.errors import ToolInvocationError
|
||||||
from haystack.utils import deserialize_callable, serialize_callable
|
from haystack.utils import deserialize_callable, serialize_callable
|
||||||
|
|
||||||
with LazyImport(message="Run 'pip install jsonschema'") as jsonschema_import:
|
|
||||||
from jsonschema import Draft202012Validator
|
|
||||||
from jsonschema.exceptions import SchemaError
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Tool:
|
class Tool:
|
||||||
@ -39,7 +37,6 @@ class Tool:
|
|||||||
function: Callable
|
function: Callable
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
jsonschema_import.check()
|
|
||||||
# Check that the parameters define a valid JSON schema
|
# Check that the parameters define a valid JSON schema
|
||||||
try:
|
try:
|
||||||
Draft202012Validator.check_schema(self.parameters)
|
Draft202012Validator.check_schema(self.parameters)
|
||||||
|
|||||||
@ -57,6 +57,7 @@ dependencies = [
|
|||||||
"requests",
|
"requests",
|
||||||
"numpy",
|
"numpy",
|
||||||
"python-dateutil",
|
"python-dateutil",
|
||||||
|
"jsonschema", # JsonSchemaValidator, Tool
|
||||||
"haystack-experimental",
|
"haystack-experimental",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -116,9 +117,6 @@ extra-dependencies = [
|
|||||||
"jsonref", # OpenAPIServiceConnector, OpenAPIServiceToFunctions
|
"jsonref", # OpenAPIServiceConnector, OpenAPIServiceToFunctions
|
||||||
"openapi3",
|
"openapi3",
|
||||||
|
|
||||||
# JsonSchemaValidator, Tool
|
|
||||||
"jsonschema",
|
|
||||||
|
|
||||||
# Tracing
|
# Tracing
|
||||||
"opentelemetry-sdk",
|
"opentelemetry-sdk",
|
||||||
"ddtrace",
|
"ddtrace",
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
enhancements:
|
||||||
|
- |
|
||||||
|
Add jsonschema library as a core dependency. It is used in Tool and JsonSchemaValidator.
|
||||||
Loading…
x
Reference in New Issue
Block a user