Errors Using langchain_core.agents.utils.function_calling.convert_to_openai_function in Python

54 views Asked by At

I'm working on a Python project where I need to use specific functions from a library called langchain_core to convert tools into OpenAI-compatible functions. However, I'm encountering a NameError when I attempt to run my code.

Problem: Here is the code snippet that's causing the issue:

tools = [GetCurrentWeatherTool()]
#functions = [format_tool_to_openai_function(tool_name) for tool_name in tools]
functions = [langchain_core.agents.utils.function_calling.convert_to_openai_function(tool_name) for tool_name in tools]

And the error I receive is:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[16], line 3
      1 tools = [GetCurrentWeatherTool()]
      2 #functions = [format_tool_to_openai_function(tool_name) for tool_name in tools]
----> 3 functions = [langchain_core.agents.utils.function_calling.convert_to_openai_function(tool_name) for tool_name in tools]

Cell In[16], line 3, in <listcomp>(.0)
      1 tools = [GetCurrentWeatherTool()]
      2 #functions = [format_tool_to_openai_function(tool_name) for tool_name in tools]
----> 3 functions = [langchain_core.agents.utils.function_calling.convert_to_openai_function(tool_name) for tool_name in tools]

NameError: name 'langchain_core' is not defined

I am using Python 3.9, Langchain 0.1.12, and openai 1.10.0 in a virtual environment. I have verified that langchain_core is properly installed in my environment. I tried to see if I needed to import any additional module or if there was any missing dependency, but I couldn't find clear information regarding this. What I've Tried: Ensuring all necessary packages are installed and up-to-date. Searching for specific langchain_core documentation for this use case but found no similar examples. Commenting and uncommenting different parts of the code to isolate the problem. Question: How can I resolve the NameError and ensure that langchain_core is correctly defined and accessible in my code? Is there a specific import or setup I am missing?

I would appreciate any guidance or code examples that could help me move forward with this issue.

0

There are 0 answers