Standardize SparkLLM (#25239)

- **Description:** Standardize SparkLLM, include:
  - docs, the issue #24803 
  - to support stream
  - update api url
  - model init arg names, the issue #20085
This commit is contained in:
maang-h
2024-08-13 21:50:12 +08:00
committed by GitHub
parent 35e2230f56
commit 089f5e6cad
2 changed files with 138 additions and 28 deletions

View File

@@ -18,3 +18,28 @@ def test_generate() -> None:
output = llm.generate(["Say foo:"])
assert isinstance(output, LLMResult)
assert isinstance(output.generations, list)
def test_spark_llm_with_param_alias() -> None:
"""Test SparkLLM with parameters alias."""
llm = SparkLLM( # type: ignore[call-arg]
app_id="your-app-id",
api_key="your-api-key",
api_secret="your-api-secret",
model="Spark4.0 Ultra",
api_url="your-api-url",
timeout=20,
)
assert llm.spark_app_id == "your-app-id"
assert llm.spark_api_key == "your-api-key"
assert llm.spark_api_secret == "your-api-secret"
assert llm.spark_llm_domain == "Spark4.0 Ultra"
assert llm.spark_api_url == "your-api-url"
assert llm.request_timeout == 20
def test_spark_llm_with_stream() -> None:
"""Test SparkLLM with stream."""
llm = SparkLLM() # type: ignore[call-arg]
for chunk in llm.stream("你好呀"):
assert isinstance(chunk, str)