client.ask routes through the rag skill; always show citations in CLI
This commit is contained in:
parent
57d077e2c3
commit
d96d2eeb0f
5 changed files with 606 additions and 281 deletions
|
|
@ -443,14 +443,12 @@ class HaikuRAGApp: # pragma: no cover
|
|||
async def ask(
|
||||
self,
|
||||
question: str,
|
||||
cite: bool = False,
|
||||
filter: str | None = None,
|
||||
):
|
||||
"""Ask a question using the RAG system.
|
||||
|
||||
Args:
|
||||
question: The question to ask
|
||||
cite: Include citations in the answer
|
||||
filter: SQL WHERE clause to filter documents
|
||||
"""
|
||||
async with HaikuRAG(
|
||||
|
|
@ -465,9 +463,8 @@ class HaikuRAGApp: # pragma: no cover
|
|||
self.console.print()
|
||||
self.console.print("[bold green]Answer:[/bold green]")
|
||||
self.console.print(Markdown(answer))
|
||||
if cite and citations:
|
||||
for renderable in format_citations_rich(citations):
|
||||
self.console.print(renderable)
|
||||
for renderable in format_citations_rich(citations):
|
||||
self.console.print(renderable)
|
||||
|
||||
async def analyze(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -369,11 +369,6 @@ def ask( # pragma: no cover
|
|||
"--db",
|
||||
help="Path to the LanceDB database file",
|
||||
),
|
||||
cite: bool = typer.Option(
|
||||
False,
|
||||
"--cite",
|
||||
help="Include citations in the response",
|
||||
),
|
||||
filter: str | None = typer.Option(
|
||||
None,
|
||||
"--filter",
|
||||
|
|
@ -385,7 +380,6 @@ def ask( # pragma: no cover
|
|||
asyncio.run(
|
||||
app.ask(
|
||||
question=question,
|
||||
cite=cite,
|
||||
filter=filter,
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -368,12 +368,11 @@ class HaikuRAG:
|
|||
async def ask(
|
||||
self,
|
||||
question: str,
|
||||
system_prompt: str | None = None,
|
||||
filter: str | None = None,
|
||||
) -> "tuple[str, list[Citation]]":
|
||||
from haiku.rag.client.agents import ask
|
||||
|
||||
return await ask(self, question, system_prompt, filter)
|
||||
return await ask(self, question, filter)
|
||||
|
||||
async def research(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -9,24 +9,32 @@ if TYPE_CHECKING:
|
|||
async def ask(
|
||||
client: "HaikuRAG",
|
||||
question: str,
|
||||
system_prompt: str | None = None,
|
||||
filter: str | None = None,
|
||||
) -> "tuple[str, list[Citation]]":
|
||||
"""Ask a question using the configured QA agent.
|
||||
"""Ask a question against the knowledge base via the rag skill.
|
||||
|
||||
Args:
|
||||
client: The HaikuRAG client.
|
||||
question: The question to ask.
|
||||
system_prompt: Optional custom system prompt for the QA agent.
|
||||
filter: SQL WHERE clause to filter documents.
|
||||
|
||||
Returns:
|
||||
Tuple of (answer text, list of resolved citations).
|
||||
"""
|
||||
from haiku.rag.agents.qa import get_qa_agent
|
||||
from haiku.rag.skills.rag import RAGState, create_skill
|
||||
from haiku.rag.utils import get_model
|
||||
from haiku.skills import run_skill
|
||||
|
||||
qa_agent = get_qa_agent(client, config=client._config, system_prompt=system_prompt)
|
||||
return await qa_agent.answer(question, filter=filter)
|
||||
skill = create_skill(db_path=client.store.db_path, config=client._config)
|
||||
state = RAGState(document_filter=filter)
|
||||
model = get_model(client._config.qa.model, client._config)
|
||||
answer, _, _ = await run_skill(model, skill, question, state=state)
|
||||
citations = [
|
||||
state.citation_index[cid]
|
||||
for cid in state.citations
|
||||
if cid in state.citation_index
|
||||
]
|
||||
return answer, citations
|
||||
|
||||
|
||||
async def research(
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue