/** * Create a Rotten Tomatoes agent * * @param client An http client object * @param apikey A Rotten Tomatoes API key */ public RottenTomatoesAgent(HttpClient client, String apikey) { this.apikey = apikey; this.client = client; this.setDescription(new Description("movies", SUMMARY, EXAMPLE)); }
/** * Create a date-time agent */ public DateTimeAgent() { this.setDescription(new Description("date-time", SUMMARY, EXAMPLES)); }
/** * Create a duckduckgo agent * * @param client http client */ public DuckDuckGoAgent(HttpClient client) { this.client = client; this.setDescription(new Description("general answers", SUMMARY, EXAMPLE)); }
@Override public AgentResponse process(AgentRequest request) { logger.debug("Handling the request: " + request.getText()); String agentRequest = request.getText(); String searchPhrase = getSearchPhrase(agentRequest); logger.debug("Search phrase: " + searchPhrase); if (searchPhrase == null) { return new AgentResponse(ResponseStatus.Code.AGENT_DID_NOT_UNDERSTAND_REQUEST); } String json = getFlickrJson(searchPhrase); logger.debug("Flickr JSON: " + json); if (json == null) { return new AgentResponse(ResponseStatus.Code.AGENT_INTERNAL_ERROR); } String url = getImageUrl(json); logger.debug("Flickr image URL: " + url); byte[] data = getImage(url); if (data == null) { return new AgentResponse(ResponseStatus.Code.AGENT_INTERNAL_ERROR); } String payload = encodeImage(data); return new AgentResponse(Response.Type.IMAGE_EMBED, "Here is your image", payload); }
@Override public AgentResponse process(AgentRequest request) { logger.debug("Handling the request: " + request.getText()); String requestText = request.getText(); String entityText = extractEntity(requestText); String data = requestData(entityText); return createResponse(data); }
@Override public AgentResponse process(AgentRequest request) { logger.debug("Handling the request: " + request.getText()); return new AgentResponse(request.getText()); }
/** * Stock agent * * The Quandl API provides stock information for various companies world * wide. The StockAgent uses said API to scrape historical closing prices of * NASDAQ and NYSE companies. * * @param client An http client object * @param apiKey A Quandl API key */ public StockAgent(HttpClient client, String apiKey) { this.client = client; this.apiKey = apiKey; this.stockSymbolMap = new TreeMap<String, CompanyInfo>(String.CASE_INSENSITIVE_ORDER); readCsvFile("stockagent/NASDAQ_Companies.csv"); readCsvFile("stockagent/NYSE_Companies.csv"); this.setDescription(new Description("stock ticker", SUMMARY, EXAMPLE)); }
/** * Create an echo agent */ public EchoAgent() { setDescription(new Description("echo", SUMMARY, EXAMPLE)); }
public CalculatorAgent() { this.setDescription(new Description("calculator", SUMMARY, EXAMPLE)); }
/** * Create a response * * @param response response from an agent */ public Response(AgentResponse response) { this.type = response.getType(); this.text = response.getText(); this.payload = response.getPayload(); this.status = response.getStatus(); }
/** * Create a Flickr agent * * @param client An http client object * @param apikey Flickr API key */ public FlickrAgent(HttpClient client, String apikey) { this.apikey = apikey; this.client = client; this.setDescription(new Description("images", SUMMARY, EXAMPLE)); this.pattern = Pattern.compile(REGEX, Pattern.CASE_INSENSITIVE); }
@Override public Description getDescription() { return new Description(description); }
/** * Create an agent description * * @param name Name of the agent * @param summary A user-facing description of the agent's capabilities * @param examples Array of example questions or commands */ public Description(String name, String summary, String[] examples) { this.setName(name); this.setSummary(summary); this.setExamples(examples); }
/** * Copy a description * * @param description agent description */ public Description(Description description) { this(description.getName(), description.getSummary(), description.getExamples()); }
/** * Create a remote agent object * * @param urlBase the base URL for the web services * @param client the http client */ public RemoteAgent(String urlBase, HttpClient client) { // make sure end of url has slash this.urlBase = urlBase.replaceAll("/$", "") + "/"; this.client = client; setUrls(); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(ResponseStatus.Code.class, new ResponseCodeDeserializer()); gsonBuilder.registerTypeAdapter(Response.Type.class, new ResponseTypeDeserializer()); gson = gsonBuilder.create(); }
/** * Set the agent that handled the request * * @param agent Agent object */ public void setAgent(Agent agent) { agentName = agent.getName(); }
@Override public void setName(String name) { description.setName(name); }
@Override public String getName() { return description.getName(); }
@Override public void setDescription(Description description) { this.description = new Description(description); }
/** * Get a default description * * @param clazz The class of the agent * @return default description */ public static Description getUninitializedDescription(Class<?> clazz) { String name = clazz.getCanonicalName(); return new Description(name, "Summary is not set.", "Example is not set."); } }