Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Nov 17, 2024
1 parent d73de53 commit f9e4aee
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 11 deletions.
22 changes: 22 additions & 0 deletions gptme/logmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,28 @@ def get_user_conversations() -> Generator[ConversationMeta, None, None]:
yield conv


def format_conversation(conv: ConversationMeta) -> str:
"""Format a conversation for display."""
return f"{conv.name}: {conv.messages} messages, last modified {conv.modified}"


def list_conversations(limit: int = 20, formatter: Callable[[ConversationMeta], str] | None = None) -> tuple[list[ConversationMeta], bool]:
"""List conversations with a limit, returns (conversations, found_any)."""
if formatter is None:
formatter = format_conversation

found = False
conversations = []
for conv in get_user_conversations():
if limit <= 0:
break
conversations.append(conv)
limit -= 1
found = True

return conversations, found


def _gen_read_jsonl(path: PathLike) -> Generator[Message, None, None]:
with open(path) as file:
for line in file.readlines():
Expand Down
15 changes: 7 additions & 8 deletions gptme/util/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ def chats():
@click.option("-n", "--limit", default=20, help="Maximum number of chats to show.")
def chats_list(limit: int):
"""List conversation logs."""
found = False
for conv in get_user_conversations():
if limit <= 0:
break
print(f"{conv.name}: {conv.messages} messages, last modified {conv.modified}")
limit -= 1
found = True

from ..logmanager import list_conversations, format_conversation

conversations, found = list_conversations(limit)
if not found:
print("No conversations found.")
return

for conv in conversations:
print(format_conversation(conv))


@chats.command("read")
Expand Down
89 changes: 86 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ myst-parser = "*"
# types
types-tabulate = "*"
types-lxml = "*"
pylint = "^3.3.1"

[tool.poetry.extras]
server = ["flask", "flask-cors"]
Expand Down

0 comments on commit f9e4aee

Please sign in to comment.