2023-09-13 23:23:49 +00:00
|
|
|
"""Test Baidu Qianfan LLM Endpoint."""
|
|
|
|
from typing import Generator
|
|
|
|
|
2023-11-21 16:35:29 +00:00
|
|
|
from langchain_core.outputs import LLMResult
|
2023-09-13 23:23:49 +00:00
|
|
|
|
2023-12-11 21:53:30 +00:00
|
|
|
from langchain_community.llms.baidu_qianfan_endpoint import QianfanLLMEndpoint
|
2023-09-13 23:23:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_call() -> None:
|
|
|
|
"""Test valid call to qianfan."""
|
|
|
|
llm = QianfanLLMEndpoint()
|
|
|
|
output = llm("write a joke")
|
|
|
|
assert isinstance(output, str)
|
|
|
|
|
|
|
|
|
|
|
|
def test_generate() -> None:
|
|
|
|
"""Test valid call to qianfan."""
|
|
|
|
llm = QianfanLLMEndpoint()
|
|
|
|
output = llm.generate(["write a joke"])
|
|
|
|
assert isinstance(output, LLMResult)
|
|
|
|
assert isinstance(output.generations, list)
|
|
|
|
|
|
|
|
|
|
|
|
def test_generate_stream() -> None:
|
|
|
|
"""Test valid call to qianfan."""
|
|
|
|
llm = QianfanLLMEndpoint()
|
|
|
|
output = llm.stream("write a joke")
|
|
|
|
assert isinstance(output, Generator)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_qianfan_aio() -> None:
|
|
|
|
llm = QianfanLLMEndpoint(streaming=True)
|
|
|
|
|
|
|
|
async for token in llm.astream("hi qianfan."):
|
|
|
|
assert isinstance(token, str)
|