Replies: 3 comments 1 reply
-
were you able to make it work? I am running into similar issue |
Beta Was this translation helpful? Give feedback.
-
Hi,
You can check this answer : #21907 (comment) |
Beta Was this translation helpful? Give feedback.
-
Since some models available within ollama now allow toolcalling you can indeed use an ollama model such as llama3-groq-tool-use, either with create_sql_agent or as post above stated using the tools that it uses under the hood directly. If you want to use create_sql_agent, you must specify the toolkit over db, it uses get_tools() itself so no need for that: from langchain_core.messages import HumanMessage
from langchain_ollama import ChatOllama
from langchain_community.agent_toolkits import SQLDatabaseToolkit
from langchain_community.agent_toolkits import create_sql_agent
llm = ChatOllama(model="llama3-groq-tool-use:latest", base_url="{url}")
toolkit = SQLDatabaseToolkit(db=db, llm=llm)
agent_executor = create_sql_agent(llm, toolkit=toolkit, agent_type="tool-calling")
agent_executor.invoke([HumanMessage(content="A question about the database?")]) Should help you on the way. I do highly recommend looking under the hood and using either the langgraph.prebuilt create_react_agent or stepping away from usage of prebuilt/community components for a while and diving deeper in it's core to gain more understanding of both langchain/langgraph, it can save you lots of time and makes you more flexible versus changes within langchain, langgraph, models or stuff like streamlit etc. |
Beta Was this translation helpful? Give feedback.
-
The docs describe how to create an SQL agent using OpenAI as an example but implying that the approach is generic.
I am able to use
create_sql_query_chain
just fine against either an OpenAI LLM or an Ollama LLM (examples below). However, when I try to usecreate_sql_agent
on the Ollama LLM, the agent throws an error on anyagent.run()
call, while the identical setup works fine with the OpenAI agent.I have seen the ollama-sql template, but this seems to create a 'chain' (a la
create_sql_query_chain
?) and not an agent? I don't quite see how to use it. I'd like to usecreate_sql_agent()
with a ollama agent -- the documentation seems to imply this should be possible.Setup:
create_sql_query_chain
works just fine:But creating an agent does not:
ERROR:
The same code executes fine with an ChatOpenAI LLM
Beta Was this translation helpful? Give feedback.
All reactions