Skip to content

Commit 28a1117

Browse files
committed
Fix compatibility with older python versions
1 parent d10ce62 commit 28a1117

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

llama_cpp/server/app.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from re import compile, Match, Pattern
44
from threading import Lock
55
from functools import partial
6-
from typing import Callable, Coroutine, Iterator, List, Optional, Union, Dict
6+
from typing import Callable, Coroutine, Iterator, List, Optional, Tuple, Union, Dict
77
from typing_extensions import TypedDict, Literal
88

99
import llama_cpp
@@ -115,16 +115,16 @@ class ErrorResponseFormatters:
115115
match (Match[str]): Match object from regex pattern
116116
117117
Returns:
118-
tuple[int, ErrorResponse]: Status code and error response
118+
Tuple[int, ErrorResponse]: Status code and error response
119119
"""
120120

121121
@staticmethod
122122
def context_length_exceeded(
123123
request: Union[
124124
"CreateCompletionRequest", "CreateChatCompletionRequest"
125125
],
126-
match: Match[str],
127-
) -> tuple[int, ErrorResponse]:
126+
match, # type: Match[str] # type: ignore
127+
) -> Tuple[int, ErrorResponse]:
128128
"""Formatter for context length exceeded error"""
129129

130130
context_window = int(match.group(2))
@@ -163,8 +163,8 @@ def model_not_found(
163163
request: Union[
164164
"CreateCompletionRequest", "CreateChatCompletionRequest"
165165
],
166-
match: Match[str],
167-
) -> tuple[int, ErrorResponse]:
166+
match # type: Match[str] # type: ignore
167+
) -> Tuple[int, ErrorResponse]:
168168
"""Formatter for model_not_found error"""
169169

170170
model_path = str(match.group(1))
@@ -182,14 +182,14 @@ class RouteErrorHandler(APIRoute):
182182

183183
# key: regex pattern for original error message from llama_cpp
184184
# value: formatter function
185-
pattern_and_formatters: dict[
185+
pattern_and_formatters: Dict[
186186
"Pattern",
187187
Callable[
188188
[
189189
Union["CreateCompletionRequest", "CreateChatCompletionRequest"],
190-
Match[str],
190+
"Match[str]",
191191
],
192-
tuple[int, ErrorResponse],
192+
Tuple[int, ErrorResponse],
193193
],
194194
] = {
195195
compile(
@@ -210,7 +210,7 @@ def error_message_wrapper(
210210
"CreateEmbeddingRequest",
211211
]
212212
] = None,
213-
) -> tuple[int, ErrorResponse]:
213+
) -> Tuple[int, ErrorResponse]:
214214
"""Wraps error message in OpenAI style error response"""
215215

216216
if body is not None and isinstance(

0 commit comments

Comments
 (0)