Replies: 2 comments
-
@GaffeyFF Hello there! I'm here to help you out with any bugs, questions, or contributions. Let's work on this together while we wait for the human maintainer. To resolve the Here is a possible implementation of the class MyLanguageModel(BaseLanguageModel):
def bind_tools(self, tools: Sequence[BaseTool]):
# Implement the logic to bind tools to the language model
self.tools = tools
return self
# Example usage
model = MyLanguageModel()
tools = [price_search] # Assuming price_search is defined as a tool
agent = create_tool_calling_agent(model, tools, prompt) Make sure that your language model class ( If you are using the LangChain framework, you can use the from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts.chat import ChatPromptTemplate
from langchain_core.tools import BaseTool
from langchain.agents.structured_chat.base import create_structured_chat_agent
# Assuming price_search is an instance of BaseTool
llm = BaseLanguageModel() # Replace with your actual language model
price_search_tool = BaseTool(name="price_search", description="Search for prices")
# Create a prompt template
prompt = ChatPromptTemplate.from_messages([
("system", "Respond to the human as helpfully and accurately as possible. You have access to the following tools:\n\n{tools}\n\nUse a json blob to specify a tool by providing an action key (tool name) and an action_input key (tool input).\n\nValid \"action\" values: \"Final Answer\" or {tool_names}\n\nProvide only ONE action per $JSON_BLOB, as shown:\n\n```\n{\n \"action\": $TOOL_NAME,\n \"action_input\": $INPUT\n}\n```\n\nFollow this format:\n\nQuestion: input question to answer\nThought: consider previous and subsequent steps\nAction:\n```\n$JSON_BLOB\n```\nObservation: action result\n... (repeat Thought/Action/Observation N times)\nThought: I know what to respond\nAction:\n```\n{\n \"action\": \"Final Answer\",\n \"action_input\": \"Final response to human\"\n}\nBegin! Reminder to ALWAYS respond with a valid json blob of a single action. Use tools if necessary. Respond directly if appropriate. Format is Action:```$JSON_BLOB```then Observation"),
("human", "{input}\n\n{agent_scratchpad}\n\n(reminder to respond in a JSON blob no matter what)")
])
agent = create_structured_chat_agent(
llm=llm,
tools=[price_search_tool],
prompt=prompt
) This function constructs a structured chat agent from an LLM and a tool, handling the binding of tools internally. Make sure to replace |
Beta Was this translation helpful? Give feedback.
-
I'm a Chinese student, my English level seems a bit low, please forgive me if my saying is offensive or having gramma errors. I don't know which LLM you are using, but I discover that in def bind_tools(
self,
tools: Sequence[
Union[typing.Dict[str, Any], type, Callable, BaseTool] # noqa: UP006
],
**kwargs: Any,
) -> Runnable[LanguageModelInput, BaseMessage]:
raise NotImplementedError |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
"price" has "description" content, but throws an exception
System Info
System Information
Package Information
Packages not installed (Not Necessarily a Problem)
The following packages were not found:
Beta Was this translation helpful? Give feedback.
All reactions