langchain/tests/integration_tests/chains/test_self_ask_with_search.py

19 lines
694 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
from langchain.utilities.google_serper import GoogleSerperAPIWrapper
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),
search_chain=GoogleSerperAPIWrapper(),
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"