Close local release-quality gaps and reconcile workplan status
All checks were successful
CI Smoke / host-smoke (push) Successful in 1s
CI Smoke / container-smoke (push) Successful in 2s

Assistant: codex
Assistant-Model: gpt-6-astra
Assistant-Session: 01a0e332-3365-77c0-8491-084e9ea33ac1
This commit is contained in:
tegwick 2026-09-27 17:36:27 +02:00
parent 37436bb562
commit 7cd633986e
56 changed files with 462 additions and 237 deletions

View file

@ -3,18 +3,18 @@ OpenAI (ChatGPT) adapter — calls the OpenAI chat completions API.
"""
import time
from typing import Optional, Dict, Any
from typing import Any
from llm_connect.adapter import LLMAdapter
from llm_connect.models import RunConfig, LLMResponse
from llm_connect.config import resolve_api_key, find_project_root
from llm_connect._http import post_json
from llm_connect._payload import merge_openai_chat_model_params
from llm_connect.adapter import LLMAdapter
from llm_connect.config import find_project_root, resolve_api_key
from llm_connect.exceptions import (
LLMConfigurationError,
LLMAPIError,
LLMConfigurationError,
LLMRateLimitError,
)
from llm_connect.models import LLMResponse, RunConfig
_DEFAULT_MODEL = "gpt-4.1-mini"
_API_BASE = "https://api.openai.com/v1"
@ -25,9 +25,9 @@ class OpenAIAdapter(LLMAdapter):
def __init__(
self,
model: Optional[str] = None,
api_key: Optional[str] = None,
system_prompt: Optional[str] = None,
model: str | None = None,
api_key: str | None = None,
system_prompt: str | None = None,
max_retries: int = 3,
**_kwargs: Any,
):
@ -55,12 +55,12 @@ class OpenAIAdapter(LLMAdapter):
self._preflight_budget(config)
model = self._model
messages: list[Dict[str, str]] = []
messages: list[dict[str, str]] = []
if self._system_prompt:
messages.append({"role": "system", "content": self._system_prompt})
messages.append({"role": "user", "content": prompt})
payload: Dict[str, Any] = {
payload: dict[str, Any] = {
"model": model,
"messages": messages,
"temperature": config.temperature,
@ -114,11 +114,11 @@ class OpenAIAdapter(LLMAdapter):
def _post_with_retries(
self,
url: str,
payload: Dict[str, Any],
headers: Dict[str, str],
payload: dict[str, Any],
headers: dict[str, str],
timeout: int,
) -> Dict[str, Any]:
last_exc: Optional[Exception] = None
) -> dict[str, Any]:
last_exc: Exception | None = None
for attempt in range(self._max_retries + 1):
try:
return post_json(url, payload, headers, timeout=timeout)