2025-07-14 20:57:47 -04:00
|
|
|
import argparse
|
2025-07-05 15:16:18 -04:00
|
|
|
from dataclasses import dataclass, field
|
2025-06-08 06:31:34 -04:00
|
|
|
from pathlib import Path
|
2025-06-09 21:22:50 -04:00
|
|
|
from typing import List
|
2025-06-08 06:31:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
|
|
class OllamaConfig:
|
|
|
|
"""Configuration for Ollama client."""
|
|
|
|
|
2025-07-05 15:16:18 -04:00
|
|
|
chat_model: str
|
|
|
|
embedding_model: str
|
2025-06-18 14:26:21 -04:00
|
|
|
base_url: str
|
|
|
|
system_prompt: str
|
2025-07-05 15:16:18 -04:00
|
|
|
# TODO: Update this to be a passed in value
|
|
|
|
temperature: float = field(default=0.7)
|
2025-06-08 06:31:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
@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(
|
2025-07-05 15:16:18 -04:00
|
|
|
model: str,
|
|
|
|
server_url: str,
|
|
|
|
system_prompt: str,
|
|
|
|
temperature=0.7,
|
|
|
|
embedding_model="nomic-embed-text",
|
2025-06-08 06:31:34 -04:00
|
|
|
) -> OllamaConfig:
|
|
|
|
"""Create OllamaConfig with validated parameters."""
|
2025-07-05 15:16:18 -04:00
|
|
|
return OllamaConfig(
|
|
|
|
chat_model=model,
|
|
|
|
embedding_model=embedding_model,
|
|
|
|
base_url=server_url,
|
|
|
|
system_prompt=system_prompt,
|
|
|
|
temperature=temperature,
|
|
|
|
)
|
2025-06-08 06:31:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2025-07-14 20:57:47 -04:00
|
|
|
def namespace_to_config(
|
|
|
|
namespace: argparse.Namespace
|
2025-06-08 06:31:34 -04:00
|
|
|
):
|
2025-07-14 20:57:47 -04:00
|
|
|
"""Transform argparse namespace into ReviewConfig."""
|
|
|
|
paths = [Path(path_str) for path_str in namespace.paths]
|
2025-06-08 06:31:34 -04:00
|
|
|
ollama_config = OllamaConfig(
|
2025-07-14 20:57:47 -04:00
|
|
|
chat_model=namespace.model, base_url=namespace.server_url, system_prompt=namespace.system_prompt, embedding_model=namespace.embedding_model
|
2025-06-08 06:31:34 -04:00
|
|
|
)
|
|
|
|
|
2025-07-14 20:57:47 -04:00
|
|
|
return create_review_config(paths, ollama_config, namespace.base_branch)
|