From 00eec68c3b0597ba1727237ebb075be59505d318 Mon Sep 17 00:00:00 2001 From: wwakabobik Date: Sat, 14 Oct 2023 19:52:43 +0200 Subject: [PATCH] Fix linters --- .github/workflows/linters.yml | 4 ++-- .github/workflows/master_linters.yml | 4 ++-- src/openai_api/chatgpt.py | 19 +++++++------------ src/openai_api/dalle.py | 2 +- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index daf3518..b88afa6 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -1,4 +1,4 @@ -name: Linters +name: Linters-PR on: push: @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11"] steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/master_linters.yml b/.github/workflows/master_linters.yml index 3ef94c5..0c0df24 100644 --- a/.github/workflows/master_linters.yml +++ b/.github/workflows/master_linters.yml @@ -1,4 +1,4 @@ -name: Linters-Master +name: Linters on: push: @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11"] steps: - name: Checkout uses: actions/checkout@v4 diff --git a/src/openai_api/chatgpt.py b/src/openai_api/chatgpt.py index a7ce547..cb33f60 100644 --- a/src/openai_api/chatgpt.py +++ b/src/openai_api/chatgpt.py @@ -602,10 +602,6 @@ async def process_chat(self, prompt, default_choice=0, chat_name=None): if "content" in chunk["choices"][default_choice]["delta"]: if chunk["choices"][default_choice]["delta"]["content"]: yield chunk - else: - continue - else: - continue except GeneratorExit: self.___logger.debug("Chat ended with uid=%s", uid) try: @@ -696,11 +692,11 @@ async def chat(self, prompt, chat_name=None, default_choice=0, extra_settings="" # Add new message to chat self.chats[chat_name].append({"role": "user", "content": prompt}) # Get last 'history_length' messages - messages = self.chats[chat_name][-self.history_length :] + messages = self.chats[chat_name][-self.history_length :] # flake8: noqa : E203 messages.insert(0, {"role": "system", "content": f"{self.system_settings} {extra_settings}"}) try: - async for prompt_response in self.process_chat( + async for prompt_response in self.process_chat( # flake8: noqa : WPS352 prompt=messages, default_choice=default_choice, chat_name=chat_name ): if isinstance(prompt_response, dict): @@ -913,12 +909,11 @@ async def __handle_chat_name(self, chat_name, prompt): self.___chat_name_length, chat_name, ) - else: - if len(chat_name) > self.___chat_name_length: - self.___logger.debug( - "Chat name is longer than %s characters, truncating it: %s", self.___chat_name_length, chat_name - ) - chat_name = chat_name[: self.___chat_name_length] + elif len(chat_name) > self.___chat_name_length: + self.___logger.debug( + "Chat name is longer than %s characters, truncating it: %s", self.___chat_name_length, chat_name + ) + chat_name = chat_name[: self.___chat_name_length] if chat_name not in self.chats: self.___logger.debug("Chat name '%s' is not present in self.chats, adding it", chat_name) self.chats[chat_name] = [] diff --git a/src/openai_api/dalle.py b/src/openai_api/dalle.py index 9ff0d1c..d056afd 100644 --- a/src/openai_api/dalle.py +++ b/src/openai_api/dalle.py @@ -454,4 +454,4 @@ def ___set_auth(self, token, organization): """ self.___logger.debug("Setting auth bearer") openai.api_key = token - openai.organization = organization \ No newline at end of file + openai.organization = organization