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(
|
async def ask(
|
||||||
self,
|
self,
|
||||||
question: str,
|
question: str,
|
||||||
cite: bool = False,
|
|
||||||
filter: str | None = None,
|
filter: str | None = None,
|
||||||
):
|
):
|
||||||
"""Ask a question using the RAG system.
|
"""Ask a question using the RAG system.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
question: The question to ask
|
question: The question to ask
|
||||||
cite: Include citations in the answer
|
|
||||||
filter: SQL WHERE clause to filter documents
|
filter: SQL WHERE clause to filter documents
|
||||||
"""
|
"""
|
||||||
async with HaikuRAG(
|
async with HaikuRAG(
|
||||||
|
|
@ -465,9 +463,8 @@ class HaikuRAGApp: # pragma: no cover
|
||||||
self.console.print()
|
self.console.print()
|
||||||
self.console.print("[bold green]Answer:[/bold green]")
|
self.console.print("[bold green]Answer:[/bold green]")
|
||||||
self.console.print(Markdown(answer))
|
self.console.print(Markdown(answer))
|
||||||
if cite and citations:
|
for renderable in format_citations_rich(citations):
|
||||||
for renderable in format_citations_rich(citations):
|
self.console.print(renderable)
|
||||||
self.console.print(renderable)
|
|
||||||
|
|
||||||
async def analyze(
|
async def analyze(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
|
|
@ -369,11 +369,6 @@ def ask( # pragma: no cover
|
||||||
"--db",
|
"--db",
|
||||||
help="Path to the LanceDB database file",
|
help="Path to the LanceDB database file",
|
||||||
),
|
),
|
||||||
cite: bool = typer.Option(
|
|
||||||
False,
|
|
||||||
"--cite",
|
|
||||||
help="Include citations in the response",
|
|
||||||
),
|
|
||||||
filter: str | None = typer.Option(
|
filter: str | None = typer.Option(
|
||||||
None,
|
None,
|
||||||
"--filter",
|
"--filter",
|
||||||
|
|
@ -385,7 +380,6 @@ def ask( # pragma: no cover
|
||||||
asyncio.run(
|
asyncio.run(
|
||||||
app.ask(
|
app.ask(
|
||||||
question=question,
|
question=question,
|
||||||
cite=cite,
|
|
||||||
filter=filter,
|
filter=filter,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -368,12 +368,11 @@ class HaikuRAG:
|
||||||
async def ask(
|
async def ask(
|
||||||
self,
|
self,
|
||||||
question: str,
|
question: str,
|
||||||
system_prompt: str | None = None,
|
|
||||||
filter: str | None = None,
|
filter: str | None = None,
|
||||||
) -> "tuple[str, list[Citation]]":
|
) -> "tuple[str, list[Citation]]":
|
||||||
from haiku.rag.client.agents import ask
|
from haiku.rag.client.agents import ask
|
||||||
|
|
||||||
return await ask(self, question, system_prompt, filter)
|
return await ask(self, question, filter)
|
||||||
|
|
||||||
async def research(
|
async def research(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
|
|
@ -9,24 +9,32 @@ if TYPE_CHECKING:
|
||||||
async def ask(
|
async def ask(
|
||||||
client: "HaikuRAG",
|
client: "HaikuRAG",
|
||||||
question: str,
|
question: str,
|
||||||
system_prompt: str | None = None,
|
|
||||||
filter: str | None = None,
|
filter: str | None = None,
|
||||||
) -> "tuple[str, list[Citation]]":
|
) -> "tuple[str, list[Citation]]":
|
||||||
"""Ask a question using the configured QA agent.
|
"""Ask a question against the knowledge base via the rag skill.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
client: The HaikuRAG client.
|
client: The HaikuRAG client.
|
||||||
question: The question to ask.
|
question: The question to ask.
|
||||||
system_prompt: Optional custom system prompt for the QA agent.
|
|
||||||
filter: SQL WHERE clause to filter documents.
|
filter: SQL WHERE clause to filter documents.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Tuple of (answer text, list of resolved citations).
|
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)
|
skill = create_skill(db_path=client.store.db_path, config=client._config)
|
||||||
return await qa_agent.answer(question, filter=filter)
|
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(
|
async def research(
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue