Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added read_chat function to chats tool #115

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion gptme/tools/chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,39 @@ def search_chats(query: str, max_results: int = 5) -> None:
)


def read_chat(conversation: str, max_results: int = 5, incl_system=False) -> None:
"""
Read a specific conversation log.

Args:
conversation (str): The name of the conversation to read.
max_results (int): Maximum number of messages to display.
incl_system (bool): Whether to include system messages.
"""
# noreorder
from ..logmanager import LogManager, get_conversations # fmt: skip

conversations = list(get_conversations())

for conv in conversations:
if conv["name"] == conversation:
log_path = Path(conv["path"])
logmanager = LogManager.load(log_path)
print(f"Reading conversation: {conversation}")
i = 0
for msg in logmanager.log:
if msg.role != "system" or incl_system:
print(f"{i}. {_format_message_snippet(msg)}")
i += 1
else:
print(f"{i}. (system message)")
if i >= max_results:
break
break
else:
print(f"Conversation '{conversation}' not found.")


instructions = """
The chats tool allows you to list, search, and summarize past conversation logs.
"""
Expand All @@ -163,5 +196,5 @@ def search_chats(query: str, max_results: int = 5) -> None:
desc="List, search, and summarize past conversation logs",
instructions=instructions,
examples=examples,
functions=[list_chats, search_chats],
functions=[list_chats, search_chats, read_chat],
)
Loading