mirror of
https://github.com/hwchase17/langchain.git
synced 2025-05-02 13:55:42 +00:00
You.com is releasing two new conversational APIs — Smart and Research. This PR: - integrates those APIs with Langchain, as an LLM - streaming is supported If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
import pytest
|
|
import requests_mock
|
|
|
|
|
|
@pytest.mark.parametrize("endpoint", ("smart", "research"))
|
|
@pytest.mark.requires("sseclient")
|
|
def test_invoke(
|
|
endpoint: str, requests_mock: requests_mock.Mocker, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
from langchain_community.llms import You
|
|
from langchain_community.llms.you import RESEARCH_ENDPOINT, SMART_ENDPOINT
|
|
|
|
json = {
|
|
"answer": (
|
|
"A solar eclipse occurs when the Moon passes between the Sun and Earth, "
|
|
"casting a shadow on Earth and ..."
|
|
),
|
|
"search_results": [
|
|
{
|
|
"url": "https://en.wikipedia.org/wiki/Solar_eclipse",
|
|
"name": "Solar eclipse - Wikipedia",
|
|
"snippet": (
|
|
"A solar eclipse occurs when the Moon passes "
|
|
"between Earth and the Sun, thereby obscuring the view of the Sun "
|
|
"from a small part of Earth, totally or partially. "
|
|
),
|
|
}
|
|
],
|
|
}
|
|
request_endpoint = SMART_ENDPOINT if endpoint == "smart" else RESEARCH_ENDPOINT
|
|
requests_mock.post(request_endpoint, json=json)
|
|
|
|
monkeypatch.setenv("YDC_API_KEY", "...")
|
|
|
|
llm = You(endpoint=endpoint)
|
|
output = llm.invoke("What is a solar eclipse?")
|
|
assert output == json["answer"]
|