Skip to content

Commit fcfea66

Browse files
committed
fix: pydantic deprecation warning
1 parent 7f52335 commit fcfea66

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

llama_cpp/server/settings.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import multiprocessing
44

5-
from typing import Optional, List, Literal, Union
6-
from pydantic import Field, root_validator
5+
from typing import Optional, List, Literal, Union, Dict, cast
6+
from typing_extensions import Self
7+
8+
from pydantic import Field, model_validator
79
from pydantic_settings import BaseSettings
810

911
import llama_cpp
@@ -173,15 +175,16 @@ class ModelSettings(BaseSettings):
173175
default=True, description="Whether to print debug information."
174176
)
175177

176-
@root_validator(pre=True) # pre=True to ensure this runs before any other validation
177-
def set_dynamic_defaults(cls, values):
178+
@model_validator(mode="before") # pre=True to ensure this runs before any other validation
179+
def set_dynamic_defaults(self) -> Self:
178180
# If n_threads or n_threads_batch is -1, set it to multiprocessing.cpu_count()
179181
cpu_count = multiprocessing.cpu_count()
182+
values = cast(Dict[str, int], self)
180183
if values.get('n_threads', 0) == -1:
181184
values['n_threads'] = cpu_count
182185
if values.get('n_threads_batch', 0) == -1:
183186
values['n_threads_batch'] = cpu_count
184-
return values
187+
return self
185188

186189

187190
class ServerSettings(BaseSettings):

0 commit comments

Comments
 (0)