Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions hyperextract/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def search(
)


def chat_loop(ka, ka_path: str):
def chat_loop(ka, ka_path: str, top_k: int = 3):
"""Interactive chat loop."""
console.print(
"\n[bold green]Entering interactive mode. Type 'exit' or 'quit' to stop.[/bold green]\n"
Expand All @@ -669,7 +669,7 @@ def chat_loop(ka, ka_path: str):
break
if not query.strip():
continue
response = ka.chat(query)
response = ka.chat(query, top_k=top_k)
console.print()
console.print(response.content)
console.print()
Expand Down Expand Up @@ -740,7 +740,7 @@ def talk(
raise typer.Exit(1)

if interactive:
chat_loop(ka, ka_path)
chat_loop(ka, ka_path, top_k=top_k)
else:
with console.status("[bold blue]Thinking..."):
try:
Expand Down
20 changes: 20 additions & 0 deletions tests/cli/test_talk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Tests for the interactive `he talk` chat loop."""

import hyperextract.cli.cli as climod


def test_chat_loop_passes_top_k(monkeypatch):
"""Interactive chat must forward top_k to ka.chat, not use the default."""
recorded = {}

class _StubKA:
def chat(self, query, top_k=3):
recorded["top_k"] = top_k
return type("_Resp", (), {"content": "ok"})()

queries = iter(["hello", "exit"])
monkeypatch.setattr(climod.console, "input", lambda *a, **k: next(queries))

climod.chat_loop(_StubKA(), "some/ka", top_k=10)

assert recorded["top_k"] == 10