From 76c76584f3cb2e168e879c4e4b131efcd06baadc Mon Sep 17 00:00:00 2001 From: Artificiangel Date: Fri, 14 Jun 2024 20:52:02 -0400 Subject: [PATCH] Typing --- extensions/openai/script.py | 2 +- extensions/openai/utils.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/extensions/openai/script.py b/extensions/openai/script.py index a6710163..dc6d2908 100644 --- a/extensions/openai/script.py +++ b/extensions/openai/script.py @@ -239,7 +239,7 @@ async def handle_embeddings(request: Request, request_data: EmbeddingsRequest): if not input: raise HTTPException(status_code=400, detail="Missing required argument input") - if type(input) is str: + if isinstance(input, str): input = [input] async with embedding_semaphore: diff --git a/extensions/openai/utils.py b/extensions/openai/utils.py index b4c1048c..b21a04fc 100644 --- a/extensions/openai/utils.py +++ b/extensions/openai/utils.py @@ -2,7 +2,7 @@ import base64 import os import time import traceback -from typing import Callable, Optional, AsyncGenerator, Generator +from typing import Any, Callable, Optional, AsyncGenerator, Generator import numpy as np from modules import shared @@ -58,7 +58,7 @@ def _start_cloudflared(port: int, tunnel_id: str, max_attempts: int = 3, on_star raise Exception('Could not start cloudflared.') -def get_next_generator_result(gen: Generator) -> tuple[any, bool]: +def get_next_generator_result(gen: Generator) -> tuple[Any, bool]: """ Because StopIteration interacts badly with generators and cannot be raised into a Future """ @@ -69,7 +69,7 @@ def get_next_generator_result(gen: Generator) -> tuple[any, bool]: return None, True -async def generate_in_executor(partial: partial, loop: AbstractEventLoop = None) -> AsyncGenerator[any, any]: +async def generate_in_executor(partial: partial, loop: AbstractEventLoop|None = None) -> AsyncGenerator[Any, Any]: """ Converts a blocking generator to an async one """ @@ -84,7 +84,7 @@ async def generate_in_executor(partial: partial, loop: AbstractEventLoop = None) yield result -async def run_in_executor(partial: partial, loop: AbstractEventLoop = None) -> Future: +async def run_in_executor(partial: partial, loop: AbstractEventLoop|None = None) -> Future: """ Runs a blocking function in a new thread so it can be awaited. """