Package com.tnsai.tools.search
Class QnATools
java.lang.Object
com.tnsai.tools.search.QnATools
Function-shape Qinvalid input: '&A' and developer-community search tools — the LangChain-style
replacement for the legacy
HackerNewsTool (Algolia HN search) and
StackOverflowSearchTool (see issue #188 — RFC).
Two typed @Tool methods:
hackernews(String, int, String)— Algolia HN search; returns up to N stories with title, points, comments, age, URL, and HN discussion link.stackoverflow(String)— Stack Exchange search filtered to Stack Overflow; returns the top 5 questions with score, answer count, and link.
Stack Exchange optionally takes an STACKEXCHANGE_KEY env var to
raise the per-IP quota. The key is read once in the no-arg constructor and
is sent only when set; IllegalStateException is never thrown for a
missing key (the API works without it, just with a lower quota).
- Since:
- 0.5.7 (Phase 2 batch 4d — built-in tool migration to function shape, see #188)
-
Constructor Summary
ConstructorsConstructorDescriptionQnATools()Default constructor — picks the optional STACKEXCHANGE_KEY from env.Explicit-key constructor (ornullto skip the key parameter on requests).QnATools(String stackExchangeKey, okhttp3.OkHttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper) Full constructor for tests or shared HTTP/JSON instances. -
Method Summary
Modifier and TypeMethodDescriptionhackernews(String query, int count, String tags) stackoverflow(String query)
-
Constructor Details
-
QnATools
public QnATools()Default constructor — picks the optional STACKEXCHANGE_KEY from env. -
QnATools
Explicit-key constructor (ornullto skip the key parameter on requests). -
QnATools
public QnATools(String stackExchangeKey, okhttp3.OkHttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper) Full constructor for tests or shared HTTP/JSON instances.
-
-
Method Details
-
hackernews
@Tool(name="hackernews", description="Search Hacker News stories via the Algolia HN API. Returns up to {count} stories matching the query, sorted by relevance, with title, points, comment count, age, external URL, and HN discussion link. {tags} restricts the result type \u2014 \"story\" (default), \"comment\", \"poll\", \"show_hn\", \"ask_hn\". No API key needed.", keywords={"search","hackernews","hn","tech","startup","yc"}, idempotent=true) public String hackernews(@ToolParam(description="The natural-language search query") String query, @ToolParam(description="Number of stories (1..50; defaults to 10)",required=false,defaultValue="10") int count, @ToolParam(description="Result type \u2014 \"story\" (default), \"comment\", \"poll\", \"show_hn\", \"ask_hn\"",required=false,defaultValue="story") String tags) throws IOException - Throws:
IOException
-
stackoverflow
@Tool(name="stackoverflow_search", description="Search Stack Overflow via the Stack Exchange API for questions matching the query in their title. Returns the top 5 questions with score, answer count, is-answered flag, and direct link. The optional STACKEXCHANGE_KEY env var raises the per-IP daily quota from 300 to 10,000 requests; the tool works without it.", keywords={"search","stackoverflow","stack","questions","developer"}, idempotent=true) public String stackoverflow(@ToolParam(description="The natural-language search query (matched against question titles)") String query) throws IOException - Throws:
IOException
-