codingphun / gcp_graph_rag

9 stars 4 forks source link

'SafetySetting' is not defined #1

Open psk4998 opened 1 day ago

psk4998 commented 1 day ago

NameError: name 'SafetySetting' is not defined

The above exception was the direct cause of the following exception:

PydanticUndefinedAnnotation Traceback (most recent call last) Cell In[1], line 3 1 import os 2 from langchain_experimental.graph_transformers import LLMGraphTransformer ----> 3 from langchain_google_vertexai import VertexAI 4 import networkx as nx 5 from langchain.chains import GraphQAChain

File /opt/conda/lib/python3.10/site-packages/langchain_google_vertexai/init.py:16 14 from langchain_google_vertexai.chains import create_structured_runnable 15 from langchain_google_vertexai.chat_models import ChatVertexAI ---> 16 from langchain_google_vertexai.embeddings import VertexAIEmbeddings 17 from langchain_google_vertexai.evaluators.evaluation import ( 18 VertexPairWiseStringEvaluator, 19 VertexStringEvaluator, 20 ) 21 from langchain_google_vertexai.functions_utils import ( 22 PydanticFunctionsOutputParser, 23 )

File /opt/conda/lib/python3.10/site-packages/langchain_google_vertexai/embeddings.py:502 496 result: MultiModalEmbeddingResponse = self.instance[ 497 "get_embeddings_with_retry" 498 ](image=image, contextual_text=contextual_text, dimension=dimensions) 499 return result.image_embedding --> 502 VertexAIEmbeddings.model_rebuild()

File /opt/conda/lib/python3.10/site-packages/pydantic/main.py:589, in BaseModel.model_rebuild(cls, force, raise_errors, _parent_namespace_depth, _types_namespace) 587 # manually override defer_build so complete_model_class doesn't skip building the model again 588 config = {**cls.model_config, 'defer_build': False} --> 589 return _model_construction.complete_model_class( 590 cls, 591 cls.name, 592 _config.ConfigWrapper(config, check=False), 593 raise_errors=raise_errors, 594 ns_resolver=ns_resolver, 595 )

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py:658, in complete_model_class(cls, cls_name, config_wrapper, raise_errors, ns_resolver, create_model_module) 651 handler = CallbackGetCoreSchemaHandler( 652 partial(gen_schema.generate_schema, from_dunder_get_core_schema=False), 653 gen_schema, 654 ref_mode='unpack', 655 ) 657 try: --> 658 schema = cls.__get_pydantic_core_schema__(cls, handler) 659 except PydanticUndefinedAnnotation as e: 660 if ra

psk4998 commented 1 day ago

NameError Traceback (most recent call last) File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:815, in GenerateSchema._resolve_forward_ref(self, obj) 814 try: --> 815 obj = _typing_extra.eval_type_backport(obj, *self._types_namespace) 816 except NameError as e:

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_typing_extra.py:534, in eval_type_backport(value, globalns, localns, type_params) 533 try: --> 534 return _eval_type_backport(value, globalns, localns, type_params) 535 except TypeError as e:

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_typing_extra.py:558, in _eval_type_backport(value, globalns, localns, type_params) 557 try: --> 558 return _eval_type(value, globalns, localns, type_params) 559 except TypeError as e:

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_typing_extra.py:592, in _eval_type(value, globalns, localns, type_params) 591 else: --> 592 return typing._eval_type( # type: ignore 593 value, globalns, localns 594 )

File /opt/conda/lib/python3.10/typing.py:327, in _eval_type(t, globalns, localns, recursive_guard) 326 if isinstance(t, ForwardRef): --> 327 return t._evaluate(globalns, localns, recursive_guard) 328 if isinstance(t, (_GenericAlias, GenericAlias, types.UnionType)):

File /opt/conda/lib/python3.10/typing.py:699, in ForwardRef._evaluate(self, globalns, localns, recursiveguard) 693 type = _type_check( 694 eval(self.forward_code__, globalns, localns), 695 "Forward references must evaluate to types.", 696 is_argument=self.forward_is_argument, 697 allow_special_forms=self.forward_is_class, 698 ) --> 699 self.forward_value = _evaltype( 700 type, globalns, localns, recursive_guard | {self.forward_arg} 701 ) 702 self.forward_evaluated__ = True

File /opt/conda/lib/python3.10/typing.py:329, in _eval_type(t, globalns, localns, recursive_guard) 328 if isinstance(t, (_GenericAlias, GenericAlias, types.UnionType)): --> 329 ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.args) 330 if ev_args == t.args:

