Skip to content

Commit e5eaaf8

Browse files
m96-chanclaude
andcommitted
Fix ruff lint errors
- Remove unused import `re` in database.py - Fix f-string without placeholders in database.py - Shorten long lines in agent.py (descriptions and cut_url) - Include pending image display improvements Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 61f684a commit e5eaaf8

4 files changed

Lines changed: 54 additions & 12 deletions

File tree

src/comike_cli/agent.py

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,40 @@
88
from .api import CircleMsClient
99
from .image import fetch_image_as_braille
1010

11+
# Callback for direct output (set by main.py)
12+
_direct_output_callback = None
13+
14+
15+
def set_direct_output_callback(callback):
16+
"""Set callback for direct CLI output (bypassing LLM)."""
17+
global _direct_output_callback
18+
_direct_output_callback = callback
19+
1120
SYSTEM_PROMPT = """あなたはコミケWebカタログの検索アシスタントです。
1221
ユーザーの自然言語での質問に対して、適切なAPI呼び出しを行い、結果をわかりやすく説明します。
1322
1423
利用可能な機能:
1524
- サークル検索(名前、ジャンル、館で検索)
1625
- 頒布物検索(作品名で検索)
1726
- サークル詳細情報の取得
27+
- サークルカット画像の表示
1828
- お気に入りサークルの一覧・追加・削除
1929
- イベント一覧の取得
2030
- ユーザー情報の取得
2131
2232
回答は日本語で、簡潔にお願いします。
33+
34+
重要: show_circle_cutの結果が{"status": "displayed"}の場合、画像は既にCLIに直接表示されています。
35+
画像を再度テキストで表現したり、Braille文字で描画しようとしないでください。
36+
「画像を表示しました」と簡潔に伝えるだけで十分です。
2337
"""
2438

2539
TOOLS = [
2640
{
2741
"type": "function",
2842
"function": {
2943
"name": "search_circles",
30-
"description": "サークルを検索します(配置情報付き)。ローカルデータベースを使用します。",
44+
"description": "サークルを検索します(配置情報付き)",
3145
"parameters": {
3246
"type": "object",
3347
"properties": {
@@ -37,7 +51,7 @@
3751
},
3852
"block": {
3953
"type": "string",
40-
"description": "ブロック名(あ/ア/A等)。ひらがな・カタカナは区別、英語は大文字小文字・全角半角を区別しない",
54+
"description": "ブロック名(あ/ア/A等)",
4155
},
4256
"day": {
4357
"type": "integer",
@@ -305,14 +319,36 @@ def _execute_function(self, name: str, args: dict) -> Any:
305319
elif name == "get_user_info":
306320
return self.api.get_user_info()
307321
elif name == "show_circle_cut":
322+
wcid = args.get("wcid")
323+
if not wcid:
324+
return {"error": "wcidが指定されていません"}
308325
# Get circle info to find image URL
309-
circle_info = self.api.get_circle(args["wcid"])
326+
circle_info = self.api.get_circle(wcid)
327+
if circle_info.get("status") != "success":
328+
return {"error": f"APIエラー: {circle_info.get('status')}", "detail": circle_info}
310329
circle = circle_info.get("response", {}).get("circle", {})
311-
cut_url = circle.get("cut_url") or circle.get("cut_web_url") or circle.get("cut_base_url")
330+
if not circle:
331+
return {"error": "サークル情報が見つかりません", "wcid": wcid}
332+
# Try all possible image URLs
333+
cut_url = (
334+
circle.get("cut_url")
335+
or circle.get("cut_web_url")
336+
or circle.get("cut_base_url")
337+
)
312338
if not cut_url:
313-
return {"error": "サークルカット画像が見つかりません"}
314-
braille_art = fetch_image_as_braille(cut_url)
315-
return {"braille_art": braille_art, "circle_name": circle.get("name", "")}
339+
return {
340+
"error": "サークルカット画像URLが見つかりません",
341+
"circle_name": circle.get("name", ""),
342+
}
343+
try:
344+
braille_art = fetch_image_as_braille(cut_url)
345+
circle_name = circle.get("name", "")
346+
# Direct output to CLI, bypassing LLM
347+
if _direct_output_callback:
348+
_direct_output_callback(f"\n{circle_name}\n{braille_art}\n")
349+
return {"status": "displayed", "circle_name": circle_name}
350+
except Exception as e:
351+
return {"error": f"画像取得エラー: {str(e)}", "url": cut_url}
316352
else:
317353
raise ValueError(f"Unknown function: {name}")
318354

src/comike_cli/database.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Local SQLite database for circle placement information."""
22

3-
import re
43
import sqlite3
54
import zipfile
65
from io import BytesIO
@@ -59,7 +58,7 @@ def download(self, db_url: str, event_id: int) -> None:
5958
# Already downloaded
6059
return
6160

62-
print(f"データベースをダウンロード中...")
61+
print("データベースをダウンロード中...")
6362
response = httpx.get(db_url, timeout=120.0, follow_redirects=True)
6463
response.raise_for_status()
6564

src/comike_cli/image.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,12 @@ def get_pixel(x: int, y: int) -> bool:
9696
return "\n".join(lines)
9797

9898

99-
def fetch_image_as_braille(url: str, width: int = 60, edge_mode: bool = True) -> str:
100-
"""Fetch image from URL and convert to Braille art."""
99+
def fetch_image_as_braille(url: str, width: int = 40, edge_mode: bool = False) -> str:
100+
"""Fetch image from URL and convert to Braille art.
101+
102+
Default width=40 for circle cuts (typically 180x252, tall images).
103+
Default edge_mode=False uses dithering for better gradation.
104+
"""
101105
response = httpx.get(url, timeout=30.0)
102106
response.raise_for_status()
103107

src/comike_cli/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from rich.markdown import Markdown
1010
from rich.panel import Panel
1111

12-
from .agent import Agent
12+
from .agent import Agent, set_direct_output_callback
1313
from .api import CircleMsClient
1414
from .auth import AuthManager
1515
from .config import Config
@@ -71,6 +71,9 @@ def main():
7171

7272
api_client = CircleMsClient(auth_manager)
7373
agent = Agent(config.openai_api_key, api_client)
74+
75+
# Set callback for direct output (e.g., images)
76+
set_direct_output_callback(lambda text: console.print(text))
7477
except Exception as e:
7578
console.print(f"[red]初期化エラー: {e}[/red]")
7679
sys.exit(1)

0 commit comments

Comments
 (0)