Skip to content

Commit 33651c0

Browse files
committed
Add local chat completions fallback
1 parent 0c2f54e commit 33651c0

4 files changed

Lines changed: 45 additions & 5 deletions

File tree

mu_unscramble_bot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""MU unscramble bot package."""
22

3-
__version__ = "0.3.17"
3+
__version__ = "0.3.18"

mu_unscramble_bot/solver.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,21 @@ def _request_text(
425425
if timeout_seconds is not None:
426426
request["timeout"] = timeout_seconds
427427

428-
response = self.client.responses.create(**request)
429-
return getattr(response, "output_text", "").strip()
428+
try:
429+
response = self.client.responses.create(**request)
430+
text = getattr(response, "output_text", "").strip()
431+
if text:
432+
return text
433+
except Exception:
434+
# Many local OpenAI-compatible servers expose only chat/completions.
435+
pass
436+
437+
return self._request_chat_text(
438+
instructions=instructions,
439+
prompt=prompt,
440+
max_output_tokens=max_output_tokens,
441+
timeout_seconds=timeout_seconds,
442+
)
430443

431444
def _is_openrouter(self) -> bool:
432445
return bool(self.base_url and "openrouter.ai" in self.base_url.lower())
@@ -465,6 +478,33 @@ def _request_openrouter_text(
465478

466479
return ""
467480

481+
def _request_chat_text(
482+
self,
483+
*,
484+
instructions: str,
485+
prompt: str,
486+
max_output_tokens: int,
487+
timeout_seconds: float | None = None,
488+
) -> str:
489+
token_budget = max(96, max_output_tokens)
490+
request: dict[str, object] = {
491+
"model": self.model,
492+
"messages": [
493+
{"role": "system", "content": instructions},
494+
{"role": "user", "content": prompt},
495+
],
496+
"temperature": 0,
497+
}
498+
request["max_tokens"] = token_budget
499+
if timeout_seconds is not None:
500+
request["timeout"] = timeout_seconds
501+
502+
completion = self.client.chat.completions.create(**request)
503+
choice = completion.choices[0] if completion.choices else None
504+
message = choice.message if choice else None
505+
content = (message.content or "").strip() if message else ""
506+
return content
507+
468508

469509
class SolverChain:
470510
def __init__(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "mu-unscramble-bot"
7-
version = "0.3.17"
7+
version = "0.3.18"
88
description = "Screen-reading MU Online helper that watches the center yellow text, solves the puzzle, and can auto-submit the answer."
99
readme = "README.md"
1010
requires-python = ">=3.12"

scripts/build_release.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
param(
2-
[string]$Version = "0.3.17",
2+
[string]$Version = "0.3.18",
33
[string]$PythonPath = ""
44
)
55

0 commit comments

Comments
 (0)