File /opt/conda/lib/python3.10/typing.py:329, in (.0) 328 if isinstance(t, (_GenericAlias, GenericAlias, types.UnionType)): --> 329 ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.args) 330 if ev_args == t.args:

File /opt/conda/lib/python3.10/typing.py:327, in _eval_type(t, globalns, localns, recursive_guard) 326 if isinstance(t, ForwardRef): --> 327 return t._evaluate(globalns, localns, recursive_guard) 328 if isinstance(t, (_GenericAlias, GenericAlias, types.UnionType)):

File /opt/conda/lib/python3.10/typing.py:699, in ForwardRef._evaluate(self, globalns, localns, recursiveguard) 693 type = _type_check( 694 eval(self.forward_code__, globalns, localns), 695 "Forward references must evaluate to types.", 696 is_argument=self.forward_is_argument, 697 allow_special_forms=self.forward_is_class, 698 ) --> 699 self.forward_value = _evaltype( 700 type, globalns, localns, recursive_guard | {self.forward_arg} 701 ) 702 self.forward_evaluated__ = True

File /opt/conda/lib/python3.10/typing.py:329, in _eval_type(t, globalns, localns, recursive_guard) 328 if isinstance(t, (_GenericAlias, GenericAlias, types.UnionType)): --> 329 ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.args) 330 if ev_args == t.args:

File /opt/conda/lib/python3.10/typing.py:329, in (.0) 328 if isinstance(t, (_GenericAlias, GenericAlias, types.UnionType)): --> 329 ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.args) 330 if ev_args == t.args:

File /opt/conda/lib/python3.10/typing.py:329, in _eval_type(t, globalns, localns, recursive_guard) 328 if isinstance(t, (_GenericAlias, GenericAlias, types.UnionType)): --> 329 ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.args) 330 if ev_args == t.args:

File /opt/conda/lib/python3.10/typing.py:329, in (.0) 328 if isinstance(t, (_GenericAlias, GenericAlias, types.UnionType)): --> 329 ev_args = tuple(_eval_type(a, globalns, localns, recursive_guard) for a in t.args) 330 if ev_args == t.args:

File /opt/conda/lib/python3.10/typing.py:327, in _eval_type(t, globalns, localns, recursive_guard) 326 if isinstance(t, ForwardRef): --> 327 return t._evaluate(globalns, localns, recursive_guard) 328 if isinstance(t, (_GenericAlias, GenericAlias, types.UnionType)):

File /opt/conda/lib/python3.10/typing.py:694, in ForwardRef._evaluate(self, globalns, localns, recursive_guard) 690 globalns = getattr( 691 sys.modules.get(self.forward_module, None), 'dict_', globalns 692 ) 693 type = _type_check( --> 694 eval(self.forward_code, globalns, localns), 695 "Forward references must evaluate to types.", 696 is_argument=self.forward_is_argument, 697 allow_special_forms=self.forward_is_class, 698 ) 699 self.__forward_value = _evaltype( 700 type, globalns, localns, recursive_guard | {self.__forward_arg__} 701 )

File :1

NameError: name 'SafetySetting' is not defined

The above exception was the direct cause of the following exception:

PydanticUndefinedAnnotation Traceback (most recent call last) Cell In[1], line 3 1 import os 2 from langchain_experimental.graph_transformers import LLMGraphTransformer ----> 3 from langchain_google_vertexai import VertexAI 4 import networkx as nx 5 from langchain.chains import GraphQAChain

