Skip to content

Commit

Permalink
fix: some lint errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
cauwulixuan committed Jan 31, 2024
1 parent 4992648 commit 0dc2846
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
24 changes: 14 additions & 10 deletions libs/community/langchain_community/chat_models/yuan2.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@
SystemMessageChunk,
)
from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, ChatResult
from langchain_core.pydantic_v1 import Field, SecretStr, root_validator
from langchain_core.pydantic_v1 import Field, root_validator
from langchain_core.utils import (
get_from_dict_or_env,
get_pydantic_field_names,
)
from openai.types.chat import (
ChatCompletion,
ChatCompletionMessage,
)
from tenacity import (
before_sleep_log,
retry,
Expand All @@ -52,11 +56,6 @@
wait_exponential,
)

from openai.types.chat import (
ChatCompletion,
ChatCompletionMessage,
)

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -208,7 +207,10 @@ def is_lc_serializable(cls) -> bool:
yuan2_api_key: Optional[str] = Field(default="EMPTY", alias="api_key")
"""Automatically inferred from env var `YUAN2_API_KEY` if not provided."""

yuan2_api_base: Optional[str] = Field(default="http://127.0.0.1:8000", alias="base_url")
yuan2_api_base: Optional[str] = Field(
default="http://127.0.0.1:8000",
alias="base_url"
)
"""Base URL path for API requests, an OpenAI compatible API server."""

request_timeout: Optional[Union[float, Tuple[float, float]]] = None
Expand All @@ -233,7 +235,8 @@ def is_lc_serializable(cls) -> bool:
# """The top-k value to use for sampling."""

# do_sample: bool = False
# """The do_sample is a Boolean value that determines whether to use the sampling method during text generation."""
# """The do_sample is a Boolean value that determines whether
# to use the sampling method during text generation."""

# echo: Optional[bool] = False
# """Whether to echo the prompt."""
Expand Down Expand Up @@ -308,7 +311,6 @@ def validate_environment(cls, values: Dict) -> Dict:
**client_params
).chat.completions


return values

@property
Expand Down Expand Up @@ -339,7 +341,9 @@ def _completion_with_retry(**kwargs: Any) -> Any:

def _combine_llm_outputs(self, llm_outputs: List[Optional[dict]]) -> dict:
overall_token_usage: dict = {}
logger.debug(f"type(llm_outputs): {type(llm_outputs)}; llm_outputs: {llm_outputs}")
logger.debug(
f"type(llm_outputs): {type(llm_outputs)}; llm_outputs: {llm_outputs}"
)
for output in llm_outputs:
if output is None:
# Happens in streaming
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,3 @@ async def test_async_chat_yuan2_streaming() -> None:
assert isinstance(generation, ChatGeneration)
assert isinstance(generation.text, str)
assert generation.text == generation.message.content

7 changes: 5 additions & 2 deletions libs/community/tests/unit_tests/chat_models/test_yuan2.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
"""Test ChatYuan2 wrapper."""

import pytest
from langchain_community.chat_models.yuan2 import (
ChatYuan2,
_convert_message_to_dict,
_convert_dict_to_message,
)
from langchain_core.messages import (
AIMessage,
HumanMessage,
SystemMessage,
)

from langchain_community.chat_models.yuan2 import ChatYuan2, _convert_message_to_dict, _convert_dict_to_message


@pytest.mark.requires("openai")

Check failure on line 16 in libs/community/tests/unit_tests/chat_models/test_yuan2.py

View workflow job for this annotation

GitHub Actions / ci (libs/community) / lint / build (3.11)

Ruff (I001)

tests/unit_tests/chat_models/test_yuan2.py:3:1: I001 Import block is un-sorted or un-formatted

Check failure on line 16 in libs/community/tests/unit_tests/chat_models/test_yuan2.py

View workflow job for this annotation

GitHub Actions / ci (libs/community) / lint / build (3.8)

Ruff (I001)

tests/unit_tests/chat_models/test_yuan2.py:3:1: I001 Import block is un-sorted or un-formatted
def test_yuan2_model_param() -> None:
Expand Down

0 comments on commit 0dc2846

Please sign in to comment.