langchain/tests/integration_tests/chains/test_self_ask_with_search.py

19 lines
662 B
Python
Raw Normal View History

2022-10-24 21:51:15 +00:00
"""Integration test for self ask with search."""
2022-11-22 14:16:26 +00:00
from langchain.agents.self_ask_with_search.base import SelfAskWithSearchChain
2022-10-24 21:51:15 +00:00
from langchain.llms.openai import OpenAI
2022-11-30 04:07:44 +00:00
from langchain.serpapi import SerpAPIWrapper
2022-10-24 21:51:15 +00:00
def test_self_ask_with_search() -> None:
"""Test functionality on a prompt."""
question = "What is the hometown of the reigning men's U.S. Open champion?"
chain = SelfAskWithSearchChain(
llm=OpenAI(temperature=0),
2022-11-30 04:07:44 +00:00
search_chain=SerpAPIWrapper(),
2022-10-24 21:51:15 +00:00
input_key="q",
output_key="a",
)
answer = chain.run(question)
final_answer = answer.split("\n")[-1]
2022-12-19 02:51:23 +00:00
assert final_answer == "El Palmar, Spain"