File /opt/conda/lib/python3.10/site-packages/langchain_google_vertexai/init.py:16 14 from langchain_google_vertexai.chains import create_structured_runnable 15 from langchain_google_vertexai.chat_models import ChatVertexAI ---> 16 from langchain_google_vertexai.embeddings import VertexAIEmbeddings 17 from langchain_google_vertexai.evaluators.evaluation import ( 18 VertexPairWiseStringEvaluator, 19 VertexStringEvaluator, 20 ) 21 from langchain_google_vertexai.functions_utils import ( 22 PydanticFunctionsOutputParser, 23 )

File /opt/conda/lib/python3.10/site-packages/langchain_google_vertexai/embeddings.py:502 496 result: MultiModalEmbeddingResponse = self.instance[ 497 "get_embeddings_with_retry" 498 ](image=image, contextual_text=contextual_text, dimension=dimensions) 499 return result.image_embedding --> 502 VertexAIEmbeddings.model_rebuild()

File /opt/conda/lib/python3.10/site-packages/pydantic/main.py:589, in BaseModel.model_rebuild(cls, force, raise_errors, _parent_namespace_depth, _types_namespace) 587 # manually override defer_build so complete_model_class doesn't skip building the model again 588 config = {**cls.model_config, 'defer_build': False} --> 589 return _model_construction.complete_model_class( 590 cls, 591 cls.name, 592 _config.ConfigWrapper(config, check=False), 593 raise_errors=raise_errors, 594 ns_resolver=ns_resolver, 595 )

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py:658, in complete_model_class(cls, cls_name, config_wrapper, raise_errors, ns_resolver, create_model_module) 651 handler = CallbackGetCoreSchemaHandler( 652 partial(gen_schema.generate_schema, from_dunder_get_core_schema=False), 653 gen_schema, 654 ref_mode='unpack', 655 ) 657 try: --> 658 schema = cls.__get_pydantic_core_schema__(cls, handler) 659 except PydanticUndefinedAnnotation as e: 660 if raise_errors:

