Skip to content

Commit

Permalink
Feature/read me update (#9)
Browse files Browse the repository at this point in the history
* Documentation Edit

* Documentation Edit

* Chat session History

---------

Co-authored-by: aiupbw3_amway <[email protected]>
  • Loading branch information
SaurabhDhotreknoldus and aiupbw3_amway authored Jun 24, 2024
1 parent e4bca36 commit 7810519
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@


import com.google.cloud.vertexai.api.GenerateContentResponse;
import com.google.cloud.vertexai.api.Content;
import com.google.cloud.vertexai.generativeai.ChatSession;
import com.google.cloud.vertexai.generativeai.ResponseHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/api/gemini")
Expand All @@ -23,4 +27,12 @@ public String fromBodyPost(@RequestBody String prompt) throws IOException {
GenerateContentResponse generateContentResponse = this.chatSession.sendMessage(prompt);
return ResponseHandler.getText(generateContentResponse);
}

@GetMapping("/v1/history/{text}")
public List<String> getChatSessionHistory(@PathVariable String text) throws IOException {
GenerateContentResponse generateContentResponse = this.chatSession.sendMessage(text);
List<Content> history = this.chatSession.getHistory();
return history.stream().flatMap(h -> h.getPartsList().stream()).map(part -> part.getText()).toList();
}

}

0 comments on commit 7810519

Please sign in to comment.