fix: resolve all ruff linting errors across coach module

This commit is contained in:
KoalaTrapLord authored and GitHub committed 2026-03-26 15:30:27 -04:00
1 parent 0aa57ab7d2
commit 15bd6f42bb
5 files changed
+28 -32

No files matched your search

+25 -25
View File
@@ -279,32 +279,32 @@ class CoachService:
import anthropic
anthropic_key = ANTHROPIC_API_KEY
if not anthropic_key:
raise ConnectionError("Anthropic API key not configured. Set ANTHROPIC_API_KEY env var.")
raise ConnectionError("Anthropic API key not configured. Set ANTHROPIC_API_KEY env var.")
aclient = anthropic.AsyncAnthropic(api_key=anthropic_key)
resp = await aclient.messages.create(
model=ANTHROPIC_MODEL,
system=system_prompt,
messages=[{"role": "user", "content": user_prompt}],
max_tokens=8192,
temperature=0.7,
)
content = resp.content[0].text if resp.content else ""
usage = resp.usage
resp = await aclient.messages.create(
model=ANTHROPIC_MODEL,
system=system_prompt,
messages=[{"role": "user", "content": user_prompt}],
max_tokens=8192,
temperature=0.7,
)
content = resp.content[0].text if resp.content else ""
usage = resp.usage
# Build an LLMResponse-compatible object
from types import SimpleNamespace
llm_response = SimpleNamespace(
content=content,
model=resp.model,
prompt_tokens=usage.input_tokens if usage else 0,
completion_tokens=usage.output_tokens if usage else 0,
parsed_json=None,
)
try:
cleaned = re.sub(r'^```(?:json)?\s*', '', content.strip())
cleaned = re.sub(r'\s*```$', '', cleaned.strip())
llm_response.parsed_json = json.loads(cleaned)
except (json.JSONDecodeError, ValueError):
# Build an LLMResponse-compatible object
from types import SimpleNamespace
llm_response = SimpleNamespace(
content=content,
model=resp.model,
prompt_tokens=usage.input_tokens if usage else 0,
completion_tokens=usage.output_tokens if usage else 0,
parsed_json=None,
)
try:
cleaned = re.sub(r'^```(?:json)?\s*', '', content.strip())
cleaned = re.sub(r'\s*```$', '', cleaned.strip())
llm_response.parsed_json = json.loads(cleaned)
except (json.JSONDecodeError, ValueError):
# Try to find JSON object in the text
match = re.search(r'\{[\s\S]*\}', content)
if match:
@@ -313,7 +313,7 @@ class CoachService:
except json.JSONDecodeError:
pass
else:
llm_response = await self.llm.chat(system_prompt, user_prompt)
llm_response = await self.llm.chat(system_prompt, user_prompt)
# 6. Parse response into CoachSession
session_id = f"sess-{datetime.now(timezone.utc).strftime('%Y%m%d-%H%M%S')}-{uuid.uuid4().hex[:6]}"
-2
View File
@@ -21,7 +21,6 @@ import json
import logging
import re
import os
import time
from pathlib import Path
from typing import List, Optional, Tuple
from urllib.request import urlopen, Request
@@ -331,7 +330,6 @@ class MTGEmbeddingIndex:
d = np.load(str(CUSTOM_CACHE_PATH), allow_pickle=True)
for n in d["names"]:
existing_names.add(n.lower())
existing = dict(d)
except Exception:
pass
-1
View File
@@ -5,7 +5,6 @@ Pydantic v2 models for deck reports, coach requests/responses,
and coaching session persistence.
"""
from datetime import datetime
from typing import List, Optional, Dict
from pydantic import BaseModel, Field
-1
View File
@@ -6,7 +6,6 @@ Injects deck report data, underperformer analysis, and
candidate replacement cards into a structured template.
"""
import json
from typing import List, Dict, Optional
from .models import DeckReport, CoachGoals, CardPerformance
+3 -3
View File
@@ -5,7 +5,7 @@ Constructs the user message for Claude Opus deck generation
from a DeckGenV3Request.
"""
from typing import List, Optional
from typing import List
def build_user_prompt(
@@ -36,8 +36,8 @@ def build_user_prompt(
ci_str = ", ".join(color_identity) if color_identity else "Unknown"
lines = [
f"Build a complete 100-card Commander deck.",
f"",
"Build a complete 100-card Commander deck.",
"",
f"COMMANDER: {commander}",
]