langchain icon indicating copy to clipboard operation
langchain copied to clipboard

community: add `tools` support to ChatTongyi(can be used with `create_openai_tools_agent`)

Open cheese-git opened this issue 2 months ago • 2 comments

Description

Tongyi now supports "tools"(Official Docs), and the data structure is compatible with OpenAI tools, therefore it's possible now to use create_openai_tools_agent along with ChatTongyi.

Ex:

from langchain_community.chat_models.tongyi import ChatTongyi
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain import hub
from your_tools import your_tool, another_tool

prompt = hub.pull('hwchase17/openai-tools-agent')
tools = [your_tool, another_tool]
llm = ChatTongyi(temperature=0)

agent = create_openai_tools_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent = agent, tools = tools, verbose = True, handle_parsing_errors=True)

response = agent_executor.invoke(
    {"input": "Your question."}
)
print(response)

I tried the above example in my project, it works fine.

I have run the original integrations tests and they all passed.

To actually test the tools feature itself, I would need to import create_openai_tools_agent from langchain.agents, which is not a dependency of the community package. So I think I should leave the original test as it is.

Dependencies

No dependency is required for this change

cheese-git avatar Apr 09 '24 16:04 cheese-git

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Apr 22, 2024 1:55am

vercel[bot] avatar Apr 09 '24 16:04 vercel[bot]

@eyurtsev Would you mind take a look at this ?

cheese-git avatar Apr 15 '24 02:04 cheese-git