From 9d0b4d013e2cc18d349f6a3552b60cb9510abcea Mon Sep 17 00:00:00 2001 From: MIDORIBIN Date: Sun, 13 Aug 2023 12:41:58 +0900 Subject: [PATCH] style: type strictness --- langchain_g4f/G4FLLM.py | 13 ++++++------- langchain_g4f/__init__.py | 2 ++ pyrightconfig.json | 4 ++++ 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 pyrightconfig.json diff --git a/langchain_g4f/G4FLLM.py b/langchain_g4f/G4FLLM.py index 03ed2e0..3544d63 100644 --- a/langchain_g4f/G4FLLM.py +++ b/langchain_g4f/G4FLLM.py @@ -14,7 +14,7 @@ class G4FLLM(LLM): # Provider.Provider provider: Optional[ModuleType] = None auth: Optional[Union[str, bool]] = None - create_kwargs: Optional[dict] = None + create_kwargs: Optional[dict[str, Any]] = None @property def _llm_type(self) -> str: @@ -28,20 +28,19 @@ class G4FLLM(LLM): **kwargs: Any, ) -> str: create_kwargs = {} if self.create_kwargs is None else self.create_kwargs.copy() - if self.model is not None: - create_kwargs["model"] = self.model + create_kwargs["model"] = self.model if self.provider is not None: create_kwargs["provider"] = self.provider if self.auth is not None: create_kwargs["auth"] = self.auth - text = ChatCompletion.create( + text = ChatCompletion.create( # type: ignore messages=[{"role": "user", "content": prompt}], **create_kwargs, ) - if stop is not None: - text = enforce_stop_tokens(text, stop) - return text + if stop is not None and type(stop) is str: + text = enforce_stop_tokens(text, stop) # type: ignore + return text # type: ignore @property def _identifying_params(self) -> Mapping[str, Any]: diff --git a/langchain_g4f/__init__.py b/langchain_g4f/__init__.py index 94015df..ebb9446 100644 --- a/langchain_g4f/__init__.py +++ b/langchain_g4f/__init__.py @@ -1 +1,3 @@ from .G4FLLM import G4FLLM + +__all__ = ["G4FLLM"] diff --git a/pyrightconfig.json b/pyrightconfig.json new file mode 100644 index 0000000..8321d3d --- /dev/null +++ b/pyrightconfig.json @@ -0,0 +1,4 @@ +{ + "reportMissingTypeStubs": "information", + "reportUnknownMemberType": "information" +}