langchain Tavily搜索参数不会改变输出,

alen0pnh  于 6个月前  发布在  其他
关注(0)|答案(6)|浏览(103)

检查其他资源

  • 为这个问题添加了一个非常描述性的标题。
  • 使用集成搜索在LangChain文档中进行了搜索。
  • 使用GitHub搜索查找类似的问题,但没有找到。
  • 我确信这是LangChain中的一个bug,而不是我的代码。
  • 通过更新到LangChain的最新稳定版本(或特定集成包)无法解决此bug。

示例代码

from langchain_community.tools.tavily_search import TavilySearchResults, TavilyAnswer

tool_with_raw = TavilySearchResults(include_raw_content=True, max_results=1)
tool_with_raw_and_answer = TavilySearchResults(include_raw_content=True, include_answer=True, max_results=1)
tool_without_raw = TavilySearchResults(include_raw_content=False, max_results=1)

r1=tool_with_raw.invoke({'query': 'how to cook a steak?'})
print(r1)

r2=tool_without_raw.invoke({'query': 'how to cook a steak?'})
print(r2)

r3=tool_with_raw_and_answer.invoke({'query': 'how to cook a steak?'})
print(r3)
[
    {
        'url': 'https://www.onceuponachef.com/recipes/how-to-cook-steak-on-the-stovetop.html',
        'content': 'Pan-Seared Steaks\nPan-searing is the best way to cook a steak, and it’s also the easiest!\nIngredients\nInstructions\nPair 
with\nNutrition Information\nPowered by\nThis website is written and produced for informational purposes only. When I do this again I will do for 5 
minutes but will turn off the heat on my cast Iron frying pan 2 minutes before and add butter and rosemary and garlic to get the steak more to our 
liking.\n I got a ribeye steak, heated the pan to the top heat and did everything like you mentioned, but after three minutes the steak was burned, 
on the other side the same happened. After doing some more research, I find you have to bring the steak to room temperature before you cook it and 
yiu have to snip the fat around the edges to keep it from curling. 22 Quick and Easy Recipes in 30 Minutes (or less) + 5 Chef Secrets To Make You A 
Better Cook!\nFind a Recipe\nHow To Cook Steak On The Stovetop\nThis post may contain affiliate links.'
    }
]
>>> r2=tool_without_raw.invoke({'query': 'how to cook a steak?'})
>>> print(r2)
[
    {
        'url': 'https://www.onceuponachef.com/recipes/how-to-cook-steak-on-the-stovetop.html',
        'content': 'Pan-Seared Steaks\nPan-searing is the best way to cook a steak, and it’s also the easiest!\nIngredients\nInstructions\nPair 
with\nNutrition Information\nPowered by\nThis website is written and produced for informational purposes only. When I do this again I will do for 5 
minutes but will turn off the heat on my cast Iron frying pan 2 minutes before and add butter and rosemary and garlic to get the steak more to our 
liking.\n I got a ribeye steak, heated the pan to the top heat and did everything like you mentioned, but after three minutes the steak was burned, 
on the other side the same happened. After doing some more research, I find you have to bring the steak to room temperature before you cook it and 
yiu have to snip the fat around the edges to keep it from curling. 22 Quick and Easy Recipes in 30 Minutes (or less) + 5 Chef Secrets To Make You A 
Better Cook!\nFind a Recipe\nHow To Cook Steak On The Stovetop\nThis post may contain affiliate links.'
    }
]
>>> r3=tool_with_raw_and_answer.invoke({'query': 'how to cook a steak?'})
>>> print(r3)
[
    {
        'url': 'https://www.onceuponachef.com/recipes/how-to-cook-steak-on-the-stovetop.html',
        'content': 'Pan-Seared Steaks\nPan-searing is the best way to cook a steak, and it’s also the easiest!\nIngredients\nInstructions\nPair 
with\nNutrition Information\nPowered by\nThis website is written and produced for informational purposes only. When I do this again I will do for 5 
minutes but will turn off the heat on my cast Iron frying pan 2 minutes before and add butter and rosemary and garlic to get the steak more to our 
liking.\n I got a ribeye steak, heated the pan to the top heat and did everything like you mentioned, but after three minutes the steak was burned, 
on the other side the same happened. After doing some more research, I find you have to bring the steak to room temperature before you cook it and 
yiu have to snip the fat around the edges to keep it from curling. 22 Quick and Easy Recipes in 30 Minutes (or less) + 5 Chef Secrets To Make You A 
Better Cook!\nFind a Recipe\nHow To Cook Steak On The Stovetop\nThis post may contain affiliate links.'
    }
]

