Skip to content

Commit 3d02033

Browse files
committed
fix: improved typechecking coverage and fixed issues
1 parent 598b538 commit 3d02033

File tree

7 files changed

+27
-19
lines changed

7 files changed

+27
-19
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ repos:
1616
hooks:
1717
- id: mypy
1818
additional_dependencies: [
19+
"gptme @ git+https://github.com/ErikBjare/gptme.git",
20+
rich,
21+
python-dotenv,
1922
tweepy,
2023
flask,
2124
discord.py,

mypy.ini

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ strict_optional = True
1111
[mypy.plugins.django.*]
1212
ignore_missing_imports = True
1313

14-
[mypy-dotenv.*]
15-
ignore_missing_imports = True
16-
17-
[mypy-rich.*]
18-
ignore_missing_imports = True
19-
2014
[mypy-gptme.*]
2115
ignore_missing_imports = True
2216

scripts/discord/discord_bot.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import re
1717
from copy import copy
18+
from pathlib import Path
1819
from typing import AsyncGenerator
1920
from typing import Callable
2021
from typing import Dict
@@ -64,12 +65,12 @@
6465

6566
# Get workspace folder (location of `gptme.toml`):
6667
workspace_root = get_project_gptme_dir()
67-
logsdir = workspace_root / "logs_discord"
68+
logsdir = workspace_root / "logs_discord" if workspace_root else Path("logs_discord")
6869

6970
# Load environment variables
7071
env_files = [".env", ".env.discord"]
7172
for env_file in env_files:
72-
if (workspace_root / env_file).exists():
73+
if workspace_root and (workspace_root / env_file).exists():
7374
load_dotenv(env_file, override=True)
7475
logger.info(f"Loaded environment from {env_file}")
7576

@@ -696,7 +697,7 @@ async def tools(ctx: commands.Context) -> None:
696697
tool_info = "Available tools:\n\n"
697698
for tool in tools:
698699
tool_info += f"**{tool.name}**\n"
699-
tool_info += f"- Description: {tool.description}\n"
700+
tool_info += f"- Description: {tool.desc}\n"
700701
if tool.block_types:
701702
tool_info += f"- Usage: ```{', '.join(tool.block_types)}```\n"
702703
tool_info += "\n"
@@ -936,7 +937,7 @@ def main() -> None:
936937
tool_allowlist = frozenset(["read", "save", "append", "patch", "shell"])
937938

938939
# Initialize gptme and tools
939-
init(model=MODEL, interactive=False, tool_allowlist=tool_allowlist)
940+
init(model=MODEL, interactive=False, tool_allowlist=list(tool_allowlist))
940941
tools = get_tools()
941942
if not tools:
942943
logger.error("No tools loaded in gptme")

scripts/twitter/llm.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def create_review_prompt(draft: Dict, config: Dict) -> str:
329329
def get_system_prompt() -> Message:
330330
"""Get system prompt for Twitter interactions."""
331331
workspace = get_project_git_dir()
332-
context = get_workspace_prompt(workspace)
332+
context = get_workspace_prompt(workspace) if workspace else ""
333333

334334
def get_format_examples() -> Dict[str, Any]:
335335
"""Generate format examples from dataclasses"""
@@ -431,6 +431,8 @@ def generate_response(tweet: Dict, eval_result: EvaluationResponse) -> Optional[
431431

432432
# Get LLM response
433433
model = get_default_model()
434+
if not model:
435+
raise RuntimeError("default model not set")
434436
messages = [get_system_prompt(), Message("user", prompt)]
435437
response = reply(messages, model.full, stream=False)
436438

@@ -444,6 +446,8 @@ def review_draft(draft: Dict) -> ReviewResponse:
444446

445447
# Get LLM response
446448
model = get_default_model()
449+
if not model:
450+
raise RuntimeError("default model not set")
447451
messages = [get_system_prompt(), Message("user", prompt)]
448452
response = reply(messages, model.full, stream=False)
449453

scripts/twitter/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ def list_drafts(status: str) -> List[Path]:
450450
)
451451
def cli(model: str):
452452
"""Twitter Workflow Manager"""
453-
init_gptme(model=model, interactive=False, tool_allowlist=frozenset())
453+
init_gptme(model=model, interactive=False, tool_allowlist=[])
454454

455455

456456
@cli.command()

scripts/wordcount.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ def main() -> None:
103103
# Add rows
104104
for result in results:
105105
table.add_row(
106-
result["source"],
106+
str(result["source"]),
107107
str(result["lines"]),
108108
str(result["words"]),
109109
str(result["chars"]),
110-
result["top_words"],
110+
str(result["top_words"]),
111111
)
112112

113113
# Add total row for multiple files

tools/tool_pushover.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
2+
23
import requests
3-
from gptme.tools import ToolSpec, Parameter, ToolUse
44
from gptme.message import Message
5-
5+
from gptme.tools import Parameter, ToolSpec, ToolUse
6+
from gptme.tools.base import ConfirmFunc
67

78
PUSHOVER_USER_KEY = os.getenv("PUSHOVER_USER_KEY")
89
PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
@@ -12,10 +13,15 @@ def has_pushover_conf():
1213
return PUSHOVER_USER_KEY and PUSHOVER_API_TOKEN
1314

1415

15-
def execute(content: str | None, args: list[str] | None, kwargs: dict[str, str] | None, confirm=None) -> Message:
16-
if content is not None and args is not None:
16+
def execute(
17+
code: str | None,
18+
args: list[str] | None,
19+
kwargs: dict[str, str] | None,
20+
confirm: ConfirmFunc,
21+
) -> Message:
22+
if code is not None and args is not None:
1723
title = args[0]
18-
message = content
24+
message = code
1925
elif kwargs is not None:
2026
title = kwargs.get("title", "No title")
2127
message = kwargs.get("message", "No message")

0 commit comments

Comments
 (0)