feat: browser access (allowed_origins, CORS with Private Network Access), job cancel, Tomie/Unity adapters, benchmark
Includes earlier uncommitted work: Tomie and Unity adapters, benchmark, structured output, call metrics. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
13492929c6
commit
f49ee90477
32 files changed
+2799
-51
No files matched your search
@@ -14,6 +14,7 @@ class ProviderConfig(BaseModel):
|
||||
temperature: float = Field(default=0.2, ge=0, le=2)
|
||||
max_tokens: int = Field(default=4096, ge=1, le=131072)
|
||||
prompt_style: Literal["generic", "hy_mt"] = "generic"
|
||||
structured_output: bool = False
|
||||
top_p: float | None = Field(default=None, gt=0, le=1)
|
||||
top_k: int | None = Field(default=None, ge=0)
|
||||
repetition_penalty: float | None = Field(default=None, gt=0, le=3)
|
||||
@@ -36,10 +37,26 @@ class Settings(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
database: str = "data/translations.sqlite3"
|
||||
port: int = Field(default=8787, ge=1, le=65535)
|
||||
# Web pages allowed to call this API from the browser, e.g. "https://games.example".
|
||||
# No wildcard: any site could otherwise use your model and read your projects.
|
||||
allowed_origins: list[str] = Field(default_factory=list, max_length=20)
|
||||
providers: dict[str, ProviderConfig] = Field(default_factory=lambda: {
|
||||
"lmstudio": ProviderConfig(prompt_style="hy_mt", temperature=0.7, top_p=0.6, top_k=20, repetition_penalty=1.05)
|
||||
"lmstudio": ProviderConfig(prompt_style="hy_mt", structured_output=True, temperature=0.7, top_p=0.6, top_k=20, repetition_penalty=1.05)
|
||||
})
|
||||
|
||||
@field_validator("allowed_origins")
|
||||
@classmethod
|
||||
def validate_origins(cls, value: list[str]) -> list[str]:
|
||||
return list(dict.fromkeys(_check_origin(item) for item in value))
|
||||
|
||||
|
||||
def _check_origin(value: str) -> str:
|
||||
from urllib.parse import urlsplit
|
||||
url = urlsplit(value)
|
||||
if url.scheme not in {"http", "https"} or not url.hostname or url.path not in {"", "/"} or url.query or url.fragment or url.username:
|
||||
raise ValueError("allowed_origins entries look like https://games.example[:port], without a path")
|
||||
return f"{url.scheme}://{url.netloc}"
|
||||
|
||||
|
||||
def load_settings(path: str = "config.toml") -> Settings:
|
||||
config_path = Path(path).resolve()
|
||||
|
||||
Reference in new issue
Block a user