File /opt/conda/lib/python3.10/site-packages/pydantic/main.py:697, in BaseModel.__get_pydantic_core_schema(cls, source, handler) 694 if not cls.pydantic_generic_metadata['origin']: 695 return cls.pydantic_core_schema__ --> 697 return handler(source)

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py:84, in CallbackGetCoreSchemaHandler.call(self, source_type) 83 def call(self, source_type: Any, /) -> core_schema.CoreSchema: ---> 84 schema = self._handler(source_type) 85 ref = schema.get('ref') 86 if self._ref_mode == 'to-def':

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:612, in GenerateSchema.generate_schema(self, obj, from_dunder_get_core_schema) 609 schema = from_property 611 if schema is None: --> 612 schema = self._generate_schema_inner(obj) 614 metadata_js_function = _extract_get_pydantic_json_schema(obj, schema) 615 if metadata_js_function is not None:

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:881, in GenerateSchema._generate_schema_inner(self, obj) 879 if lenient_issubclass(obj, BaseModel): 880 with self.model_type_stack.push(obj): --> 881 return self._model_schema(obj) 883 if isinstance(obj, PydanticRecursiveRef): 884 return core_schema.definition_reference_schema(schema_ref=obj.type_ref)

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:693, in GenerateSchema._model_schema(self, cls) 681 model_schema = core_schema.model_schema( 682 cls, 683 inner_schema, (...) 689 ref=model_ref, 690 ) 691 else: 692 fields_schema: core_schema.CoreSchema = core_schema.model_fields_schema( --> 693 {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()}, 694 computed_fields=[ 695 self._computed_field_schema(d, decorators.field_serializers) 696 for d in computed_fields.values() 697 ], 698 extras_schema=extras_schema, 699 model_name=cls.name, 700 ) 701 inner_schema = apply_validators(fields_schema, decorators.root_validators.values(), None) 702 new_inner_schema = define_expected_missing_refs(inner_schema, recursively_defined_type_refs())

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:693, in (.0) 681 model_schema = core_schema.model_schema( 682 cls, 683 inner_schema, (...) 689 ref=model_ref, 690 ) 691 else: 692 fields_schema: core_schema.CoreSchema = core_schema.model_fields_schema( --> 693 {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()}, 694 computed_fields=[ 695 self._computed_field_schema(d, decorators.field_serializers) 696 for d in computed_fields.values() 697 ], 698 extras_schema=extras_schema, 699 model_name=cls.name, 700 ) 701 inner_schema = apply_validators(fields_schema, decorators.root_validators.values(), None) 702 new_inner_schema = define_expected_missing_refs(inner_schema, recursively_defined_type_refs())

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:1073, in GenerateSchema._generate_md_field_schema(self, name, field_info, decorators) 1066 def _generate_md_field_schema( 1067 self, 1068 name: str, 1069 field_info: FieldInfo, 1070 decorators: DecoratorInfos, 1071 ) -> core_schema.ModelField: 1072 """Prepare a ModelField to represent a model field.""" -> 1073 common_field = self._common_field_schema(name, field_info, decorators) 1074 return core_schema.model_field( 1075 common_field['schema'], 1076 serialization_exclude=common_field['serialization_exclude'], (...) 1080 metadata=common_field['metadata'], 1081 )

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:1261, in GenerateSchema._common_field_schema(self, name, field_info, decorators) 1257 schema = self._apply_annotations( 1258 source_type, annotations + validators_from_decorators, transform_inner_schema=set_discriminator 1259 ) 1260 else: -> 1261 schema = self._apply_annotations( 1262 source_type, 1263 annotations + validators_from_decorators, 1264 ) 1266 # This V1 compatibility shim should eventually be removed 1267 # push down any each_item=True validators 1268 # note that this won't work for any Annotated types that get wrapped by a function validator 1269 # but that's okay because that didn't exist in V1 1270 this_field_validators = filter_field_decorator_info_by_field(decorators.validators.values(), name)

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:2051, in GenerateSchema._apply_annotations(self, source_type, annotations, transform_inner_schema) 2046 continue 2047 get_inner_schema = self._get_wrapped_inner_schema( 2048 get_inner_schema, annotation, pydantic_js_annotation_functions 2049 ) -> 2051 schema = get_inner_schema(source_type) 2052 if pydantic_js_annotation_functions: 2053 core_metadata = schema.setdefault('metadata', {})

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py:84, in CallbackGetCoreSchemaHandler.call(self, source_type) 83 def call(self, source_type: Any, /) -> core_schema.CoreSchema: ---> 84 schema = self._handler(source_type) 85 ref = schema.get('ref') 86 if self._ref_mode == 'to-def':

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:2032, in GenerateSchema._apply_annotations..inner_handler(obj) 2030 from_property = self._generate_schema_from_property(obj, source_type) 2031 if from_property is None: -> 2032 schema = self._generate_schema_inner(obj) 2033 else: 2034 schema = from_property

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:875, in GenerateSchema._generate_schema_inner(self, obj) 872 obj = ForwardRef(obj) 874 if isinstance(obj, ForwardRef): --> 875 return self.generate_schema(self._resolve_forward_ref(obj)) 877 BaseModel = import_cached_base_model() 879 if lenient_issubclass(obj, BaseModel):

File /opt/conda/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py:817, in GenerateSchema._resolve_forward_ref(self, obj) 815 obj = _typing_extra.eval_type_backport(obj, *self._types_namespace) 816 except NameError as e: --> 817 raise PydanticUndefinedAnnotation.from_name_error(e) from e 819 # if obj is still a ForwardRef, it means we can't evaluate it, raise PydanticUndefinedAnnotation 820 if isinstance(obj, ForwardRef):

PydanticUndefinedAnnotation: name 'SafetySetting' is not defined

For further information visit https://errors.pydantic.dev/2.10/u/undefined-annotation