Replies: 6 comments 12 replies
-
Hey @chandrahk! Great to see you diving into the depths of LangChain again. How's the code wizardry going? Based on your question, it seems like you're trying to bind custom functions to a custom Language Model (LLM) in LangChain. However, as per the LangChain codebase, there is no direct method available in the base LLM to bind tools or functions. The If you're trying to bind functions to the Here's an example of how you can use the llm = ChatOpenAI(openai_api_key="xxx",temperature=0.5)
tools = [get_band_packages]
prompt = ChatPromptTemplate.from_messages(
[
(
"system",
system_msg
),
MessagesPlaceholder(variable_name="chat_history"),
("user", "{input}"),
MessagesPlaceholder(variable_name="agent_scratchpad"),
]
)
chat_history = []
functions = [format_tool_to_openai_function(t) for t in tools]
llm_with_tools = llm.bind_functions(functions=functions)
agent = (
{
"input": lambda x: x["input"],
"agent_scratchpad": lambda x: format_to_openai_function_messages(
x["intermediate_steps"]
),
"chat_history": lambda x: x["chat_history"],
}
| prompt
| llm_with_tools
| OpenAIFunctionsAgentOutputParser()
)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
agent_executor.invoke({"input": "xxxxxxx","chat_history":[]}) In this example, the Please try this approach and let me know if it resolves your issue. If you have any further questions or need additional clarification, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
-
@dosu-bot you did not answer to the OP's question. You are using ChatOpenAI in your example. However, the question was about using a custom LLM which is just a REST endpoint for LLama2. |
Beta Was this translation helpful? Give feedback.
-
@chandrahk The Or maybe I'm understanding your requirement incorrectly. |
Beta Was this translation helpful? Give feedback.
-
Checkout this documentation to call tools without binding them. This works for custom models. |
Beta Was this translation helpful? Give feedback.
-
Here is an example to use LangChain agents with DeepSeek-v3(which is not supported by the ChatOpenAI api). https://blog.eusoftbank.com/en/2025/04/use-any-llm-with-langchain-agent/ |
Beta Was this translation helpful? Give feedback.
-
Any body has solved it ? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
How to implement bind_tools to custom LLM to call custom functions in agent? It appears there is nothing exposed in base LLM to do such a thing now
System Info
N/A
Beta Was this translation helpful? Give feedback.
All reactions