Skip to content

Commit

Permalink
fix: fix /summarize command (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare authored Jan 7, 2025
1 parent b6f337a commit c41df98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 10 additions & 5 deletions gptme/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from time import sleep
from typing import Literal

from .constants import INTERRUPT_CONTENT

from . import llm
from .constants import INTERRUPT_CONTENT
from .logmanager import LogManager, prepare_messages
from .message import (
Message,
Expand All @@ -17,7 +16,13 @@
print_msg,
toml_to_msgs,
)
from .tools import ToolUse, execute_msg, get_tools, ConfirmFunc, get_tool_format
from .tools import (
ConfirmFunc,
ToolUse,
execute_msg,
get_tool_format,
get_tools,
)
from .util.cost import log_costs
from .util.export import export_chat_to_html
from .util.useredit import edit_text_with_editor
Expand Down Expand Up @@ -101,10 +106,10 @@ def handle_cmd(
new_name = args[0] if args else input("New name: ")
manager.fork(new_name)
case "summarize":
manager.undo(1, quiet=True)
msgs = prepare_messages(manager.log.messages)
msgs = [m for m in msgs if not m.hide]
summary = llm.summarize(msgs)
print(f"Summary: {summary}")
print_msg(llm.summarize(msgs))
case "edit":
# edit previous messages
# first undo the '/edit' command itself
Expand Down
4 changes: 1 addition & 3 deletions gptme/llm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _summarize_str(content: str) -> str:
messages = [
Message(
"system",
content="You are a helpful assistant that helps summarize messages with an AI assistant through a tool called gptme.",
content="You are a helpful assistant that helps summarize messages into bullet format. Dont use any preamble or heading, start directly with a bullet list.",
),
Message("user", content=f"Summarize this:\n{content}"),
]
Expand Down Expand Up @@ -245,9 +245,7 @@ def summarize(msg: str | Message | list[Message]) -> Message:
else:
content = "\n".join(format_msgs(msg))

logger.info(f"{content[:200]=}")
summary = _summarize_helper(content)
logger.info(f"{summary[:200]=}")

# construct message from summary
content = f"Here's a summary of the conversation:\n{summary}"
Expand Down

0 comments on commit c41df98

Please sign in to comment.