ReviewLlama/src/reviewllama/configs.py

60 lines
1.3 KiB
Python
Raw Normal View History

2025-06-08 06:31:34 -04:00
from dataclasses import dataclass
from pathlib import Path
from typing import List
2025-06-08 06:31:34 -04:00
@dataclass(frozen=True)
class OllamaConfig:
"""Configuration for Ollama client."""
model: str
server_url: str
timeout: int
max_retries: int
@dataclass(frozen=True)
class ReviewConfig:
"""Complete configuration for ReviewLlama."""
paths: List[Path]
ollama: OllamaConfig
2025-06-09 21:54:37 -04:00
base_branch: str
2025-06-08 06:31:34 -04:00
def create_ollama_config(
model: str, server_url: str, timeout: int, max_retries: int
) -> OllamaConfig:
"""Create OllamaConfig with validated parameters."""
return OllamaConfig(
model=model,
2025-06-09 22:00:16 -04:00
server_url=server_url,
2025-06-08 06:31:34 -04:00
timeout=timeout,
max_retries=max_retries,
)
def create_review_config(
2025-06-09 21:54:37 -04:00
paths: List[Path], ollama_config: OllamaConfig, base_branch: str
2025-06-08 06:31:34 -04:00
) -> ReviewConfig:
"""Create complete ReviewConfig from validated components."""
2025-06-09 21:54:37 -04:00
return ReviewConfig(paths=paths, ollama=ollama_config, base_branch=base_branch)
2025-06-08 06:31:34 -04:00
def create_config_from_vars(
2025-06-09 21:54:37 -04:00
paths: List[Path],
model: str,
server_url: str,
timeout: int,
max_retries: int,
base_branch: str,
2025-06-08 06:31:34 -04:00
):
ollama_config = OllamaConfig(
model=model,
server_url=server_url,
timeout=timeout,
max_retries=max_retries,
)
2025-06-09 21:54:37 -04:00
return create_review_config(paths, ollama_config, base_branch)