L5-tools-routing-apis-student: erroneous imports-2?

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.

Are you doing this assignment in your local jupyter environment?

Yas, am running them on my local laptop > VSCode > .jpynb files (Jupyter Notebooks).

Did you downloaded all the files required to do this assignment?

The solutions you are providing based on your local Jupyter environment.

these imports errors are because of these difference in your Jupyter envrionment and discourse supported assignment.

Yes. I downloaded them.
I also hand-code them as I follow the vidoe and code.

That’s great @mtadanki, kindly when you are creating such topic, include in Sub-Header: Solution to run in your local jupyter environment or Header stating Solution on how to run assignment if you encounter import error in local Jupyter notebook. This will be more helpful.

Thank you

Regards
DP

Sure DP. I will do that in future.