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

Insructor’s code gave me error (TypeError: BaseModel expected). I did some research and thereby imported different libraries - that worked for me.

1 Instructor’s code:

from pydantic import BaseModel, Field

class SearchInput(BaseModel):
query: str = Field(description=“Thing to search for”

@tool(args_schema=SearchInput) # E1.0: error: this expects BaseModel type input thereby TypeError. Why?
def search(query: str) → str:
“”“Search for the weather online.”“”
return “42f”

2 My research: worked backwadrs from the error (E1.0: error → E1.1. → E1.2 → E1.3) … that’s how I made changes to the code which finally worked for me.

3 My modified code (“imports” only):

from langchain.pydantic_v1 import BaseModel, Field
from langchain.tools import BaseTool, StructuredTool, tool
‘’’
instructor code imports: from pydantic import BaseModel, Field
E1.2: is this the cause of errors? Instructor code is from Jul-2023. Things have changed from them?
E1.3: 13-Mar-2024 ref: LangChain Tools: Defining Custom Tools | 🦜️🔗 Langchain … it suggests different imports … this elimianted the error E1.0
‘’’

class SearchInput(BaseModel):
query: str = Field(description=“Thing to search for”
print(f’{type(SearchInput) = }‘)
‘’’
E1.1: I get: pydantic._internal._model_construction.ModelMetaclass whereas the Instuctor gets: pydantic.main.ModelMetaclass, why this difference? Does this lead to error in the next step?
After different imports, this gives: class pydantic.v1.main.ModelMetaclass
‘’’

@tool(args_schema=SearchInput) # E1.0: error: this expects BaseModel type input thereby TypeError. Why?
def search(query: str) → str:
“”“Search for the weather online.”“”
return “42f”

print(search.args)

thank you, will notify the staff.

Hi @mtadanki,

I’m guessing, you came across these errors when you tried running the notebook locally ?

I just ran the notebook on the platform, and I didn’t come across any error.

@Mubsi

Sorry for this, he had created this post for other learner to get help running the assignment notebook in local environment. This is not a course related issue.

Regards
DP

1 Like