Open elliexcoding opened 10 months ago
🤖
Hello,
The error you're encountering, 'super' object has no attribute 'parse_obj'
, is likely due to the fact that the 'parse_obj' method is not available in the superclass of 'OpenAPISpec'.
In LangChain, 'OpenAPISpec' is a subclass of 'OpenAPI', which is imported from the 'openapi_schema_pydantic' package. The 'parse_obj' method is called on the superclass in the 'parse_obj' method of 'OpenAPISpec':
@classmethod
def parse_obj(cls, obj: dict) -> OpenAPISpec:
try:
cls._alert_unsupported_spec(obj)
return super().parse_obj(obj)
except ValidationError as e:
# We are handling possibly misconfigured specs and
# want to do a best-effort job to get a reasonable interface out of it.
new_obj = copy.deepcopy(obj)
for error in e.errors():
keys = error["loc"]
item = new_obj
for key in keys[:-1]:
item = item[key]
item.pop(keys[-1], None)
return cls.parse_obj(new_obj)
The error suggests that the 'OpenAPI' class does not have a 'parse_obj' method. This could be due to a version mismatch between the 'openapi_schema_pydantic' package used in your environment and the one expected by LangChain.
LangChain v0.0.268 is compatible with the 'openapi_schema_pydantic' package version "^1.2". This means any version that is compatible with version 1.2. The caret (^) symbol in "^1.2" indicates compatibility with versions up to but not including 2.0.0. This information is found in the 'pyproject.toml' file under the '[tool.poetry.dependencies]' section:
openapi-schema-pydantic = {version = "^1.2", optional = true}
Please ensure that you have the correct version of 'openapi_schema_pydantic' installed. If the issue persists, it might be a bug in LangChain or 'openapi_schema_pydantic', and you should consider reporting it to the maintainers.
I hope this helps! Let me know if you have any other questions.
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
Also affecting
OpenAPISpec.from_url
get_openapi_chain
The get_openapi_chain
error is hidden, but I confirmed it's the same error as above.
File "/usr/local/lib/python3.11/site-packages/langchain/chains/openai_functions/openapi.py", line 272, in get_openapi_chain
raise ValueError(f"Unable to parse spec from source {spec}")
cc @baskaryan @eyurtsev
Tracked this regression to openapi-schema-pydantic
being switched to an optional dependency (https://github.com/langchain-ai/langchain/pull/9408).
install openapi-schema-pydantic
into your environment.
OpenAPISpec's
parent class defaults to object
when openapi-schema-pydantic
is unavailable.
This leads to an exception in OpenAPISpec.parse_obj
when it calls super().parse_obj()
.
Thanks for looking into it and figuring out a workaround @kreneskyp
Unfortunately for me installing openapi-schema-pydantic
didn't work
Having the same issue, installing openaiapi-schema-pydantic did not work. :(
Having the same issue, installing
openaiapi-schema-pydantic
did not work. :(
I ran into this issue again when using Pydantic 2.0 with LangChain.
Try langchain==0.0.319
with openapi-pydantic==0.3.2
. Hopefully fixes all the issues now!
Having the same issue, installing
openaiapi-schema-pydantic
did not work. :(I ran into this issue again when using Pydantic 2.0 with LangChain.
Try
langchain==0.0.319
withopenapi-pydantic==0.3.2
. Hopefully fixes all the issues now!
This resolved the issue for me, cheers!
openapi_schema_pydantic is changed to: openapi-pydantic 0.3.2 (last version) install it when using langchain
openapi_schema_pydantic is changed to: openapi-pydantic 0.3.2 (last version) install it when using langchain
This works perfectly fine, thanks for the advise.
openapi_schema_pydantic is changed to: openapi-pydantic 0.3.2 (last version) install it when using langchain
This worked fine, thanks for the advise.
"pip install openapi-pydantic" fixed it for me
langchain 0.1.9 openapi-pydantic 0.4.0 Still having this issue
My colleague is facing the same issue on Python 3.10.12 and langchain==0.1.12 plus openapi-pydantic==0.4.0 (and also tried 0.3.2). On my PC, all is good with the same versions and Python. This is some random stuff.
openapi_schema_pydantic is changed to: openapi-pydantic 0.3.2 (last version) install it when using langchain
That solved my issue. Thanks. Note: (1) I also had to restart the kernel, (2) remove the imports from openapi_schema_pydantic, and (3) include imports from openapi-pydantic only. More details here: https://community.deeplearning.ai/t/attributeerror-super-object-has-no-attribute-parse-obj/481376/11
Thanks, @ChanduTadanki for reminding me to restart kernel. That was the last step to get things working for me.
System Info
Langchain version 0.0.268
Who can help?
No response
Information
Related Components
Reproduction
open_api_spec = OpenAPISpec.from_file(file_path)
Error shows that in openapi.py line 202 ,
return super().parse_obj(obj)
no longer inherits the super method from Pydantic's BaseModel parse_obj.Expected behavior
The OpenAPISpec should be delivered so that it can be passed on to
NLAToolkit.from_llm_and_spec
.