DEV Community

sanjay murmu
sanjay murmu

Posted on

unable to use search tool

i trying to use duckduckgo search engine
Tool list
tools = [duckduckgo_tool,makers_update]

chat_history = []
qa_system_prompt = """You are an assistant for question-answering tasks. \
Use the following pieces of retrieved context to answer the question. \
You have access to two tools: makers_update and duckduckgo_tool.\
Questions about current events, use the duckduckgo_tool tool to get information from the web. \
If somebody ask about your creator or ask about you,use makers_update tool to give the information.\
Use three sentences maximum and keep the answer concise.\
"""
qa_prompt = ChatPromptTemplate.from_messages(
[
("system", qa_system_prompt),
MessagesPlaceholder(variable_name="history"),
("human", "{input}"),
]
)

chain = qa_prompt | llm.bind_tools(tools)

from langchain_core.chat_history import (
BaseChatMessageHistory,
InMemoryChatMessageHistory,
)
from langchain_core.runnables.history import RunnableWithMessageHistory

store = {}

def get_session_history(session_id: str) -> BaseChatMessageHistory:
if session_id not in store:
store[session_id] = InMemoryChatMessageHistory()
return store[session_id]

def start_app():
while True:
question = input("You: ")
if question == "done":
return
with_message_history = RunnableWithMessageHistory(chain, get_session_history,input_messages_key="input",
history_messages_key="history",)
config = {"configurable": {"session_id": "abc"}}
# response = llm.invoke(question)
response = with_message_history.invoke({"input": question},config=config,)
print(response.content)

if name == "main":
start_app()
but whenever i ask something related to web search it is not using the tool

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay