mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-25 13:07:58 +00:00
community:qianfan endpoint support init params & remove useless params definietion (#15381)
- **Description:** - support custom kwargs in object initialization. For instantance, QPS differs from multiple object(chat/completion/embedding with diverse models), for which global env is not a good choice for configuration. - **Issue:** no - **Dependencies:** no - **Twitter handle:** no @baskaryan PTAL
This commit is contained in:
@@ -217,3 +217,18 @@ def test_functions_call() -> None:
|
||||
chain = prompt | chat.bind(functions=_FUNCTIONS)
|
||||
resp = chain.invoke({})
|
||||
assert isinstance(resp, AIMessage)
|
||||
|
||||
|
||||
def test_rate_limit() -> None:
|
||||
chat = QianfanChatEndpoint(model="ERNIE-Bot", init_kwargs={"query_per_second": 2})
|
||||
assert chat.client._client._rate_limiter._sync_limiter._query_per_second == 2
|
||||
responses = chat.batch(
|
||||
[
|
||||
[HumanMessage(content="Hello")],
|
||||
[HumanMessage(content="who are you")],
|
||||
[HumanMessage(content="what is baidu")],
|
||||
]
|
||||
)
|
||||
for res in responses:
|
||||
assert isinstance(res, BaseMessage)
|
||||
assert isinstance(res.content, str)
|
||||
|
@@ -25,3 +25,15 @@ def test_model() -> None:
|
||||
embedding = QianfanEmbeddingsEndpoint(model="Embedding-V1")
|
||||
output = embedding.embed_documents(documents)
|
||||
assert len(output) == 2
|
||||
|
||||
|
||||
def test_rate_limit() -> None:
|
||||
llm = QianfanEmbeddingsEndpoint(
|
||||
model="Embedding-V1", init_kwargs={"query_per_second": 2}
|
||||
)
|
||||
assert llm.client._client._rate_limiter._sync_limiter._query_per_second == 2
|
||||
documents = ["foo", "bar"]
|
||||
output = llm.embed_documents(documents)
|
||||
assert len(output) == 2
|
||||
assert len(output[0]) == 384
|
||||
assert len(output[1]) == 384
|
||||
|
@@ -33,3 +33,11 @@ async def test_qianfan_aio() -> None:
|
||||
|
||||
async for token in llm.astream("hi qianfan."):
|
||||
assert isinstance(token, str)
|
||||
|
||||
|
||||
def test_rate_limit() -> None:
|
||||
llm = QianfanLLMEndpoint(model="ERNIE-Bot", init_kwargs={"query_per_second": 2})
|
||||
assert llm.client._client._rate_limiter._sync_limiter._query_per_second == 2
|
||||
output = llm.generate(["write a joke"])
|
||||
assert isinstance(output, LLMResult)
|
||||
assert isinstance(output.generations, list)
|
||||
|
Reference in New Issue
Block a user