错误信息和堆栈跟踪(如有适用)

  • 无响应*

描述

你好,
我无法从参数中获取所有请求的信息。
似乎只有max_result被保留了。我能理解有两个类(TavilySearchResults, TavilyAnswer),但是如果我们可以使用API选项初始化TavilySearchResults,为什么要保留这两个类呢?D

系统信息

系统信息

操作系统:Darwin
操作系统版本:Darwin Kernel Version 23.3.0: Wed Dec 20 21:28:58 PST 2023; root:xnu-10002.81.5~7/RELEASE_X86_64
Python版本:3.12.2 | 由conda-forge打包 | (main, Feb 16 2024, 21:00:12) [Clang 16.0.6 ]

软件包信息

langchain_core: 0.2.11
langchain: 0.2.6
langchain_community: 0.2.6
langsmith: 0.1.83
langchain_openai: 0.1.14
langchain_text_splitters: 0.2.2
langgraph: 0.1.5
langserve: 0.2.2

wvmv3b1j

wvmv3b1j1#

我尝试使用Python SDK,这是我得到的结果:

from tavily import TavilyClient
tavily = TavilyClient(api_key=API_KEY)
print(tavily.search(query='how to cook a steak?', max_results=1, include_raw_content=True))
{
    'query': 'how to cook a steak?',
    'follow_up_questions': None,
    'answer': None,
    'images': [],
    'results': [
        {
            'title': 'How To Cook Steak On The Stovetop - Once Upon a Chef',
            'url': 'https://www.onceuponachef.com/recipes/how-to-cook-steak-on-the-stovetop.html',
            'content': 'Pan-Seared Steaks\nPan-searing is the best way to cook a steak, and it’s also the easiest!\nIngredients\nInstructions\nPair 
with\nNutrition Information\nPowered by\nThis website is written and produced for informational purposes only. When I do this again I will do for 5 
minutes but will turn off the heat on my cast Iron frying pan 2 minutes before and add butter and rosemary and garlic to get the steak more to our 
liking.\n I got a ribeye steak, heated the pan to the top heat and did everything like you mentioned, but after three minutes the steak was burned, 
on the other side the same happened. After doing some more research, I find you have to bring the steak to room temperature before you cook it and 
yiu have to snip the fat around the edges to keep it from curling. 22 Quick and Easy Recipes in 30 Minutes (or less) + 5 Chef Secrets To Make You A 
Better Cook!\nFind a Recipe\nHow To Cook Steak On The Stovetop\nThis post may contain affiliate links.',
            'score': 0.98533,
            'raw_content': "22 Quick and Easy Recipes in 30 Minutes (or less) + 5 Chef Secrets To Make You A Better Cook!\nFind a Recipe\nHow To ... (text deleted)"
        }
    ],
    'response_time': 0.95
}
k0pti3hp

k0pti3hp2#

你好@dsolito

这两个类似乎是用来构建工具调用代理的。创建两个单独的类可以使llms在根据提示指令选择从TavilySearchResults获取当前事件还是直接从TavilyAnswer获取答案时,减少混淆。

swvgeqrz

swvgeqrz3#

Hi @2020uce0047,这个说法有道理,但是为什么要将Api参数(include_raw_content, include_answer等)实现到类中呢?

1szpjjfi

1szpjjfi4#

你好,@dsolito。我看到这两个类都在使用相同的函数raw_results来从API获取输出的json数据,该API接受所有的Api参数。然而,TavilySearchResults类通过clean_results进行了额外的清理,只返回内容和url。

相关问题