3
3
from re import compile , Match , Pattern
4
4
from threading import Lock
5
5
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
7
7
from typing_extensions import TypedDict , Literal
8
8
9
9
import llama_cpp
@@ -115,16 +115,16 @@ class ErrorResponseFormatters:
115
115
match (Match[str]): Match object from regex pattern
116
116
117
117
Returns:
118
- tuple [int, ErrorResponse]: Status code and error response
118
+ Tuple [int, ErrorResponse]: Status code and error response
119
119
"""
120
120
121
121
@staticmethod
122
122
def context_length_exceeded (
123
123
request : Union [
124
124
"CreateCompletionRequest" , "CreateChatCompletionRequest"
125
125
],
126
- match : Match [str ],
127
- ) -> tuple [int , ErrorResponse ]:
126
+ match , # type : Match[str] # type: ignore
127
+ ) -> Tuple [int , ErrorResponse ]:
128
128
"""Formatter for context length exceeded error"""
129
129
130
130
context_window = int (match .group (2 ))
@@ -163,8 +163,8 @@ def model_not_found(
163
163
request : Union [
164
164
"CreateCompletionRequest" , "CreateChatCompletionRequest"
165
165
],
166
- match : Match [str ],
167
- ) -> tuple [int , ErrorResponse ]:
166
+ match # type : Match[str] # type: ignore
167
+ ) -> Tuple [int , ErrorResponse ]:
168
168
"""Formatter for model_not_found error"""
169
169
170
170
model_path = str (match .group (1 ))
@@ -182,14 +182,14 @@ class RouteErrorHandler(APIRoute):
182
182
183
183
# key: regex pattern for original error message from llama_cpp
184
184
# value: formatter function
185
- pattern_and_formatters : dict [
185
+ pattern_and_formatters : Dict [
186
186
"Pattern" ,
187
187
Callable [
188
188
[
189
189
Union ["CreateCompletionRequest" , "CreateChatCompletionRequest" ],
190
- Match [str ],
190
+ " Match[str]" ,
191
191
],
192
- tuple [int , ErrorResponse ],
192
+ Tuple [int , ErrorResponse ],
193
193
],
194
194
] = {
195
195
compile (
@@ -210,7 +210,7 @@ def error_message_wrapper(
210
210
"CreateEmbeddingRequest" ,
211
211
]
212
212
] = None ,
213
- ) -> tuple [int , ErrorResponse ]:
213
+ ) -> Tuple [int , ErrorResponse ]:
214
214
"""Wraps error message in OpenAI style error response"""
215
215
216
216
if body is not None and isinstance (
0 commit comments