From 78fcb695cefff1a65a73e85ecf6cf306b176fde9 Mon Sep 17 00:00:00 2001 From: MIDORIBIN Date: Sun, 20 Aug 2023 11:18:13 +0900 Subject: [PATCH] refactor: type --- langchain_g4f/G4FLLM.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/langchain_g4f/G4FLLM.py b/langchain_g4f/G4FLLM.py index 7e62453..2568229 100644 --- a/langchain_g4f/G4FLLM.py +++ b/langchain_g4f/G4FLLM.py @@ -32,13 +32,16 @@ class G4FLLM(LLM): if self.auth is not None: create_kwargs["auth"] = self.auth - text = ChatCompletion.create( # type: ignore + text = ChatCompletion.create( messages=[{"role": "user", "content": prompt}], **create_kwargs, ) - if stop is not None and type(stop) is str: - text = enforce_stop_tokens(text, stop) # type: ignore - return text # type: ignore + + # Generator -> str + text = text if type(text) is str else "".join(text) + if stop is not None: + text = enforce_stop_tokens(text, stop) + return text @property def _identifying_params(self) -> Mapping[str, Any]: