001/** 002 * Copyright (c) 2025-2026, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.gnu.org/licenses/lgpl-3.0.txt 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package dev.tinyflow.core.searchengine.impl; 017 018import com.agentsflex.core.document.Document; 019import com.agentsflex.core.llm.client.HttpClient; 020import com.agentsflex.core.util.Maps; 021import dev.tinyflow.core.searchengine.SearchEngine; 022 023import java.util.Collections; 024import java.util.HashMap; 025import java.util.List; 026import java.util.Map; 027 028public class BochaaiSearchEngineImpl implements SearchEngine { 029 030 private String url = "https://api.bochaai.com/v1/ai-search"; 031 private String apiKey; 032 private HttpClient httpClient = new HttpClient(); 033 034 public String getUrl() { 035 return url; 036 } 037 038 public void setUrl(String url) { 039 this.url = url; 040 } 041 042 public String getApiKey() { 043 return apiKey; 044 } 045 046 public void setApiKey(String apiKey) { 047 this.apiKey = apiKey; 048 } 049 050 @Override 051 public List<Document> search(String keyword, int limit) { 052 Map<String, String> headers = new HashMap<>(); 053 headers.put("Authorization", "Bearer " + apiKey); 054 headers.put("Content-Type", "application/json"); 055 056 String jsonString = Maps.of("query", keyword) 057 .set("summary", true). 058 set("freshness", "noLimit") 059 .set("count", limit) 060 .set("stream", false) 061 .toJSON(); 062 063 String responseString = httpClient.post(url, headers, jsonString); 064 065 return Collections.emptyList(); 066 } 067}