RAG
RAG stands for Retrieval Augmented Generation, which is a technique to generate answers based on given facts. PuppyChatter supports RAG through Google gemini's AQA. To use this feature, users should initialized an instance of GeminiAqaPuppyChatter and pass a FactSource to it via GeminiAqaPromptParameters. An simple example is shown below:
PuppyChatter chatter = new GeminiAqaPuppyChatter("{google api key}",null);
String sessionId=chatter.createSession();
InlinePassages inlinePassages=new InlinePassages();
inlinePassages.setPassages(List.of(
"只見在影片中網紅酷的夢不解台灣影片在國外為何比較不紅,對此,魏德聖認為影視是最容易打文化認同的,但台灣在經濟起飛的時候選擇了科技,相比之下南韓就選擇娛樂,所以會透過電視、電影的方式來達到韓式文化的行銷,魏德聖也認為對民眾來說電影就是生活跟自己比較有關係,但是台灣選擇了台積電就跟我們比較沒關係「這是我最無力感的地方。」",
"影片一曝光也引起許多網友的討論,但有許多網友表示不認同魏德聖導演的想法,網友提到韓國也是從科技業代工起來,甚至有網友認為魏德聖是在牽拖「他直接說沒受重視就好了,不用扯台積」,也有其餘網友提出電影不紅的看法「台灣電影的問題大部分是在沒辦法讓跨語種的觀眾也產生投射,也就是主題太狹窄」、「好看我會看啊~ 但國片就那樣」、「要讓台灣的電影在國外受歡迎,拜託先拍出有水準好片。」",
"2+2=4"));
GeminiAqaPromptParameters parameters=new GeminiAqaPromptParameters("user", inlinePassages);
Response response=chatter.bark(sessionId, "台灣電影在國外爲什麼不紅", parameters);
System.out.println("message="+response.getMessage());
chatter.closeSession(sessionId);
The example above utilizes InlinePassages as a fact source. The current release of PuppyChatter supports 5 types of fact sources:
- GoogleDriveFactSource
- GoogleSearchFactSource
- InlinePassages
- LuceneFactSource
- SemanticRetrieval
GoogleSearchFactSource
factSource=new GoogleSearchFactSource(this.googleSearchAPIKey, this.searchEngineId, this.conversationBaseQuery, this.summaryQuery)
GoogleDriveFactSource
GoogleDriveFactSource is a fact source that connects to google drive. To use this class, first, add codenote@api-project-437674419610.iam.gserviceaccount.com as a viewer to the target google drive folder and then pass the id of the folder as a parameter to the constructor.
factSource = new GoogleDriveFactSource("id to a google drive folder");SemanticRetrieval
factSource=new SemanticRetrieval(new FilebasedAccessTokenProvider(new File("api-project-437674419610-36be64919691.json")), corporaId);