1. Erring Code: Instructor’s code (video 8:40, search_wikipedia()
) that errs for me is:
from langchain.chains.openai_functions.openapi import openapi_spec_to_openai_fn
from langchain.utilities.openapi import OpenAPISpec
text = “”"
…
“”"
spec = OpenAPISpec.from_text(text)
1.1. Error: it is same as reported at: AttributeError: 'super' object has no attribute 'parse_obj' which talks of the error: AttributeError: ‘super’ object has no attribute ‘parse_obj’
. I also added my solution there.
2. Solution Step-1: as noted in the above community posting, we should add an import as:
from openapi_schema_pydantic import OpenAPI, Info, PathItem, Operation, Response
2.1. New Errors in Solution Step-1: this gives a new error as: PydanticUserError: const is removed, use Literal instead. For further information visit https://docs.pydantic.dev/2.6/errors/usage_errors/#removed-kwargs
3. Solution Step-2: Per this post: AttributeError: 'super' object has no attribute 'parse_obj' when using OpenAPISpec.from_file · Issue #9520 · langchain-ai/langchain · GitHub, openapi_schema_pydantic
is changed to: openapi-pydantic (0.3.2)
. So, my solution steps are: (1) restart the kernel, (2) remove the imports from openapi_schema_pydantic
, and (3) include imports from openapi-pydantic
only.
3.1. My Solution Code: the final code that worked for me is:
from langchain.chains.openai_functions.openapi import openapi_spec_to_openai_fn
from langchain.utilities.openapi import OpenAPISpec
from openapi_pydantic import OpenAPI, Info, PathItem, Operation, Response
text = “”"
…
“”"
spec = OpenAPISpec.from_text(text)
4. Overall Comments: the libraries are changing fast since the course was developed (Jul-2023?). It is hard to keep track of what worked then, but fails now, and what are their solutions.
4.1. Suggestion: the Community should not be a standalone and disconnected one. The course and code should have direct links taking us to community discussions. That makes the discussions very contextual.