4444with try_import () as imports_successful :
4545 import outlines
4646
47- from pydantic_ai .models .outlines import OutlinesModel
47+ from pydantic_ai .models .outlines import OutlinesAsyncBaseModel , OutlinesModel
4848 from pydantic_ai .providers .outlines import OutlinesProvider
4949
5050with try_import () as transformer_imports_successful :
5454 import llama_cpp
5555
5656with try_import () as vllm_imports_successful :
57- import vllm # type: ignore[reportMissingImports]
57+ import vllm
5858
5959 # We try to load the vllm model to ensure it is available
6060 try : # pragma: no lax cover
61- vllm .LLM ('microsoft/Phi-3-mini-4k-instruct' ) # type: ignore
61+ vllm .LLM ('microsoft/Phi-3-mini-4k-instruct' )
6262 except RuntimeError as e : # pragma: lax no cover
6363 if 'Found no NVIDIA driver' in str (e ) or 'Device string must not be empty' in str (e ):
6464 # Treat as import failure
9797
9898@pytest .fixture
9999def mock_async_model () -> OutlinesModel :
100- class MockOutlinesAsyncModel (outlines . models . base . AsyncModel ):
100+ class MockOutlinesAsyncModel (OutlinesAsyncBaseModel ):
101101 """Mock an OutlinesAsyncModel because no Outlines local models have an async version.
102102
103103 The `__call__` and `stream` methods will be called by the Pydantic AI model while the other methods are
104104 only implemented because they are abstract methods in the OutlinesAsyncModel class.
105105 """
106106
107- async def __call__ (self , model_input , output_type , backend , ** inference_kwargs ): # type: ignore[reportMissingParameterType]
107+ async def __call__ (self , model_input : Any , output_type : Any , backend : Any , ** inference_kwargs : Any ) -> str :
108108 return 'test'
109109
110- async def stream (self , model_input , output_type , backend , ** inference_kwargs ): # type: ignore[reportMissingParameterType]
110+ async def stream (self , model_input : Any , output_type : Any , backend : Any , ** inference_kwargs : Any ):
111111 for _ in range (2 ):
112112 yield 'test'
113113
114- async def generate (self , model_input , output_type , ** inference_kwargs ): # type: ignore[reportMissingParameterType]
115- ... # pragma: no cover
114+ async def generate (self , model_input : Any , output_type : Any , ** inference_kwargs : Any ): ... # pragma: no cover
116115
117- async def generate_batch (self , model_input , output_type , ** inference_kwargs ): # type: ignore[reportMissingParameterType]
118- ... # pragma: no cover
116+ async def generate_batch (
117+ self , model_input : Any , output_type : Any , ** inference_kwargs : Any
118+ ): ... # pragma: no cover
119119
120- async def generate_stream (self , model_input , output_type , ** inference_kwargs ): # type: ignore[reportMissingParameterType]
121- ... # pragma: no cover
120+ async def generate_stream (
121+ self , model_input : Any , output_type : Any , ** inference_kwargs : Any
122+ ): ... # pragma: no cover
122123
123124 return OutlinesModel (MockOutlinesAsyncModel (), provider = OutlinesProvider ())
124125
125126
126127@pytest .fixture
127128def transformers_model () -> OutlinesModel :
128- hf_model = transformers .AutoModelForCausalLM .from_pretrained ( # type: ignore
129+ hf_model = transformers .AutoModelForCausalLM .from_pretrained (
129130 'erwanf/gpt2-mini' ,
130131 device_map = 'cpu' ,
131132 )
132- hf_tokenizer = transformers .AutoTokenizer .from_pretrained ('erwanf/gpt2-mini' ) # type: ignore
133+ hf_tokenizer = transformers .AutoTokenizer .from_pretrained ('erwanf/gpt2-mini' )
133134 chat_template = '{% for message in messages %}{{ message.role }}: {{ message.content }}{% endfor %}'
134135 hf_tokenizer .chat_template = chat_template
135136 outlines_model = outlines .models .transformers .from_transformers (
136- hf_model , # type: ignore[reportUnknownArgumentType]
137- hf_tokenizer , # type: ignore
137+ hf_model ,
138+ hf_tokenizer ,
138139 )
139140 return OutlinesModel (outlines_model , provider = OutlinesProvider ())
140141
141142
142143@pytest .fixture
143144def transformers_multimodal_model () -> OutlinesModel :
144- hf_model = transformers .LlavaForConditionalGeneration .from_pretrained ( # type: ignore
145+ hf_model = transformers .LlavaForConditionalGeneration .from_pretrained (
145146 'trl-internal-testing/tiny-LlavaForConditionalGeneration' ,
146147 device_map = 'cpu' ,
147148 )
148- hf_processor = transformers .AutoProcessor .from_pretrained ( # type: ignore
149- 'trl-internal-testing/tiny-LlavaForConditionalGeneration'
150- )
149+ hf_processor = transformers .AutoProcessor .from_pretrained ('trl-internal-testing/tiny-LlavaForConditionalGeneration' )
151150 outlines_model = outlines .models .transformers .from_transformers (
152151 hf_model ,
153- hf_processor , # type: ignore
152+ hf_processor ,
154153 )
155154 return OutlinesModel (outlines_model , provider = OutlinesProvider ())
156155
157156
158157@pytest .fixture
159158def llamacpp_model () -> OutlinesModel :
160159 outlines_model_llamacpp = outlines .models .llamacpp .from_llamacpp (
161- llama_cpp .Llama .from_pretrained ( # type: ignore
160+ llama_cpp .Llama .from_pretrained (
162161 repo_id = 'M4-ai/TinyMistral-248M-v2-Instruct-GGUF' ,
163162 filename = 'TinyMistral-248M-v2-Instruct.Q4_K_M.gguf' ,
164163 )
@@ -168,9 +167,7 @@ def llamacpp_model() -> OutlinesModel:
168167
169168@pytest .fixture
170169def mlxlm_model () -> OutlinesModel : # pragma: no cover
171- outlines_model = outlines .models .mlxlm .from_mlxlm (
172- * mlx_lm .load ('mlx-community/SmolLM-135M-Instruct-4bit' ) # type: ignore
173- )
170+ outlines_model = outlines .models .mlxlm .from_mlxlm (* mlx_lm .load ('mlx-community/SmolLM-135M-Instruct-4bit' ))
174171 return OutlinesModel (outlines_model , provider = OutlinesProvider ())
175172
176173
@@ -184,9 +181,7 @@ def sglang_model() -> OutlinesModel:
184181
185182@pytest .fixture
186183def vllm_model_offline () -> OutlinesModel : # pragma: no cover
187- outlines_model = outlines .models .vllm_offline .from_vllm_offline ( # type: ignore
188- vllm .LLM ('microsoft/Phi-3-mini-4k-instruct' ) # type: ignore
189- )
184+ outlines_model = outlines .models .vllm_offline .from_vllm_offline (vllm .LLM ('microsoft/Phi-3-mini-4k-instruct' ))
190185 return OutlinesModel (outlines_model , provider = OutlinesProvider ())
191186
192187
@@ -201,18 +196,18 @@ def binary_image() -> BinaryImage:
201196 pytest .param (
202197 'from_transformers' ,
203198 lambda : (
204- transformers .AutoModelForCausalLM .from_pretrained ( # type: ignore
199+ transformers .AutoModelForCausalLM .from_pretrained (
205200 'erwanf/gpt2-mini' ,
206201 device_map = 'cpu' ,
207202 ),
208- transformers .AutoTokenizer .from_pretrained ('erwanf/gpt2-mini' ), # type: ignore
203+ transformers .AutoTokenizer .from_pretrained ('erwanf/gpt2-mini' ),
209204 ),
210205 marks = skip_if_transformers_imports_unsuccessful ,
211206 ),
212207 pytest .param (
213208 'from_llamacpp' ,
214209 lambda : (
215- llama_cpp .Llama .from_pretrained ( # type: ignore
210+ llama_cpp .Llama .from_pretrained (
216211 repo_id = 'M4-ai/TinyMistral-248M-v2-Instruct-GGUF' ,
217212 filename = 'TinyMistral-248M-v2-Instruct.Q4_K_M.gguf' ,
218213 ),
@@ -221,7 +216,7 @@ def binary_image() -> BinaryImage:
221216 ),
222217 pytest .param (
223218 'from_mlxlm' ,
224- lambda : mlx_lm .load ('mlx-community/SmolLM-135M-Instruct-4bit' ), # type: ignore
219+ lambda : mlx_lm .load ('mlx-community/SmolLM-135M-Instruct-4bit' ),
225220 marks = skip_if_mlxlm_imports_unsuccessful ,
226221 ),
227222 pytest .param (
@@ -231,7 +226,7 @@ def binary_image() -> BinaryImage:
231226 ),
232227 pytest .param (
233228 'from_vllm_offline' ,
234- lambda : (vllm .LLM ('microsoft/Phi-3-mini-4k-instruct' ),), # type: ignore
229+ lambda : (vllm .LLM ('microsoft/Phi-3-mini-4k-instruct' ),),
235230 marks = skip_if_vllm_imports_unsuccessful ,
236231 ),
237232]
@@ -260,18 +255,18 @@ def test_init(model_loading_function_name: str, args: Callable[[], tuple[Any]])
260255 pytest .param (
261256 'from_transformers' ,
262257 lambda : (
263- transformers .AutoModelForCausalLM .from_pretrained ( # type: ignore
258+ transformers .AutoModelForCausalLM .from_pretrained (
264259 'erwanf/gpt2-mini' ,
265260 device_map = 'cpu' ,
266261 ),
267- transformers .AutoTokenizer .from_pretrained ('erwanf/gpt2-mini' ), # type: ignore
262+ transformers .AutoTokenizer .from_pretrained ('erwanf/gpt2-mini' ),
268263 ),
269264 marks = skip_if_transformers_imports_unsuccessful ,
270265 ),
271266 pytest .param (
272267 'from_llamacpp' ,
273268 lambda : (
274- llama_cpp .Llama .from_pretrained ( # type: ignore
269+ llama_cpp .Llama .from_pretrained (
275270 repo_id = 'M4-ai/TinyMistral-248M-v2-Instruct-GGUF' ,
276271 filename = 'TinyMistral-248M-v2-Instruct.Q4_K_M.gguf' ,
277272 ),
@@ -280,7 +275,7 @@ def test_init(model_loading_function_name: str, args: Callable[[], tuple[Any]])
280275 ),
281276 pytest .param (
282277 'from_mlxlm' ,
283- lambda : mlx_lm .load ('mlx-community/SmolLM-135M-Instruct-4bit' ), # type: ignore
278+ lambda : mlx_lm .load ('mlx-community/SmolLM-135M-Instruct-4bit' ),
284279 marks = skip_if_mlxlm_imports_unsuccessful ,
285280 ),
286281 pytest .param (
@@ -290,7 +285,7 @@ def test_init(model_loading_function_name: str, args: Callable[[], tuple[Any]])
290285 ),
291286 pytest .param (
292287 'from_vllm_offline' ,
293- lambda : (vllm .LLM ('microsoft/Phi-3-mini-4k-instruct' ),), # type: ignore
288+ lambda : (vllm .LLM ('microsoft/Phi-3-mini-4k-instruct' ),),
294289 marks = skip_if_vllm_imports_unsuccessful ,
295290 ),
296291]
0 commit comments