Fix compatibility with older python versions

This commit is contained in:
Andrei Betlen 2023-07-20 18:52:10 -04:00
parent d10ce62714
commit 28a111704b

View file

@ -3,7 +3,7 @@ import multiprocessing
from re import compile, Match, Pattern from re import compile, Match, Pattern
from threading import Lock from threading import Lock
from functools import partial from functools import partial
from typing import Callable, Coroutine, Iterator, List, Optional, Union, Dict from typing import Callable, Coroutine, Iterator, List, Optional, Tuple, Union, Dict
from typing_extensions import TypedDict, Literal from typing_extensions import TypedDict, Literal
import llama_cpp import llama_cpp
@ -115,7 +115,7 @@ class ErrorResponseFormatters:
match (Match[str]): Match object from regex pattern match (Match[str]): Match object from regex pattern
Returns: Returns:
tuple[int, ErrorResponse]: Status code and error response Tuple[int, ErrorResponse]: Status code and error response
""" """
@staticmethod @staticmethod
@ -123,8 +123,8 @@ class ErrorResponseFormatters:
request: Union[ request: Union[
"CreateCompletionRequest", "CreateChatCompletionRequest" "CreateCompletionRequest", "CreateChatCompletionRequest"
], ],
match: Match[str], match, # type: Match[str] # type: ignore
) -> tuple[int, ErrorResponse]: ) -> Tuple[int, ErrorResponse]:
"""Formatter for context length exceeded error""" """Formatter for context length exceeded error"""
context_window = int(match.group(2)) context_window = int(match.group(2))
@ -163,8 +163,8 @@ class ErrorResponseFormatters:
request: Union[ request: Union[
"CreateCompletionRequest", "CreateChatCompletionRequest" "CreateCompletionRequest", "CreateChatCompletionRequest"
], ],
match: Match[str], match # type: Match[str] # type: ignore
) -> tuple[int, ErrorResponse]: ) -> Tuple[int, ErrorResponse]:
"""Formatter for model_not_found error""" """Formatter for model_not_found error"""
model_path = str(match.group(1)) model_path = str(match.group(1))
@ -182,14 +182,14 @@ class RouteErrorHandler(APIRoute):
# key: regex pattern for original error message from llama_cpp # key: regex pattern for original error message from llama_cpp
# value: formatter function # value: formatter function
pattern_and_formatters: dict[ pattern_and_formatters: Dict[
"Pattern", "Pattern",
Callable[ Callable[
[ [
Union["CreateCompletionRequest", "CreateChatCompletionRequest"], Union["CreateCompletionRequest", "CreateChatCompletionRequest"],
Match[str], "Match[str]",
], ],
tuple[int, ErrorResponse], Tuple[int, ErrorResponse],
], ],
] = { ] = {
compile( compile(
@ -210,7 +210,7 @@ class RouteErrorHandler(APIRoute):
"CreateEmbeddingRequest", "CreateEmbeddingRequest",
] ]
] = None, ] = None,
) -> tuple[int, ErrorResponse]: ) -> Tuple[int, ErrorResponse]:
"""Wraps error message in OpenAI style error response""" """Wraps error message in OpenAI style error response"""
if body is not None and isinstance( if body is not None and isinstance(